YAP 7.1.0
locks_alpha.h
1/************************************************************************
2** **
3** The YapTab/YapOr/OPTYap systems **
4** **
5** YapTab extends the Yap Prolog engine to support sequential tabling **
6** YapOr extends the Yap Prolog engine to support or-parallelism **
7** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
8** **
9** **
10** Yap Prolog was developed at University of Porto, Portugal **
11** **
12************************************************************************/
13
14/************************************************************************
15** Atomic locks for ALPHA **
16************************************************************************/
17
18/* This code is stolen from the Linux kernel */
19
20typedef struct { unsigned long a[100]; } __dummy_lock_t;
21#define __dummy_lock(lock) (*(__dummy_lock_t *)(lock))
22
23/*
24 Memory barrier in Alpha machines
25*/
26#define mb() \
27__asm__ __volatile__("mb": : :"memory")
28
29#define INIT_LOCK(LOCK_VAR) ((LOCK_VAR) = 0)
30#define TRY_LOCK(LOCK_PTR) (!_test_and_set_bit(0,(volatile void *)(LOCK_PTR)))
31#define LOCK(LOCK_VAR) _spin_lock((volatile void *)&(LOCK_VAR))
32#define IS_LOCKED(LOCK_VAR) ((LOCK_VAR) != 0)
33#define IS_UNLOCKED(LOCK_VAR) ((LOCK_VAR) == 0)
34
35/* We need to support a memory barrier on Alphas */
36#define UNLOCK(LOCK_VAR) { mb(); LOCK_VAR = 0; }
37
38typedef struct {
39 volatile int write_lock:1, read_counter:31;
40} /*__attribute__((aligned(32)))*/ rwlock_t;
41
42#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
43
44#define READ_LOCK(X) _read_lock(&(X))
45
46#define READ_UNLOCK(X) _read_unlock(&(X))
47
48#define WRITE_LOCK(X) _write_lock(&(X))
49
50#define WRITE_UNLOCK(X) _write_unlock(&(X))
51
52#define INIT_RWLOCK(RW) (RW) = RW_LOCK_UNLOCKED