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 lockcnt;
00037 int nwaiters;
00039 char name[XNOBJECT_NAME_LEN];
00041 } RT_MUTEX_INFO;
00042
00043 typedef struct rt_mutex_placeholder {
00044 xnhandle_t opaque;
00045 } RT_MUTEX_PLACEHOLDER;
00046
00047 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
00048
00049 #include <nucleus/synch.h>
00050 #include <native/ppd.h>
00051
00052 #define XENO_MUTEX_MAGIC 0x55550505
00053
00054 typedef struct __rt_mutex {
00055
00056 unsigned magic;
00057
00058 xnsynch_t synch_base;
00059
00060 xnhandle_t handle;
00061
00062 int lockcnt;
00063
00064 char name[XNOBJECT_NAME_LEN];
00065
00066 #ifdef CONFIG_XENO_OPT_PERVASIVE
00067 pid_t cpid;
00068 #endif
00069
00070 xnholder_t rlink;
00071
00072 #define rlink2mutex(ln) container_of(ln, RT_MUTEX, rlink)
00073
00074 xnqueue_t *rqueue;
00075
00076 } RT_MUTEX;
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00082 #ifdef CONFIG_XENO_OPT_NATIVE_MUTEX
00083
00084 int __native_mutex_pkg_init(void);
00085
00086 void __native_mutex_pkg_cleanup(void);
00087
00088 static inline void __native_mutex_flush_rq(xnqueue_t *rq)
00089 {
00090 xeno_flush_rq(RT_MUTEX, rq, mutex);
00091 }
00092
00093 #else
00094
00095 #define __native_mutex_pkg_init() ({ 0; })
00096 #define __native_mutex_pkg_cleanup() do { } while(0)
00097 #define __native_mutex_flush_rq(rq) do { } while(0)
00098
00099 #endif
00100
00101 #ifdef __cplusplus
00102 }
00103 #endif
00104
00105 #else
00106
00107 typedef RT_MUTEX_PLACEHOLDER RT_MUTEX;
00108
00109 #ifdef __cplusplus
00110 extern "C" {
00111 #endif
00112
00113 int rt_mutex_bind(RT_MUTEX *mutex,
00114 const char *name,
00115 RTIME timeout);
00116
00117 static inline int rt_mutex_unbind (RT_MUTEX *mutex)
00118
00119 {
00120 mutex->opaque = XN_NO_HANDLE;
00121 return 0;
00122 }
00123
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127
00128 #endif
00129
00130 #ifdef __cplusplus
00131 extern "C" {
00132 #endif
00133
00134
00135
00136 int rt_mutex_create(RT_MUTEX *mutex,
00137 const char *name);
00138
00139 int rt_mutex_delete(RT_MUTEX *mutex);
00140
00141 int rt_mutex_acquire(RT_MUTEX *mutex,
00142 RTIME timeout);
00143
00144 int rt_mutex_release(RT_MUTEX *mutex);
00145
00146 int rt_mutex_inquire(RT_MUTEX *mutex,
00147 RT_MUTEX_INFO *info);
00148
00149 #ifdef __KERNEL__
00150 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
00151 static inline int __deprecated_call__ rt_mutex_lock(RT_MUTEX *mutex, RTIME timeout)
00152 {
00153 return rt_mutex_acquire(mutex, timeout);
00154 }
00155
00156 static inline int __deprecated_call__ rt_mutex_unlock(RT_MUTEX *mutex)
00157 {
00158 return rt_mutex_release(mutex);
00159 }
00160 #endif
00161 #else
00162
00163 int rt_mutex_lock(RT_MUTEX *mutex,
00164 RTIME timeout);
00165
00166 int rt_mutex_unlock(RT_MUTEX *mutex);
00167
00168 #endif
00169
00170 #ifdef __cplusplus
00171 }
00172 #endif
00173
00174 #endif