[threading linux] Implement suspend count
Add suspend count to thread implementation. Increment suspend count on suspend and decrement on resume. Wait on suspend count to be decremented to 0. Return suspend count on suspend and on resume before incr/decr. Fix naming of resume suspend count to make clear that suspend count is before incr/decr. Add test.
This commit is contained in:
committed by
Rick Gibbed
parent
382dd8860f
commit
e945a13957
@@ -849,6 +849,41 @@ TEST_CASE("Test Suspending Thread", "Thread") {
|
||||
thread->Resume();
|
||||
result = threading::Wait(thread.get(), false, 50ms);
|
||||
REQUIRE(result == threading::WaitResult::kSuccess);
|
||||
|
||||
// Test recursive suspend
|
||||
thread = threading::Thread::Create(params, func);
|
||||
thread->Suspend();
|
||||
thread->Suspend();
|
||||
result = threading::Wait(thread.get(), false, 50ms);
|
||||
REQUIRE(result == threading::WaitResult::kTimeout);
|
||||
thread->Resume();
|
||||
result = threading::Wait(thread.get(), false, 50ms);
|
||||
REQUIRE(result == threading::WaitResult::kTimeout);
|
||||
thread->Resume();
|
||||
result = threading::Wait(thread.get(), false, 50ms);
|
||||
REQUIRE(result == threading::WaitResult::kSuccess);
|
||||
|
||||
// Test suspend count
|
||||
uint32_t suspend_count = 0;
|
||||
thread = threading::Thread::Create(params, func);
|
||||
thread->Suspend(&suspend_count);
|
||||
REQUIRE(suspend_count == 0);
|
||||
thread->Suspend(&suspend_count);
|
||||
REQUIRE(suspend_count == 1);
|
||||
thread->Suspend(&suspend_count);
|
||||
REQUIRE(suspend_count == 2);
|
||||
thread->Resume(&suspend_count);
|
||||
REQUIRE(suspend_count == 3);
|
||||
thread->Resume(&suspend_count);
|
||||
REQUIRE(suspend_count == 2);
|
||||
thread->Resume(&suspend_count);
|
||||
REQUIRE(suspend_count == 1);
|
||||
thread->Suspend(&suspend_count);
|
||||
REQUIRE(suspend_count == 0);
|
||||
thread->Resume(&suspend_count);
|
||||
REQUIRE(suspend_count == 1);
|
||||
result = threading::Wait(thread.get(), false, 50ms);
|
||||
REQUIRE(result == threading::WaitResult::kSuccess);
|
||||
}
|
||||
|
||||
TEST_CASE("Test Thread QueueUserCallback", "Thread") {
|
||||
|
||||
Reference in New Issue
Block a user