Xenomai API  2.6.5
mutex.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_MUTEX_H
23 #define _XENO_MUTEX_H
24 
25 #include <native/types.h>
26 
27 struct rt_task;
28 
33 typedef struct rt_mutex_info {
34 
35  int locked;
37  int nwaiters;
39  char name[XNOBJECT_NAME_LEN];
41  char owner[XNOBJECT_NAME_LEN];
45 
46 typedef struct rt_mutex_placeholder {
47 
48  xnhandle_t opaque;
49 
50 #ifdef CONFIG_XENO_FASTSYNCH
51  xnarch_atomic_t *fastlock;
52 
53  int lockcnt;
54 #endif /* CONFIG_XENO_FASTSYNCH */
55 
56 } RT_MUTEX_PLACEHOLDER;
57 
58 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
59 
60 #include <nucleus/synch.h>
61 #include <native/ppd.h>
62 
63 #define XENO_MUTEX_MAGIC 0x55550505
64 
65 #define RT_MUTEX_EXPORTED XNSYNCH_SPARE0 /* Mutex registered by name */
66 
67 typedef struct __rt_mutex {
68 
69  unsigned magic; /* !< Magic code - must be first */
70 
71  xnsynch_t synch_base; /* !< Base synchronization object. */
72 
73  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
74 
75  int lockcnt; /* !< Lock nesting level (> 0 means "locked"). */
76 
77  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
78 
79 #ifdef CONFIG_XENO_OPT_PERVASIVE
80  pid_t cpid; /* !< Creator's pid. */
81 #endif /* CONFIG_XENO_OPT_PERVASIVE */
82 
83  xnholder_t rlink; /* !< Link in resource queue. */
84 
85 #define rlink2mutex(ln) container_of(ln, RT_MUTEX, rlink)
86 
87  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
88 
89 } RT_MUTEX;
90 
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
95 #ifdef CONFIG_XENO_OPT_NATIVE_MUTEX
96 
97 int __native_mutex_pkg_init(void);
98 
99 void __native_mutex_pkg_cleanup(void);
100 
101 static inline void __native_mutex_flush_rq(xnqueue_t *rq)
102 {
103  xeno_flush_rq(RT_MUTEX, rq, mutex);
104 }
105 
106 int rt_mutex_acquire_inner(RT_MUTEX *mutex, RTIME timeout,
107  xntmode_t timeout_mode);
108 
109 #else /* !CONFIG_XENO_OPT_NATIVE_MUTEX */
110 
111 #define __native_mutex_pkg_init() ({ 0; })
112 #define __native_mutex_pkg_cleanup() do { } while(0)
113 #define __native_mutex_flush_rq(rq) do { } while(0)
114 
115 #endif /* !CONFIG_XENO_OPT_NATIVE_MUTEX */
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #else /* !(__KERNEL__ || __XENO_SIM__) */
122 
123 typedef RT_MUTEX_PLACEHOLDER RT_MUTEX;
124 
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128 
129 int rt_mutex_bind(RT_MUTEX *mutex,
130  const char *name,
131  RTIME timeout);
132 
133 static inline int rt_mutex_unbind (RT_MUTEX *mutex)
134 
135 {
136  mutex->opaque = XN_NO_HANDLE;
137  return 0;
138 }
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* __KERNEL__ || __XENO_SIM__ */
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
150 int rt_mutex_create_inner(RT_MUTEX *mutex, const char *name, int global);
151 
152 /* Public interface. */
153 
154 int rt_mutex_create(RT_MUTEX *mutex,
155  const char *name);
156 
157 int rt_mutex_delete(RT_MUTEX *mutex);
158 
159 int rt_mutex_acquire(RT_MUTEX *mutex,
160  RTIME timeout);
161 
162 int rt_mutex_acquire_until(RT_MUTEX *mutex,
163  RTIME timeout);
164 
165 int rt_mutex_release(RT_MUTEX *mutex);
166 
167 int rt_mutex_inquire(RT_MUTEX *mutex,
168  RT_MUTEX_INFO *info);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* !_XENO_MUTEX_H */
int rt_mutex_delete(RT_MUTEX *mutex)
Delete a mutex.
Definition: mutex.c:67
int rt_mutex_bind(RT_MUTEX *mutex, const char *name, RTIME timeout)
Bind to a mutex.
Definition: mutex.c:48
int rt_mutex_create(RT_MUTEX *mutex, const char *name)
Create a mutex.
Definition: mutex.c:29
int rt_mutex_release(RT_MUTEX *mutex)
Unlock mutex.
Definition: mutex.c:156
static int rt_mutex_unbind(RT_MUTEX *mutex)
Unbind from a mutex.
Definition: mutex.h:133
int nwaiters
Number of pending tasks.
Definition: mutex.h:37
Structure containing mutex information useful to users.
Definition: mutex.h:33
int locked
0 if mutex is locked.
Definition: mutex.h:35
This file is part of the Xenomai project.
int rt_mutex_acquire_until(RT_MUTEX *mutex, RTIME timeout)
Acquire a mutex (with absolute timeout date).
Definition: mutex.c:151
int rt_mutex_inquire(RT_MUTEX *mutex, RT_MUTEX_INFO *info)
Inquire about a mutex.
Definition: mutex.c:188
int rt_mutex_acquire(RT_MUTEX *mutex, RTIME timeout)
Acquire a mutex.
Definition: mutex.c:146
char owner[XNOBJECT_NAME_LEN]
Symbolic name of the current owner, empty if unlocked.
Definition: mutex.h:41
struct rt_mutex_info RT_MUTEX_INFO
Structure containing mutex information useful to users.
char name[XNOBJECT_NAME_LEN]
Symbolic name.
Definition: mutex.h:39
This file is part of the Xenomai project.