From 9137e56381763ccf474681cab56a4659d59529e3 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Sun, 22 Apr 2018 14:56:16 -0700 Subject: [PATCH] [threading linux] Fix events with closed handles Linux: Remove copy and destroy call in make_unique invokation which closes handles on all events. Testing: Add Wait test for Events set and unset. --- src/xenia/base/testing/threading_test.cc | 19 +++++++++++++++++-- src/xenia/base/threading_posix.cc | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/xenia/base/testing/threading_test.cc b/src/xenia/base/testing/threading_test.cc index f1301be87..b8e40cccd 100644 --- a/src/xenia/base/testing/threading_test.cc +++ b/src/xenia/base/testing/threading_test.cc @@ -174,8 +174,23 @@ TEST_CASE("Signal and Wait") { } TEST_CASE("Wait on Event", "Event") { - // TODO(bwrsandman): - REQUIRE(true); + auto evt = Event::CreateAutoResetEvent(false); + WaitResult result; + + // Call wait on unset Event + result = Wait(evt.get(), false, 50ms); + REQUIRE(result == WaitResult::kTimeout); + + // Call wait on set Event + evt->Set(); + result = Wait(evt.get(), false, 50ms); + REQUIRE(result == WaitResult::kSuccess); + + // Call wait on now consumed Event + result = Wait(evt.get(), false, 50ms); + REQUIRE(result == WaitResult::kTimeout); + + // TODO(bwrsandman): test Reset() and Pulse() } TEST_CASE("Wait on Semaphore", "Semaphore") { diff --git a/src/xenia/base/threading_posix.cc b/src/xenia/base/threading_posix.cc index 823dc4419..827f5cd45 100644 --- a/src/xenia/base/threading_posix.cc +++ b/src/xenia/base/threading_posix.cc @@ -357,7 +357,7 @@ std::unique_ptr Event::CreateAutoResetEvent(bool initial_state) { return nullptr; } - return std::make_unique(PosixEvent(fd)); + return std::make_unique(fd); } // TODO(dougvj)