[threading linux] Implement suspendable pthreads

Use real-time event interrupt to communicate suspend in timely manner.
Use conditional_variable to implement suspend wait and resume trigger.

Ignore real-time event 36 in .gdbinit which is used to signal suspend.

Test suspending threads.
This commit is contained in:
Sandy Carter
2019-01-11 14:47:59 -05:00
committed by Rick Gibbed
parent b2912e7891
commit 4397f25325
3 changed files with 69 additions and 13 deletions

View File

@@ -759,8 +759,29 @@ TEST_CASE("Create and Run Thread", "Thread") {
}
TEST_CASE("Test Suspending Thread", "Thread") {
// TODO(bwrsandman): Test suspension and resume
REQUIRE(true);
std::unique_ptr<Thread> thread;
WaitResult result;
Thread::CreationParameters params = {};
auto func = [] { Sleep(20ms); };
// Create initially suspended
params.create_suspended = true;
thread = threading::Thread::Create(params, func);
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);
params.create_suspended = false;
// Create and then suspend
thread = threading::Thread::Create(params, func);
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::kSuccess);
}
TEST_CASE("Test Thread QueueUserCallback", "Thread") {