00001
00022 #ifndef _RTAI_MUTEX_H
00023 #define _RTAI_MUTEX_H
00024
00025 #include <nucleus/synch.h>
00026 #include <rtai/types.h>
00027
00028 struct rt_task;
00029
00030 typedef struct rt_mutex_info {
00031
00032 int lockcnt;
00033
00034 int nwaiters;
00035
00036 char name[XNOBJECT_NAME_LEN];
00037
00038 } RT_MUTEX_INFO;
00039
00040 typedef struct rt_mutex_placeholder {
00041 rt_handle_t opaque;
00042 } RT_MUTEX_PLACEHOLDER;
00043
00044 #if defined(__KERNEL__) || defined(__RTAI_SIM__)
00045
00046 #define RTAI_MUTEX_MAGIC 0x55550505
00047
00048 typedef struct __rt_mutex {
00049
00050 unsigned magic;
00051
00052 xnsynch_t synch_base;
00053
00054 rt_handle_t handle;
00055
00056 struct rt_task *owner;
00057
00058 int lockcnt;
00059
00060 char name[XNOBJECT_NAME_LEN];
00061
00062 #if defined(__KERNEL__) && defined(CONFIG_RTAI_OPT_FUSION)
00063 pid_t cpid;
00064 #endif
00065
00066 } RT_MUTEX;
00067
00068 #ifdef __cplusplus
00069 extern "C" {
00070 #endif
00071
00072 int __mutex_pkg_init(void);
00073
00074 void __mutex_pkg_cleanup(void);
00075
00076 #ifdef __cplusplus
00077 }
00078 #endif
00079
00080 #else
00081
00082 typedef RT_MUTEX_PLACEHOLDER RT_MUTEX;
00083
00084 #ifdef __cplusplus
00085 extern "C" {
00086 #endif
00087
00088 int rt_mutex_bind(RT_MUTEX *mutex,
00089 const char *name);
00090
00091 static inline int rt_mutex_unbind (RT_MUTEX *mutex)
00092
00093 {
00094 mutex->opaque = RT_HANDLE_INVALID;
00095 return 0;
00096 }
00097
00098 #ifdef __cplusplus
00099 }
00100 #endif
00101
00102 #endif
00103
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107
00108
00109
00110 int rt_mutex_create(RT_MUTEX *mutex,
00111 const char *name);
00112
00113 int rt_mutex_delete(RT_MUTEX *mutex);
00114
00115 int rt_mutex_lock(RT_MUTEX *mutex);
00116
00117 int rt_mutex_unlock(RT_MUTEX *mutex);
00118
00119 int rt_mutex_inquire(RT_MUTEX *mutex,
00120 RT_MUTEX_INFO *info);
00121
00122 #ifdef __cplusplus
00123 }
00124 #endif
00125
00126 #endif