include/native/mutex.h

Go to the documentation of this file.
00001 
00022 #ifndef _XENO_MUTEX_H
00023 #define _XENO_MUTEX_H
00024 
00025 #include <nucleus/synch.h>
00026 #include <native/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         xnhandle_t opaque;
00042 } RT_MUTEX_PLACEHOLDER;
00043 
00044 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00045 
00046 #define XENO_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         xnhandle_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_XENO_OPT_PERVASIVE)
00063         pid_t cpid;             /* !< Creator's pid. */
00064 #endif /* __KERNEL__ && CONFIG_XENO_OPT_PERVASIVE */
00065 
00066 } RT_MUTEX;
00067 
00068 #ifdef __cplusplus
00069 extern "C" {
00070 #endif
00071 
00072 int __native_mutex_pkg_init(void);
00073 
00074 void __native_mutex_pkg_cleanup(void);
00075 
00076 #ifdef __cplusplus
00077 }
00078 #endif
00079 
00080 #else /* !(__KERNEL__ || __XENO_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 = XN_NO_HANDLE;
00096         return 0;
00097 }
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102 
00103 #endif /* __KERNEL__ || __XENO_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_acquire(RT_MUTEX *mutex,
00117                      RTIME timeout);
00118 
00119 int rt_mutex_release(RT_MUTEX *mutex);
00120 
00121 int rt_mutex_inquire(RT_MUTEX *mutex,
00122                      RT_MUTEX_INFO *info);
00123 
00124 #ifdef __KERNEL__
00125 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
00126 static inline int __deprecated_call__ rt_mutex_lock(RT_MUTEX *mutex, RTIME timeout)
00127 {
00128         return rt_mutex_acquire(mutex, timeout);
00129 }
00130 
00131 static inline int __deprecated_call__ rt_mutex_unlock(RT_MUTEX *mutex)
00132 {
00133         return rt_mutex_release(mutex);
00134 }
00135 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) */
00136 #else /* !__KERNEL__ */
00137 
00138 int rt_mutex_lock(RT_MUTEX *mutex,
00139                   RTIME timeout);
00140 
00141 int rt_mutex_unlock(RT_MUTEX *mutex);
00142 
00143 #endif /* __KERNEL__ */
00144 
00145 #ifdef __cplusplus
00146 }
00147 #endif
00148 
00149 #endif /* !_XENO_MUTEX_H */

Generated on Mon Dec 25 13:57:10 2006 for Xenomai API by  doxygen 1.4.6