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 
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 /* __KERNEL__ || __RTAI_SIM__ */
00103 
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107 
00108 /* Public interface. */
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 /* !_RTAI_MUTEX_H */

Generated on Wed Jun 22 22:54:02 2005 for RTAI Fusion API by  doxygen 1.4.1