Skip to content

Commit 1e5bd2c

Browse files
committed
Refs #8212. FIFO strategy in condition notify.
Signed-off-by: AdolfoMartinez <[email protected]>
1 parent 9ef6850 commit 1e5bd2c

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/cpp/rtps/transport/shared_mem/RobustInterprocessCondition.hpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class RobustInterprocessCondition
3131
public:
3232

3333
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)
3636
{
3737
init_sem_list();
3838
}
@@ -50,7 +50,7 @@ class RobustInterprocessCondition
5050
{
5151
bi::scoped_lock<bi::interprocess_mutex> lock(semaphore_lists_mutex_);
5252

53-
auto sem_index = list_listening_.tail();
53+
auto sem_index = list_listening_.head();
5454

5555
if (sem_index != SemaphoreList::LIST_NULL)
5656
{
@@ -67,12 +67,12 @@ class RobustInterprocessCondition
6767
{
6868
bi::scoped_lock<bi::interprocess_mutex> lock(semaphore_lists_mutex_);
6969

70-
auto sem_index = list_listening_.tail();
70+
auto sem_index = list_listening_.head();
7171

7272
while (sem_index != SemaphoreList::LIST_NULL)
7373
{
7474
semaphores_pool_[sem_index].sem.post();
75-
sem_index = semaphores_pool_[sem_index].prev;
75+
sem_index = semaphores_pool_[sem_index].next;
7676
}
7777
}
7878

@@ -100,7 +100,9 @@ class RobustInterprocessCondition
100100
Pr pred)
101101
{
102102
while (!pred())
103+
{
103104
do_wait(*lock.mutex());
105+
}
104106
}
105107

106108
/**
@@ -145,7 +147,8 @@ class RobustInterprocessCondition
145147
wait(lock, pred);
146148
return true;
147149
}
148-
while (!pred()){
150+
while (!pred())
151+
{
149152
if (!do_timed_wait(abs_time, *lock.mutex()))
150153
{
151154
return pred();
@@ -170,15 +173,18 @@ class RobustInterprocessCondition
170173
{
171174
private:
172175

176+
uint32_t head_;
173177
uint32_t tail_;
174178

175179
public:
176180

177181
static constexpr uint32_t LIST_NULL = static_cast<uint32_t>(-1);
178182

179183
SemaphoreList(
184+
uint32_t head,
180185
uint32_t tail)
181-
: tail_(tail)
186+
: head_(head)
187+
, tail_(tail)
182188
{
183189
}
184190

@@ -190,11 +196,16 @@ class RobustInterprocessCondition
190196
{
191197
sem_pool[tail_].next = sem_index;
192198
}
193-
199+
194200
sem_pool[sem_index].prev = tail_;
195201
sem_pool[sem_index].next = LIST_NULL;
196202

197203
tail_ = sem_index;
204+
205+
if (head_ == LIST_NULL)
206+
{
207+
head_ = sem_index;
208+
}
198209
}
199210

200211
inline uint32_t pop(
@@ -212,6 +223,11 @@ class RobustInterprocessCondition
212223
{
213224
sem_pool[tail_].next = LIST_NULL;
214225
}
226+
else
227+
{
228+
head_ = LIST_NULL;
229+
}
230+
215231
return sem_index;
216232
}
217233

@@ -220,6 +236,11 @@ class RobustInterprocessCondition
220236
return tail_;
221237
}
222238

239+
inline uint32_t head() const
240+
{
241+
return head_;
242+
}
243+
223244
inline void remove(
224245
uint32_t sem_index,
225246
SemaphoreNode* sem_pool)
@@ -239,6 +260,11 @@ class RobustInterprocessCondition
239260
sem_pool[next].prev = prev;
240261
}
241262

263+
if (head_ == sem_index)
264+
{
265+
head_ = next;
266+
}
267+
242268
if (tail_ == sem_index)
243269
{
244270
tail_ = prev;

0 commit comments

Comments
 (0)