Skip to content

Commit

Permalink
[#51] Fix condition variable for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 19, 2023
1 parent 37d89a4 commit cd408aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
14 changes: 6 additions & 8 deletions iceoryx2-pal/concurrency-sync/tests/condition_variable_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn condition_variable_notify_one_unblocks_one() {
let counter_old = counter.load(Ordering::Relaxed);

for i in 0..NUMBER_OF_THREADS {
sut.notify(|_| {
sut.notify_one(|_| {
triggered_thread.fetch_add(1, Ordering::Relaxed);
});

Expand Down Expand Up @@ -142,7 +142,7 @@ fn condition_variable_notify_all_unblocks_all() {
std::thread::sleep(TIMEOUT);
let counter_old = counter.load(Ordering::Relaxed);

sut.notify(|_| {
sut.notify_all(|_| {
triggered_thread.fetch_add(1, Ordering::Relaxed);
});

Expand Down Expand Up @@ -192,12 +192,10 @@ fn condition_variable_mutex_is_locked_when_wait_returns() {
std::thread::sleep(TIMEOUT);
let counter_old = counter.load(Ordering::Relaxed);

for _ in 0..NUMBER_OF_THREADS {
sut.notify(|_| {
triggered_thread.fetch_add(1, Ordering::Relaxed);
});
std::thread::sleep(TIMEOUT);
}
sut.notify_all(|_| {
triggered_thread.fetch_add(1, Ordering::Relaxed);
});
std::thread::sleep(TIMEOUT);

assert_that!(counter_old, eq 0);
});
Expand Down
10 changes: 3 additions & 7 deletions iceoryx2-pal/concurrency-sync/tests/semaphore_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ fn semaphore_post_and_try_wait_works() {
}
assert_that!(!sut.try_wait(), eq true);

for _ in 0..initial_value {
sut.post(|_| {});
}
sut.post(|_| {}, initial_value);

for _ in 0..initial_value {
assert_that!(sut.try_wait(), eq true);
Expand All @@ -50,9 +48,7 @@ fn semaphore_post_and_wait_works() {
}
assert_that!(!sut.wait(|_, _| false), eq true);

for _ in 0..initial_value {
sut.post(|_| {});
}
sut.post(|_| {}, initial_value);

for _ in 0..initial_value {
assert_that!(sut.wait(|_, _| false), eq true);
Expand All @@ -74,7 +70,7 @@ fn semaphore_wait_blocks() {

std::thread::sleep(TIMEOUT);
let old_counter = counter.load(Ordering::Relaxed);
sut.post(|_| {});
sut.post(|_| {}, 1);

assert_that!(old_counter, eq 0);
});
Expand Down
6 changes: 3 additions & 3 deletions iceoryx2-pal/posix/src/windows/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,14 @@ pub unsafe fn pthread_rwlock_timedrdlock(
}

pub unsafe fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> int {
(*cond).cv.notify(|atomic| {
(*cond).cv.notify_all(|atomic| {
WakeByAddressAll((atomic as *const AtomicU32).cast());
});
Errno::ESUCCES as _
}

pub unsafe fn pthread_cond_signal(cond: *mut pthread_cond_t) -> int {
(*cond).cv.notify(|atomic| {
(*cond).cv.notify_one(|atomic| {
WakeByAddressSingle((atomic as *const AtomicU32).cast());
});
Errno::ESUCCES as _
Expand Down Expand Up @@ -767,7 +767,7 @@ pub unsafe fn pthread_cond_timedwait(
4,
timeout as _,
), ignore ERROR_TIMEOUT };
true
false
},
|atomic, value| {
win32call! { WaitOnAddress(
Expand Down
9 changes: 6 additions & 3 deletions iceoryx2-pal/posix/src/windows/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ pub unsafe fn sem_post(sem: *mut sem_t) -> int {
return -1;
}

(*sem).semaphore.post(|atomic| {
WakeByAddressSingle((atomic as *const AtomicU32).cast());
});
(*sem).semaphore.post(
|atomic| {
WakeByAddressSingle((atomic as *const AtomicU32).cast());
},
1,
);

Errno::set(Errno::ESUCCES);
0
Expand Down

0 comments on commit cd408aa

Please sign in to comment.