Xenomai API
2.5.6.1
|
00001 00022 #ifndef _XENO_SEM_H 00023 #define _XENO_SEM_H 00024 00025 #include <nucleus/synch.h> 00026 #include <native/types.h> 00027 00028 /* Creation flags. */ 00029 #define S_PRIO XNSYNCH_PRIO /* Pend by task priority order. */ 00030 #define S_FIFO XNSYNCH_FIFO /* Pend by FIFO order. */ 00031 #define S_PULSE 0x100 /* Apply pulse mode. */ 00032 00033 typedef struct rt_sem_info { 00034 00035 unsigned long count; /* !< Current semaphore value. */ 00036 00037 int nwaiters; /* !< Number of pending tasks. */ 00038 00039 char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */ 00040 00041 } RT_SEM_INFO; 00042 00043 typedef struct rt_sem_placeholder { 00044 xnhandle_t opaque; 00045 } RT_SEM_PLACEHOLDER; 00046 00047 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP) 00048 00049 #include <native/ppd.h> 00050 00051 #define XENO_SEM_MAGIC 0x55550303 00052 00053 typedef struct rt_sem { 00054 00055 unsigned magic; /* !< Magic code - must be first */ 00056 00057 xnsynch_t synch_base; /* !< Base synchronization object. */ 00058 00059 unsigned long count; /* !< Current semaphore value. */ 00060 00061 int mode; /* !< Creation mode. */ 00062 00063 xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */ 00064 00065 char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */ 00066 00067 #ifdef CONFIG_XENO_OPT_PERVASIVE 00068 pid_t cpid; /* !< Creator's pid. */ 00069 #endif /* CONFIG_XENO_OPT_PERVASIVE */ 00070 00071 xnholder_t rlink; /* !< Link in resource queue. */ 00072 00073 #define rlink2sem(ln) container_of(ln, RT_SEM, rlink) 00074 00075 xnqueue_t *rqueue; /* !< Backpointer to resource queue. */ 00076 00077 } RT_SEM; 00078 00079 #ifdef __cplusplus 00080 extern "C" { 00081 #endif 00082 00083 #ifdef CONFIG_XENO_OPT_NATIVE_SEM 00084 00085 int __native_sem_pkg_init(void); 00086 00087 void __native_sem_pkg_cleanup(void); 00088 00089 static inline void __native_sem_flush_rq(xnqueue_t *rq) 00090 { 00091 xeno_flush_rq(RT_SEM, rq, sem); 00092 } 00093 00094 int rt_sem_p_inner(RT_SEM *sem, 00095 xntmode_t timeout_mode, RTIME timeout); 00096 00097 #else /* !CONFIG_XENO_OPT_NATIVE_SEM */ 00098 00099 #define __native_sem_pkg_init() ({ 0; }) 00100 #define __native_sem_pkg_cleanup() do { } while(0) 00101 #define __native_sem_flush_rq(rq) do { } while(0) 00102 00103 #endif /* !CONFIG_XENO_OPT_NATIVE_SEM */ 00104 00105 #ifdef __cplusplus 00106 } 00107 #endif 00108 00109 #else /* !(__KERNEL__ || __XENO_SIM__) */ 00110 00111 typedef RT_SEM_PLACEHOLDER RT_SEM; 00112 00113 #ifdef __cplusplus 00114 extern "C" { 00115 #endif 00116 00117 int rt_sem_bind(RT_SEM *sem, 00118 const char *name, 00119 RTIME timeout); 00120 00121 static inline int rt_sem_unbind (RT_SEM *sem) 00122 00123 { 00124 sem->opaque = XN_NO_HANDLE; 00125 return 0; 00126 } 00127 00128 #ifdef __cplusplus 00129 } 00130 #endif 00131 00132 #endif /* __KERNEL__ || __XENO_SIM__ */ 00133 00134 #ifdef __cplusplus 00135 extern "C" { 00136 #endif 00137 00138 /* Public interface. */ 00139 00140 int rt_sem_create(RT_SEM *sem, 00141 const char *name, 00142 unsigned long icount, 00143 int mode); 00144 00145 int rt_sem_delete(RT_SEM *sem); 00146 00147 int rt_sem_p(RT_SEM *sem, 00148 RTIME timeout); 00149 00150 int rt_sem_p_until(RT_SEM *sem, 00151 RTIME timeout); 00152 00153 int rt_sem_v(RT_SEM *sem); 00154 00155 int rt_sem_broadcast(RT_SEM *sem); 00156 00157 int rt_sem_inquire(RT_SEM *sem, 00158 RT_SEM_INFO *info); 00159 00160 #ifdef __cplusplus 00161 } 00162 #endif 00163 00164 #endif /* !_XENO_SEM_H */