Xenomai API
2.5.6.1
|
00001 00022 #ifndef _XENO_MUTEX_H 00023 #define _XENO_MUTEX_H 00024 00025 #include <native/types.h> 00026 00027 struct rt_task; 00028 00033 typedef struct rt_mutex_info { 00034 00035 int locked; 00037 int nwaiters; 00039 char name[XNOBJECT_NAME_LEN]; 00041 char owner[XNOBJECT_NAME_LEN]; 00044 } RT_MUTEX_INFO; 00045 00046 typedef struct rt_mutex_placeholder { 00047 00048 xnhandle_t opaque; 00049 00050 #ifdef CONFIG_XENO_FASTSYNCH 00051 xnarch_atomic_t *fastlock; 00052 00053 int lockcnt; 00054 #endif /* CONFIG_XENO_FASTSYNCH */ 00055 00056 } RT_MUTEX_PLACEHOLDER; 00057 00058 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP) 00059 00060 #include <nucleus/synch.h> 00061 #include <native/ppd.h> 00062 00063 #define XENO_MUTEX_MAGIC 0x55550505 00064 00065 #define RT_MUTEX_EXPORTED XNSYNCH_SPARE0 /* Mutex registered by name */ 00066 00067 typedef struct __rt_mutex { 00068 00069 unsigned magic; /* !< Magic code - must be first */ 00070 00071 xnsynch_t synch_base; /* !< Base synchronization object. */ 00072 00073 xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */ 00074 00075 int lockcnt; /* !< Lock nesting level (> 0 means "locked"). */ 00076 00077 char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */ 00078 00079 #ifdef CONFIG_XENO_OPT_PERVASIVE 00080 pid_t cpid; /* !< Creator's pid. */ 00081 #endif /* CONFIG_XENO_OPT_PERVASIVE */ 00082 00083 xnholder_t rlink; /* !< Link in resource queue. */ 00084 00085 #define rlink2mutex(ln) container_of(ln, RT_MUTEX, rlink) 00086 00087 xnqueue_t *rqueue; /* !< Backpointer to resource queue. */ 00088 00089 } RT_MUTEX; 00090 00091 #ifdef __cplusplus 00092 extern "C" { 00093 #endif 00094 00095 #ifdef CONFIG_XENO_OPT_NATIVE_MUTEX 00096 00097 int __native_mutex_pkg_init(void); 00098 00099 void __native_mutex_pkg_cleanup(void); 00100 00101 static inline void __native_mutex_flush_rq(xnqueue_t *rq) 00102 { 00103 xeno_flush_rq(RT_MUTEX, rq, mutex); 00104 } 00105 00106 int rt_mutex_acquire_inner(RT_MUTEX *mutex, RTIME timeout, 00107 xntmode_t timeout_mode); 00108 00109 #else /* !CONFIG_XENO_OPT_NATIVE_MUTEX */ 00110 00111 #define __native_mutex_pkg_init() ({ 0; }) 00112 #define __native_mutex_pkg_cleanup() do { } while(0) 00113 #define __native_mutex_flush_rq(rq) do { } while(0) 00114 00115 #endif /* !CONFIG_XENO_OPT_NATIVE_MUTEX */ 00116 00117 #ifdef __cplusplus 00118 } 00119 #endif 00120 00121 #else /* !(__KERNEL__ || __XENO_SIM__) */ 00122 00123 typedef RT_MUTEX_PLACEHOLDER RT_MUTEX; 00124 00125 #ifdef __cplusplus 00126 extern "C" { 00127 #endif 00128 00129 int rt_mutex_bind(RT_MUTEX *mutex, 00130 const char *name, 00131 RTIME timeout); 00132 00133 static inline int rt_mutex_unbind (RT_MUTEX *mutex) 00134 00135 { 00136 mutex->opaque = XN_NO_HANDLE; 00137 return 0; 00138 } 00139 00140 #ifdef __cplusplus 00141 } 00142 #endif 00143 00144 #endif /* __KERNEL__ || __XENO_SIM__ */ 00145 00146 #ifdef __cplusplus 00147 extern "C" { 00148 #endif 00149 00150 int rt_mutex_create_inner(RT_MUTEX *mutex, const char *name, int global); 00151 00152 /* Public interface. */ 00153 00154 int rt_mutex_create(RT_MUTEX *mutex, 00155 const char *name); 00156 00157 int rt_mutex_delete(RT_MUTEX *mutex); 00158 00159 int rt_mutex_acquire(RT_MUTEX *mutex, 00160 RTIME timeout); 00161 00162 int rt_mutex_acquire_until(RT_MUTEX *mutex, 00163 RTIME timeout); 00164 00165 int rt_mutex_release(RT_MUTEX *mutex); 00166 00167 int rt_mutex_inquire(RT_MUTEX *mutex, 00168 RT_MUTEX_INFO *info); 00169 00170 #ifdef __cplusplus 00171 } 00172 #endif 00173 00174 #endif /* !_XENO_MUTEX_H */