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