YAP 7.1.0
locks_mips.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 MIPS **
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#define load_linked(addr) \
24({ \
25 unsigned int __res; \
26 \
27 __asm__ __volatile__( \
28 "ll\t%0,(%1)" \
29 : "=r" (__res) \
30 : "r" ((unsigned long) (addr))); \
31 \
32 __res; \
33})
34
35#define store_conditional(addr,value) \
36({ \
37 int __res; \
38 \
39 __asm__ __volatile__( \
40 "sc\t%0,(%2)" \
41 : "=r" (__res) \
42 : "0" (value), "r" (addr)); \
43 \
44 __res; \
45})
46
47#define INIT_LOCK(LOCK_VAR) ((LOCK_VAR) = 0)
48#define TRY_LOCK(LOCK_PTR) (!test_and_set_bit(0,(__dumy_lock_t *)(LOCK_PTR)))
49#define LOCK(LOCK_VAR) _spin_lock((__dummy_lock_t *)(&(LOCK_VAR)))
50#define IS_LOCKED(LOCK_VAR) ((LOCK_VAR) != 0)
51#define IS_UNLOCKED(LOCK_VAR) ((LOCK_VAR) == 0)
52
53
54/* We need to support sync on MIPS */
55#define UNLOCK(LOCK_VAR) spin_unlock((__dummy_lock_t *)(&(LOCK_VAR)))
56
57typedef struct {
58 volatile unsigned int lock;
59} rwlock_t;
60
61#define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
62
63#define READ_LOCK(X) _read_lock(&(X))
64
65#define READ_UNLOCK(X) _read_unlock(&(X))
66
67#define WRITE_LOCK(X) _write_lock(&(X))
68
69#define WRITE_UNLOCK(X) _write_unlock(&(X))
70
71#define INIT_RWLOCK(RW) (RW) = RW_LOCK_UNLOCKED