Skip to content

Instantly share code, notes, and snippets.

@shuffle2
Created April 14, 2014 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuffle2/10607905 to your computer and use it in GitHub Desktop.
Save shuffle2/10607905 to your computer and use it in GitHub Desktop.
diff --git a/Source/Core/Common/Thread.h b/Source/Core/Common/Thread.h
index d108359..8e03c6a 100644
--- a/Source/Core/Common/Thread.h
+++ b/Source/Core/Common/Thread.h
@@ -24,6 +24,8 @@
#include <sys/time.h>
#endif
+#include <concrt.h>
+
namespace Common
{
@@ -36,39 +38,25 @@ class Event
{
public:
Event()
- : is_set(false)
{}
void Set()
{
- std::lock_guard<std::mutex> lk(m_mutex);
- if (!is_set)
- {
- is_set = true;
- m_condvar.notify_one();
- }
+ m_event.set();
}
void Wait()
{
- std::unique_lock<std::mutex> lk(m_mutex);
- m_condvar.wait(lk, [&]{ return is_set; });
- is_set = false;
+ m_event.wait();
}
void Reset()
{
- std::unique_lock<std::mutex> lk(m_mutex);
- // no other action required, since wait loops on
- // the predicate and any lingering signal will get
- // cleared on the first iteration
- is_set = false;
+ m_event.reset();
}
private:
- volatile bool is_set;
- std::condition_variable m_condvar;
- std::mutex m_mutex;
+ concurrency::event m_event;
};
// TODO: doesn't work on windows with (count > 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment