Skip to content

Commit a8cb41f

Browse files
committed
[#51] Use blocking_wait_while to make test more robust, rename wait_while into blocking_wait_while to be consistent with other blocking functions
1 parent af0ec81 commit a8cb41f

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

iceoryx2-bb/posix/src/condition_variable.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'mutex, 'handle, T: Debug> From<MutexLockError<'mutex, 'handle, T>>
153153
/// use iceoryx2_bb_posix::mutex::*;
154154
///
155155
///
156-
/// // create a condition variable which allows multiple predicates in wait_while nad
156+
/// // create a condition variable which allows multiple predicates in blocking_wait_while nad
157157
/// // timed_wait_while
158158
/// let mtx_handle = MutexHandle::<i32>::new();
159159
/// let condvar = ConditionVariableBuilder::new()
@@ -237,7 +237,7 @@ impl ConditionVariableBuilder {
237237
/// modified and used for triggering.
238238
///
239239
/// The condition variable can use
240-
/// multiple conditions in [`MultiConditionVariable::wait_while()`] and
240+
/// multiple conditions in [`MultiConditionVariable::blocking_wait_while()`] and
241241
/// [`MultiConditionVariable::timed_wait_while()`] but is only able to trigger all waiters.
242242
pub fn create_multi_condition_variable<T: Debug>(
243243
self,
@@ -252,7 +252,7 @@ impl ConditionVariableBuilder {
252252
///
253253
/// The condition variable has one fixed
254254
/// condition which has to be provided on construction. The methods
255-
/// [`ConditionVariable::wait_while()`] and
255+
/// [`ConditionVariable::blocking_wait_while()`] and
256256
/// [`ConditionVariable::timed_wait_while()`] will wait on that preset condition until
257257
/// it is satisfied.
258258
/// The restriction to a preset fixed condition comes with the feature to signal single waiters
@@ -489,7 +489,7 @@ pub trait BasicConditionVariableInterface<T: Debug>:
489489
}
490490

491491
/// Condition variable which allows to use multiple conditions in
492-
/// [`MultiConditionVariable::wait_while()`] and
492+
/// [`MultiConditionVariable::blocking_wait_while()`] and
493493
/// [`MultiConditionVariable::timed_wait_while()`] concurrently but with the draw
494494
/// back that only all waiters can be triggered and not one.
495495
/// The reason is when one waits on multiple
@@ -505,7 +505,7 @@ pub trait BasicConditionVariableInterface<T: Debug>:
505505
/// is written.
506506
/// The condition variable provides the following features:
507507
/// * wait on the condition variable: [wait](BasicConditionVariableInterface::wait()), [timed_wait](BasicConditionVariableInterface::timed_wait())
508-
/// * wait until a defined condition occurs: [wait_while](MultiConditionVariable::wait_while()), [timed_wait_while](MultiConditionVariable::timed_wait_while())
508+
/// * wait until a defined condition occurs: [blocking_wait_while](MultiConditionVariable::blocking_wait_while()), [timed_wait_while](MultiConditionVariable::timed_wait_while())
509509
/// * modify condition variable and then notify waiters:
510510
/// [notify_all](MultiConditionVariable::notify_all()), [modify_notify_all](MultiConditionVariable::modify_notify_all())
511511
/// * trigger waiters without changing condition variable: [trigger_all](BasicConditionVariableInterface::trigger_all())
@@ -530,7 +530,7 @@ pub trait BasicConditionVariableInterface<T: Debug>:
530530
/// thread::scope(|s| {
531531
/// let t1 = s.spawn(|| {
532532
/// // wait until value is 5000
533-
/// let guard = cv.wait_while(|t| *t == 5000).expect("failed to wait");
533+
/// let guard = cv.blocking_wait_while(|t| *t == 5000).expect("failed to wait");
534534
/// println!("cv value changed to 5000");
535535
/// });
536536
///
@@ -589,12 +589,11 @@ impl<'mtx_handle, T: Debug> MultiConditionVariable<'mtx_handle, T> {
589589
/// [`MultiConditionVariable::modify_notify_all()`] or
590590
/// [`BasicConditionVariableInterface::trigger_all()`]
591591
/// and the provided predicate returns true.
592-
pub fn wait_while<P: FnMut(&mut T) -> bool>(
592+
pub fn blocking_wait_while<P: FnMut(&mut T) -> bool>(
593593
&self,
594594
mut predicate: P,
595595
) -> Result<MutexGuard<'_, '_, T>, ConditionVariableWaitError<'_, '_, T>> {
596-
let mut guard =
597-
fail!(from self, when self.mutex.lock(), "Failed to lock mutex in wait_while.");
596+
let mut guard = fail!(from self, when self.mutex.lock(), "Failed to lock mutex in blocking_wait_while.");
598597

599598
while !(predicate)(&mut *guard) {
600599
self.condvar.pthread_wait(&self.mutex)?;
@@ -742,7 +741,7 @@ impl<T: Debug> Drop for ConditionVariableGuard<'_, '_, '_, T> {
742741
}
743742

744743
/// Condition variable which requires a fixed predicate on creation which is then used in
745-
/// [`ConditionVariable::wait_while()`] and
744+
/// [`ConditionVariable::blocking_wait_while()`] and
746745
/// [`ConditionVariable::timed_wait_while()`] concurrently with the benefit of triggering
747746
/// single waiters.
748747
/// The reason is when one waits on multiple
@@ -758,7 +757,7 @@ impl<T: Debug> Drop for ConditionVariableGuard<'_, '_, '_, T> {
758757
/// is written.
759758
/// The condition variable provides the following features:
760759
/// * wait on the condition variable: [wait](BasicConditionVariableInterface::wait()), [timed_wait](BasicConditionVariableInterface::timed_wait())
761-
/// * wait until a defined condition occurs: [wait_while](ConditionVariable::wait_while()), [timed_wait_while](ConditionVariable::timed_wait_while())
760+
/// * wait until a defined condition occurs: [blocking_wait_while](ConditionVariable::blocking_wait_while()), [timed_wait_while](ConditionVariable::timed_wait_while())
762761
/// * modify condition variable and then notify waiters:
763762
/// [notify_all](ConditionVariable::notify_all()), [modify_notify_all](ConditionVariable::modify_notify_all()),
764763
/// [notify_one](ConditionVariable::notify_one()), [modify_notify_one](ConditionVariable::modify_notify_one())
@@ -786,7 +785,7 @@ impl<T: Debug> Drop for ConditionVariableGuard<'_, '_, '_, T> {
786785
/// thread::scope(|s| {
787786
/// let t1 = s.spawn(|| {
788787
/// // wait until value is 5000
789-
/// let guard = cv.wait_while().expect("failed to wait");
788+
/// let guard = cv.blocking_wait_while().expect("failed to wait");
790789
/// println!("cv value is greater or equal 5000");
791790
/// });
792791
///
@@ -856,13 +855,14 @@ impl<'mtx_handle, T: Debug> ConditionVariable<'mtx_handle, T> {
856855
/// [`BasicConditionVariableInterface::trigger_all()`] or
857856
/// [`ConditionVariable::trigger_one()`]
858857
/// and the provided predicate returns true.
859-
pub fn wait_while(
858+
pub fn blocking_wait_while(
860859
&self,
861860
) -> Result<
862861
MutexGuard<'_, '_, ConditionVariableData<T>>,
863862
ConditionVariableWaitError<'_, '_, ConditionVariableData<T>>,
864863
> {
865-
let guard = fail!(from self, when self.mutex.lock(), "failed to lock mutex in wait_while");
864+
let guard =
865+
fail!(from self, when self.mutex.lock(), "failed to lock mutex in blocking_wait_while");
866866

867867
while !self.call_underlying_predicate(&guard) {
868868
self.condvar.pthread_wait(&self.mutex)?;

iceoryx2-bb/posix/tests/condition_variable_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn multi_condition_variable_wait_while_is_signalled_by_notify_all() {
4949

5050
thread::scope(|s| {
5151
let t1 = s.spawn(|| {
52-
let guard = sut.wait_while(|t| *t == 4456).unwrap();
52+
let guard = sut.blocking_wait_while(|t| *t == 4456).unwrap();
5353
assert_that!(*guard, eq 4456);
5454
});
5555

@@ -78,7 +78,7 @@ fn multi_condition_variable_wait_while_is_signalled_by_modify_notify_all() {
7878

7979
thread::scope(|s| {
8080
let t1 = s.spawn(|| {
81-
let guard = sut.wait_while(|t| *t == 4456).unwrap();
81+
let guard = sut.blocking_wait_while(|t| *t == 4456).unwrap();
8282
assert_that!(*guard, eq 4456);
8383
});
8484

@@ -254,14 +254,14 @@ fn condition_variable_notify_all_signals_all_waiters() {
254254
let sut_thread1 = Arc::clone(&sut);
255255
let counter_thread1 = Arc::clone(&counter);
256256
let t1 = s.spawn(move || {
257-
sut_thread1.wait_while().unwrap();
257+
sut_thread1.blocking_wait_while().unwrap();
258258
counter_thread1.fetch_add(1, Ordering::Relaxed);
259259
});
260260

261261
let sut_thread2 = Arc::clone(&sut);
262262
let counter_thread2 = Arc::clone(&counter);
263263
let t2 = s.spawn(move || {
264-
sut_thread2.wait_while().unwrap();
264+
sut_thread2.blocking_wait_while().unwrap();
265265
counter_thread2.fetch_add(1, Ordering::Relaxed);
266266
});
267267

@@ -300,14 +300,14 @@ fn condition_variable_notify_one_signals_one_waiter() {
300300
let sut_thread1 = Arc::clone(&sut);
301301
let counter_thread1 = Arc::clone(&counter);
302302
let t1 = s.spawn(move || {
303-
sut_thread1.wait_while().unwrap();
303+
sut_thread1.blocking_wait_while().unwrap();
304304
counter_thread1.fetch_add(1, Ordering::Relaxed);
305305
});
306306

307307
let sut_thread2 = Arc::clone(&sut);
308308
let counter_thread2 = Arc::clone(&counter);
309309
let t2 = s.spawn(move || {
310-
sut_thread2.wait_while().unwrap();
310+
sut_thread2.blocking_wait_while().unwrap();
311311
counter_thread2.fetch_add(1, Ordering::Relaxed);
312312
});
313313

@@ -383,14 +383,14 @@ fn condition_variable_modify_notify_one_signals_one_waiter() {
383383
let sut_thread1 = Arc::clone(&sut);
384384
let counter_thread1 = Arc::clone(&counter);
385385
let t1 = s.spawn(move || {
386-
sut_thread1.timed_wait_while(TIMEOUT * 10).unwrap();
386+
sut_thread1.blocking_wait_while().unwrap();
387387
counter_thread1.fetch_add(1, Ordering::Relaxed);
388388
});
389389

390390
let sut_thread2 = Arc::clone(&sut);
391391
let counter_thread2 = Arc::clone(&counter);
392392
let t2 = s.spawn(move || {
393-
sut_thread2.timed_wait_while(TIMEOUT * 10).unwrap();
393+
sut_thread2.blocking_wait_while().unwrap();
394394
counter_thread2.fetch_add(1, Ordering::Relaxed);
395395
});
396396

@@ -466,5 +466,5 @@ fn condition_variable_wait_while_does_not_wait_when_predicate_is_fulfilled() {
466466
);
467467
sut.lock().unwrap().value = 9999999;
468468

469-
assert_that!(sut.wait_while(), is_ok);
469+
assert_that!(sut.blocking_wait_while(), is_ok);
470470
}

iceoryx2-cal/src/event/process_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<Id: crate::event::TriggerId + 'static> Listener<Id> for Duplex<Id> {
193193

194194
fn blocking_wait(&self) -> Result<Option<Id>, ListenerWaitError> {
195195
let msg = "Failed to blocking_wait";
196-
match self.management.as_ref().borrow_cvar().wait_while() {
196+
match self.management.as_ref().borrow_cvar().blocking_wait_while() {
197197
Err(v) => {
198198
fail!(from self, with ListenerWaitError::InternalFailure,
199199
"{} due to an internal failure in the underlying condition variable ({:?}).", msg, v);

0 commit comments

Comments
 (0)