19#ifndef _COBALT_KERNEL_SYNCH_H
20#define _COBALT_KERNEL_SYNCH_H
22#include <cobalt/kernel/list.h>
23#include <cobalt/kernel/assert.h>
24#include <cobalt/kernel/timer.h>
25#include <cobalt/uapi/kernel/synch.h>
26#include <cobalt/uapi/kernel/thread.h>
32#define XNSYNCH_CLAIMED 0x100
33#define XNSYNCH_CEILING 0x200
36#define XNSYNCH_SPARE0 0x01000000
37#define XNSYNCH_SPARE1 0x02000000
38#define XNSYNCH_SPARE2 0x04000000
39#define XNSYNCH_SPARE3 0x08000000
40#define XNSYNCH_SPARE4 0x10000000
41#define XNSYNCH_SPARE5 0x20000000
42#define XNSYNCH_SPARE6 0x40000000
43#define XNSYNCH_SPARE7 0x80000000
48#define XNSYNCH_RESCHED 2
57 struct list_head next;
66 struct list_head pendq;
68 struct xnthread *owner;
72 void (*cleanup)(
struct xnsynch *synch);
75#define XNSYNCH_WAITQUEUE_INITIALIZER(__name) { \
76 .status = XNSYNCH_PRIO, \
78 .pendq = LIST_HEAD_INIT((__name).pendq), \
84#define DEFINE_XNWAITQ(__name) \
85 struct xnsynch __name = XNSYNCH_WAITQUEUE_INITIALIZER(__name)
87static inline void xnsynch_set_status(
struct xnsynch *synch,
int bits)
89 synch->status |= bits;
92static inline void xnsynch_clear_status(
struct xnsynch *synch,
int bits)
94 synch->status &= ~bits;
97#define xnsynch_for_each_sleeper(__pos, __synch) \
98 list_for_each_entry(__pos, &(__synch)->pendq, plink)
100#define xnsynch_for_each_sleeper_safe(__pos, __tmp, __synch) \
101 list_for_each_entry_safe(__pos, __tmp, &(__synch)->pendq, plink)
103static inline int xnsynch_pended_p(
struct xnsynch *synch)
105 return !list_empty(&synch->pendq);
108static inline struct xnthread *xnsynch_owner(
struct xnsynch *synch)
113#define xnsynch_fastlock(synch) ((synch)->fastlock)
114#define xnsynch_fastlock_p(synch) ((synch)->fastlock != NULL)
115#define xnsynch_owner_check(synch, thread) \
116 xnsynch_fast_owner_check((synch)->fastlock, thread->handle)
118#ifdef CONFIG_XENO_OPT_DEBUG_MUTEX_RELAXED
120void xnsynch_detect_relaxed_owner(
struct xnsynch *synch,
121 struct xnthread *sleeper);
123void xnsynch_detect_boosted_relax(
struct xnthread *owner);
127static inline void xnsynch_detect_relaxed_owner(
struct xnsynch *synch,
128 struct xnthread *sleeper) { }
130static inline void xnsynch_detect_boosted_relax(
struct xnthread *owner) { }
138 atomic_t *fastlock, u32 *ceiling_ref);
142void xnsynch_commit_ceiling(
struct xnthread *curr);
144static inline void xnsynch_register_cleanup(
struct xnsynch *synch,
145 void (*handler)(
struct xnsynch *))
147 synch->cleanup = handler;
152 xntmode_t timeout_mode);
156int xnsynch_wakeup_many_sleepers(
struct xnsynch *synch,
int nr);
159 struct xnthread *sleeper);
163 xntmode_t timeout_mode);
173void xnsynch_requeue_sleeper(
struct xnthread *thread);
175void xnsynch_forget_sleeper(
struct xnthread *thread);
177struct xnsynch *__cobalt_mutex_lookup_lazy_pp(xnhandle_t handle);
int __must_check xnsynch_acquire(struct xnsynch *synch, xnticks_t timeout, xntmode_t timeout_mode)
Acquire the ownership of a synchronization object.
Definition synch.c:657
struct xnthread * xnsynch_peek_pendq(struct xnsynch *synch)
Access the thread leading a synch object wait queue.
Definition synch.c:1007
int __must_check xnsynch_sleep_on(struct xnsynch *synch, xnticks_t timeout, xntmode_t timeout_mode)
Sleep on an ownerless synchronization object.
Definition synch.c:199
int xnsynch_flush(struct xnsynch *synch, int reason)
Unblock all waiters pending on a resource.
Definition synch.c:1060
struct xnthread * xnsynch_wakeup_one_sleeper(struct xnsynch *synch)
Unblock the heading thread from wait.
Definition synch.c:253
void xnsynch_wakeup_this_sleeper(struct xnsynch *synch, struct xnthread *sleeper)
Unblock a particular thread from wait.
Definition synch.c:329
bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread)
Release a resource and pass it to the next waiting thread.
Definition synch.c:914
void xnsynch_init_protect(struct xnsynch *synch, int flags, atomic_t *fastlock, u32 *ceiling_ref)
Initialize a synchronization object enforcing PP.
Definition synch.c:131
int __must_check xnsynch_try_acquire(struct xnsynch *synch)
Try acquiring the ownership of a synchronization object.
Definition synch.c:592
int xnsynch_destroy(struct xnsynch *synch)
Destroy a synchronization object.
Definition synch.c:154
void xnsynch_init(struct xnsynch *synch, int flags, atomic_t *fastlock)
Initialize a synchronization object.
Definition synch.c:88
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition atomic.h:24