mutex.h

Go to the documentation of this file.
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;        /* !< Lock nesting level (> 0 means "locked"). */
00033 
00034     int nwaiters;       /* !< Number of pending tasks. */
00035 
00036     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
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;   /* !< Magic code - must be first */
00051 
00052     xnsynch_t synch_base; /* !< Base synchronization object. */
00053 
00054     rt_handle_t handle; /* !< Handle in registry -- zero if unregistered. */
00055 
00056     struct rt_task *owner;      /* !< Current mutex owner. */
00057 
00058     int lockcnt;        /* !< Lock nesting level (> 0 means "locked"). */
00059 
00060     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00061 
00062 #if defined(__KERNEL__) && defined(CONFIG_RTAI_OPT_FUSION)
00063     pid_t cpid;                 /* !< Creator's pid. */
00064 #endif /* __KERNEL__ && CONFIG_RTAI_OPT_FUSION */
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 /* !(__KERNEL__ || __RTAI_SIM__) */
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                   RTIME timeout);
00091 
00092 static inline int rt_mutex_unbind (RT_MUTEX *mutex)
00093 
00094 {
00095     mutex->opaque = RT_HANDLE_INVALID;
00096     return 0;
00097 }
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102 
00103 #endif /* __KERNEL__ || __RTAI_SIM__ */
00104 
00105 #ifdef __cplusplus
00106 extern "C" {
00107 #endif
00108 
00109 /* Public interface. */
00110 
00111 int rt_mutex_create(RT_MUTEX *mutex,
00112                     const char *name);
00113 
00114 int rt_mutex_delete(RT_MUTEX *mutex);
00115 
00116 int rt_mutex_lock(RT_MUTEX *mutex,
00117                   RTIME timeout);
00118 
00119 int rt_mutex_unlock(RT_MUTEX *mutex);
00120 
00121 int rt_mutex_inquire(RT_MUTEX *mutex,
00122                      RT_MUTEX_INFO *info);
00123 
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127 
00128 #endif /* !_RTAI_MUTEX_H */

Generated on Sat Sep 3 12:32:47 2005 for RTAI Fusion API by  doxygen 1.4.2