@@ -31,8 +31,8 @@ class RobustInterprocessCondition
31
31
public:
32
32
33
33
RobustInterprocessCondition ()
34
- : list_listening_(SemaphoreList::LIST_NULL)
35
- , list_free_(MAX_LISTENERS-1 )
34
+ : list_listening_(SemaphoreList::LIST_NULL, SemaphoreList::LIST_NULL )
35
+ , list_free_(0 , MAX_LISTENERS-1 )
36
36
{
37
37
init_sem_list ();
38
38
}
@@ -50,7 +50,7 @@ class RobustInterprocessCondition
50
50
{
51
51
bi::scoped_lock<bi::interprocess_mutex> lock (semaphore_lists_mutex_);
52
52
53
- auto sem_index = list_listening_.tail ();
53
+ auto sem_index = list_listening_.head ();
54
54
55
55
if (sem_index != SemaphoreList::LIST_NULL)
56
56
{
@@ -67,12 +67,12 @@ class RobustInterprocessCondition
67
67
{
68
68
bi::scoped_lock<bi::interprocess_mutex> lock (semaphore_lists_mutex_);
69
69
70
- auto sem_index = list_listening_.tail ();
70
+ auto sem_index = list_listening_.head ();
71
71
72
72
while (sem_index != SemaphoreList::LIST_NULL)
73
73
{
74
74
semaphores_pool_[sem_index].sem .post ();
75
- sem_index = semaphores_pool_[sem_index].prev ;
75
+ sem_index = semaphores_pool_[sem_index].next ;
76
76
}
77
77
}
78
78
@@ -100,7 +100,9 @@ class RobustInterprocessCondition
100
100
Pr pred)
101
101
{
102
102
while (!pred ())
103
+ {
103
104
do_wait (*lock.mutex ());
105
+ }
104
106
}
105
107
106
108
/* *
@@ -145,7 +147,8 @@ class RobustInterprocessCondition
145
147
wait (lock, pred);
146
148
return true ;
147
149
}
148
- while (!pred ()){
150
+ while (!pred ())
151
+ {
149
152
if (!do_timed_wait (abs_time, *lock.mutex ()))
150
153
{
151
154
return pred ();
@@ -170,15 +173,18 @@ class RobustInterprocessCondition
170
173
{
171
174
private:
172
175
176
+ uint32_t head_;
173
177
uint32_t tail_;
174
178
175
179
public:
176
180
177
181
static constexpr uint32_t LIST_NULL = static_cast <uint32_t >(-1 );
178
182
179
183
SemaphoreList (
184
+ uint32_t head,
180
185
uint32_t tail)
181
- : tail_(tail)
186
+ : head_(head)
187
+ , tail_(tail)
182
188
{
183
189
}
184
190
@@ -190,11 +196,16 @@ class RobustInterprocessCondition
190
196
{
191
197
sem_pool[tail_].next = sem_index;
192
198
}
193
-
199
+
194
200
sem_pool[sem_index].prev = tail_;
195
201
sem_pool[sem_index].next = LIST_NULL;
196
202
197
203
tail_ = sem_index;
204
+
205
+ if (head_ == LIST_NULL)
206
+ {
207
+ head_ = sem_index;
208
+ }
198
209
}
199
210
200
211
inline uint32_t pop (
@@ -212,6 +223,11 @@ class RobustInterprocessCondition
212
223
{
213
224
sem_pool[tail_].next = LIST_NULL;
214
225
}
226
+ else
227
+ {
228
+ head_ = LIST_NULL;
229
+ }
230
+
215
231
return sem_index;
216
232
}
217
233
@@ -220,6 +236,11 @@ class RobustInterprocessCondition
220
236
return tail_;
221
237
}
222
238
239
+ inline uint32_t head () const
240
+ {
241
+ return head_;
242
+ }
243
+
223
244
inline void remove (
224
245
uint32_t sem_index,
225
246
SemaphoreNode* sem_pool)
@@ -239,6 +260,11 @@ class RobustInterprocessCondition
239
260
sem_pool[next].prev = prev;
240
261
}
241
262
263
+ if (head_ == sem_index)
264
+ {
265
+ head_ = next;
266
+ }
267
+
242
268
if (tail_ == sem_index)
243
269
{
244
270
tail_ = prev;
0 commit comments