22 #ifndef _XENO_NUCLEUS_SYNCH_H
23 #define _XENO_NUCLEUS_SYNCH_H
25 #include <nucleus/queue.h>
28 #define XNSYNCH_FIFO 0x0
29 #define XNSYNCH_PRIO 0x1
30 #define XNSYNCH_NOPIP 0x0
31 #define XNSYNCH_PIP 0x2
32 #define XNSYNCH_DREORD 0x4
33 #define XNSYNCH_OWNER 0x8
35 #ifndef CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX
36 #define CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX 0
39 #ifdef CONFIG_XENO_FASTSYNCH
42 static inline int xnsynch_fast_owner_check(xnarch_atomic_t *fastlock,
45 return (xnhandle_mask_spare(xnarch_atomic_get(fastlock)) == ownerh) ?
49 static inline int xnsynch_fast_acquire(xnarch_atomic_t *fastlock,
50 xnhandle_t new_ownerh)
52 xnhandle_t lock_state =
53 xnarch_atomic_cmpxchg(fastlock, XN_NO_HANDLE, new_ownerh);
55 if (likely(lock_state == XN_NO_HANDLE))
58 if (xnhandle_mask_spare(lock_state) == new_ownerh)
64 static inline int xnsynch_fast_release(xnarch_atomic_t *fastlock,
65 xnhandle_t cur_ownerh)
67 return (xnarch_atomic_cmpxchg(fastlock, cur_ownerh, XN_NO_HANDLE) ==
73 static inline int xnsynch_fast_acquire(xnarch_atomic_t *fastlock,
74 xnhandle_t new_ownerh)
79 static inline int xnsynch_fast_release(xnarch_atomic_t *fastlock,
80 xnhandle_t cur_ownerh)
87 #if defined(__KERNEL__) || defined(__XENO_SIM__)
89 #define XNSYNCH_CLAIMED 0x10
91 #define XNSYNCH_FLCLAIM XN_HANDLE_SPARE3
94 #define XNSYNCH_SPARE0 0x01000000
95 #define XNSYNCH_SPARE1 0x02000000
96 #define XNSYNCH_SPARE2 0x04000000
97 #define XNSYNCH_SPARE3 0x08000000
98 #define XNSYNCH_SPARE4 0x10000000
99 #define XNSYNCH_SPARE5 0x20000000
100 #define XNSYNCH_SPARE6 0x40000000
101 #define XNSYNCH_SPARE7 0x80000000
104 #define XNSYNCH_DONE 0
105 #define XNSYNCH_WAIT 1
106 #define XNSYNCH_RESCHED 2
112 typedef struct xnsynch {
116 #define link2synch(ln) container_of(ln, struct xnsynch, link)
122 struct xnthread *owner;
124 #ifdef CONFIG_XENO_FASTSYNCH
125 xnarch_atomic_t *fastlock;
128 void (*cleanup)(
struct xnsynch *synch);
130 XNARCH_DECL_DISPLAY_CONTEXT();
134 #define xnsynch_test_flags(synch,flags) testbits((synch)->status,flags)
135 #define xnsynch_set_flags(synch,flags) setbits((synch)->status,flags)
136 #define xnsynch_clear_flags(synch,flags) clrbits((synch)->status,flags)
137 #define xnsynch_wait_queue(synch) (&((synch)->pendq))
138 #define xnsynch_nsleepers(synch) countpq(&((synch)->pendq))
139 #define xnsynch_pended_p(synch) (!emptypq_p(&((synch)->pendq)))
140 #define xnsynch_owner(synch) ((synch)->owner)
142 #ifdef CONFIG_XENO_FASTSYNCH
143 #define xnsynch_fastlock(synch) ((synch)->fastlock)
144 #define xnsynch_fastlock_p(synch) ((synch)->fastlock != NULL)
145 #define xnsynch_owner_check(synch, thread) \
146 xnsynch_fast_owner_check((synch)->fastlock, xnthread_handle(thread))
148 #define xnsynch_fastlock(synch) ((xnarch_atomic_t *)NULL)
149 #define xnsynch_fastlock_p(synch) 0
150 #define xnsynch_owner_check(synch, thread) \
151 ((synch)->owner == thread ? 0 : -EPERM)
154 #define xnsynch_fast_is_claimed(fastlock) \
155 xnhandle_test_spare(fastlock, XNSYNCH_FLCLAIM)
156 #define xnsynch_fast_set_claimed(fastlock, enable) \
157 (((fastlock) & ~XNSYNCH_FLCLAIM) | ((enable) ? XNSYNCH_FLCLAIM : 0))
158 #define xnsynch_fast_mask_claimed(fastlock) ((fastlock) & ~XNSYNCH_FLCLAIM)
164 #if XENO_DEBUG(SYNCH_RELAX)
166 void xnsynch_detect_relaxed_owner(
struct xnsynch *synch,
167 struct xnthread *sleeper);
169 void xnsynch_detect_claimed_relax(
struct xnthread *owner);
173 static inline void xnsynch_detect_relaxed_owner(
struct xnsynch *synch,
174 struct xnthread *sleeper)
178 static inline void xnsynch_detect_claimed_relax(
struct xnthread *owner)
184 void xnsynch_init(
struct xnsynch *synch, xnflags_t flags,
185 xnarch_atomic_t *fastlock);
187 #define xnsynch_destroy(synch) xnsynch_flush(synch, XNRMID)
189 static inline void xnsynch_set_owner(
struct xnsynch *synch,
190 struct xnthread *thread)
192 synch->owner = thread;
195 static inline void xnsynch_register_cleanup(
struct xnsynch *synch,
196 void (*handler)(
struct xnsynch *))
198 synch->cleanup = handler;
203 xntmode_t timeout_mode);
208 xnpholder_t *holder);
212 xntmode_t timeout_mode);
struct xnthread * xnsynch_wakeup_one_sleeper(struct xnsynch *synch)
Give the resource ownership to the next waiting thread.
Definition: synch.c:237
xnflags_t xnsynch_sleep_on(struct xnsynch *synch, xnticks_t timeout, xntmode_t timeout_mode)
Sleep on an ownerless synchronization object.
Definition: synch.c:171
void xnsynch_release_all_ownerships(struct xnthread *thread)
Release all ownerships.
Definition: synch.c:981
void xnsynch_forget_sleeper(struct xnthread *thread)
Abort a wait for a resource.
Definition: synch.c:921
void xnsynch_init(struct xnsynch *synch, xnflags_t flags, xnarch_atomic_t *fastlock)
Initialize a synchronization object.
Definition: synch.c:102
xnflags_t xnsynch_acquire(struct xnsynch *synch, xnticks_t timeout, xntmode_t timeout_mode)
Acquire the ownership of a synchronization object.
Definition: synch.c:406
struct xnthread * xnsynch_peek_pendq(struct xnsynch *synch)
Access the thread leading a synch object wait queue.
Definition: synch.c:803
xnpholder_t * xnsynch_wakeup_this_sleeper(struct xnsynch *synch, xnpholder_t *holder)
Give the resource ownership to a given waiting thread.
Definition: synch.c:309
struct xnthread * xnsynch_release(struct xnsynch *synch)
Give the resource ownership to the next waiting thread.
Definition: synch.c:775
int xnsynch_flush(struct xnsynch *synch, xnflags_t reason)
Unblock all waiters pending on a resource.
Definition: synch.c:869
void xnsynch_requeue_sleeper(struct xnthread *thread)
Change a sleeper's priority.
Definition: synch.c:629