00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _XENO_NUCLEUS_SYNCH_H
00023 #define _XENO_NUCLEUS_SYNCH_H
00024
00025 #include <nucleus/queue.h>
00026
00027
00028 #define XNSYNCH_FIFO 0x0
00029 #define XNSYNCH_PRIO 0x1
00030 #define XNSYNCH_NOPIP 0x0
00031 #define XNSYNCH_PIP 0x2
00032 #define XNSYNCH_DREORD 0x4
00033
00034 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00035
00036 #define XNSYNCH_CLAIMED 0x8
00037
00038
00039 #define XNSYNCH_SPARE0 0x01000000
00040 #define XNSYNCH_SPARE1 0x02000000
00041 #define XNSYNCH_SPARE2 0x04000000
00042 #define XNSYNCH_SPARE3 0x08000000
00043 #define XNSYNCH_SPARE4 0x10000000
00044 #define XNSYNCH_SPARE5 0x20000000
00045 #define XNSYNCH_SPARE6 0x40000000
00046 #define XNSYNCH_SPARE7 0x80000000
00047
00048
00049 #define XNSYNCH_DONE 0
00050 #define XNSYNCH_WAIT 1
00051 #define XNSYNCH_RESCHED 2
00052
00053 struct xnthread;
00054 struct xnsynch;
00055 struct xnmutex;
00056
00057 typedef struct xnsynch {
00058
00059 xnpholder_t link;
00060
00061 #define link2synch(ln) container_of(ln, xnsynch_t, link)
00062
00063 xnflags_t status;
00064
00065 xnpqueue_t pendq;
00066
00067 struct xnthread *owner;
00068
00069 void (*cleanup)(struct xnsynch *synch);
00070
00071 XNARCH_DECL_DISPLAY_CONTEXT();
00072
00073 } xnsynch_t;
00074
00075 #define xnsynch_test_flags(synch,flags) testbits((synch)->status,flags)
00076 #define xnsynch_set_flags(synch,flags) setbits((synch)->status,flags)
00077 #define xnsynch_clear_flags(synch,flags) clrbits((synch)->status,flags)
00078 #define xnsynch_wait_queue(synch) (&((synch)->pendq))
00079 #define xnsynch_nsleepers(synch) countpq(&((synch)->pendq))
00080 #define xnsynch_pended_p(synch) (!emptypq_p(&((synch)->pendq)))
00081 #define xnsynch_owner(synch) ((synch)->owner)
00082
00083 #ifdef __cplusplus
00084 extern "C" {
00085 #endif
00086
00087 void xnsynch_init(xnsynch_t *synch,
00088 xnflags_t flags);
00089
00090 #define xnsynch_destroy(synch) xnsynch_flush(synch,XNRMID)
00091
00092 static inline void xnsynch_set_owner (xnsynch_t *synch, struct xnthread *thread)
00093 {
00094 synch->owner = thread;
00095 }
00096
00097 static inline void xnsynch_register_cleanup (xnsynch_t *synch, void (*handler)(xnsynch_t *))
00098 {
00099 synch->cleanup = handler;
00100 }
00101
00102 void xnsynch_sleep_on(xnsynch_t *synch,
00103 xnticks_t timeout,
00104 xntmode_t timeout_mode);
00105
00106 struct xnthread *xnsynch_wakeup_one_sleeper(xnsynch_t *synch);
00107
00108 struct xnthread *xnsynch_peek_pendq(xnsynch_t *synch);
00109
00110 xnpholder_t *xnsynch_wakeup_this_sleeper(xnsynch_t *synch,
00111 xnpholder_t *holder);
00112
00113 int xnsynch_flush(xnsynch_t *synch,
00114 xnflags_t reason);
00115
00116 void xnsynch_release_all_ownerships(struct xnthread *thread);
00117
00118 void xnsynch_renice_sleeper(struct xnthread *thread);
00119
00120 void xnsynch_forget_sleeper(struct xnthread *thread);
00121
00122 struct xnthread *xnsynch_forget_one_sleeper(xnsynch_t *synch);
00123
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127
00128 #endif
00129
00130 #endif