diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-17 14:38:13 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-17 14:38:13 +0100 |
| commit | b0082066596178f7b72d9963bffdec306a5b6250 (patch) | |
| tree | 83505561e50e8a09237b05bddb579a714344c219 /src/zencore/thread.cpp | |
| parent | use dynamic port assignment for tests (#545) (diff) | |
| download | zen-b0082066596178f7b72d9963bffdec306a5b6250.tar.xz zen-b0082066596178f7b72d9963bffdec306a5b6250.zip | |
fix named event (#553)
* fix named event timout and test, fix blocking queue
Diffstat (limited to 'src/zencore/thread.cpp')
| -rw-r--r-- | src/zencore/thread.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index a55bc5d69..6092895b0 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -411,9 +411,10 @@ NamedEvent::Wait(int TimeoutMs) } # if defined(_GNU_SOURCE) + const int TimeoutSec = TimeoutMs / 1000; struct timespec TimeoutValue = { - .tv_sec = TimeoutMs >> 10, - .tv_nsec = (TimeoutMs & 0x3ff) << 20, + .tv_sec = TimeoutSec, + .tv_nsec = (TimeoutMs - (TimeoutSec * 1000)) * 1000000, }; Result = semtimedop(Sem, &SemOp, 1, &TimeoutValue); # else @@ -431,7 +432,6 @@ NamedEvent::Wait(int TimeoutMs) TimeoutMs -= SleepTimeMs; } while (TimeoutMs > 0); # endif // _GNU_SOURCE - return Result == 0; #endif } @@ -1225,19 +1225,20 @@ TEST_CASE("NamedEvent") CHECK(!bEventSet); } + NamedEvent ReadyEvent(Name + "_ready"); + // Thread check std::thread Waiter = std::thread([Name]() { NamedEvent ReadyEvent(Name + "_ready"); ReadyEvent.Set(); NamedEvent TestEvent(Name); - TestEvent.Wait(100); + TestEvent.Wait(1000); }); - NamedEvent ReadyEvent(Name + "_ready"); ReadyEvent.Wait(); - zen::Sleep(50); + zen::Sleep(100); TestEvent.Set(); Waiter.join(); |