4 #include <asm/xenomai/atomic.h>
5 #include <nucleus/compiler.h>
6 #include <nucleus/types.h>
8 #if !defined(__KERNEL__) && !defined(__XENO_SIM__)
9 typedef void xnthread_t;
12 #define __CLAIMED_BIT XN_HANDLE_SPARE3
14 #define test_claimed(owner) xnhandle_test_spare(owner, __CLAIMED_BIT)
15 #define clear_claimed(owner) xnhandle_mask_spare(owner)
16 #define set_claimed(owner, bit) ({ \
17 xnhandle_t __tmp = xnhandle_mask_spare(owner); \
19 xnhandle_set_spare(__tmp, __CLAIMED_BIT); \
23 #ifdef CONFIG_XENO_FASTSYNCH
25 static __inline__
int __cb_try_read_lock(xnarch_atomic_t *lock)
27 unsigned val = xnarch_atomic_get(lock);
28 while (likely(val != -1)) {
29 unsigned old = xnarch_atomic_cmpxchg(lock, val, val + 1);
30 if (likely(old == val))
37 static __inline__
void __cb_read_unlock(xnarch_atomic_t *lock)
39 unsigned old, val = xnarch_atomic_get(lock);
40 while (likely(val != -1)) {
41 old = xnarch_atomic_cmpxchg(lock, val, val - 1);
42 if (likely(old == val))
48 static __inline__
int __cb_try_write_lock(xnarch_atomic_t *lock)
50 unsigned old = xnarch_atomic_cmpxchg(lock, 0, -1);
56 static __inline__
void __cb_force_write_lock(xnarch_atomic_t *lock)
58 xnarch_atomic_set(lock, -1);
61 static __inline__
void __cb_write_unlock(xnarch_atomic_t *lock)
63 xnarch_atomic_set(lock, 0);
65 #define DECLARE_CB_LOCK_FLAGS(name) struct { } name __attribute__((unused))
66 #define cb_try_read_lock(lock, flags) __cb_try_read_lock(lock)
67 #define cb_read_unlock(lock, flags) __cb_read_unlock(lock)
68 #define cb_try_write_lock(lock, flags) __cb_try_write_lock(lock)
69 #define cb_force_write_lock(lock, flags) __cb_force_write_lock(lock)
70 #define cb_write_unlock(lock, flags) __cb_write_unlock(lock)
72 #if defined(__KERNEL__) || defined(__XENO_SIM__)
73 #define DECLARE_CB_LOCK_FLAGS(name) spl_t name
74 #define cb_try_read_lock(lock, flags) \
75 ({ xnlock_get_irqsave(&nklock, flags); 0; })
76 #define cb_read_unlock(lock, flags) xnlock_put_irqrestore(&nklock, flags)
77 #define cb_try_write_lock(lock, flags) \
78 ({ xnlock_get_irqsave(&nklock, flags); 0; })
79 #define cb_force_write_lock(lock, flags) \
80 ({ xnlock_get_irqsave(&nklock, flags); 0; })
81 #define cb_write_unlock(lock, flags) xnlock_put_irqrestore(&nklock, flags)
83 #define DECLARE_CB_LOCK_FLAGS(name)
84 #define cb_try_read_lock(lock, flags) (0)
85 #define cb_read_unlock(lock, flags) do { } while (0)
86 #define cb_try_write_lock(lock, flags) (0)
87 #define cb_force_write_lock(lock, flags) do { } while (0)
88 #define cb_write_unlock(lock, flags) do { } while (0)