Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/Thread.cpp

Issue 10026001: Cross-platform thread primitives (Closed)
Patch Set: Don't unlock/signal mutices/conditions, move Mutex and Condition to the top level Created April 4, 2013, 2:52 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/Thread.h ('k') | test/Thread.cpp » ('j') | test/Thread.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/Thread.cpp
===================================================================
--- a/src/Thread.cpp
+++ b/src/Thread.cpp
@@ -10,7 +10,7 @@
}
}
-Thread::Mutex::Mutex()
+Mutex::Mutex()
{
#ifdef WIN32
InitializeCriticalSection(&nativeMutex);
@@ -19,9 +19,8 @@
#endif
}
-Thread::Mutex::~Mutex()
+Mutex::~Mutex()
{
- Unlock();
#ifdef WIN32
DeleteCriticalSection(&nativeMutex);
#else
@@ -29,7 +28,7 @@
#endif
}
-void Thread::Mutex::Lock()
+void Mutex::Lock()
{
#ifdef WIN32
EnterCriticalSection(&nativeMutex);
@@ -38,7 +37,7 @@
#endif
}
-void Thread::Mutex::Unlock()
+void Mutex::Unlock()
{
#ifdef WIN32
LeaveCriticalSection(&nativeMutex);
@@ -47,7 +46,7 @@
#endif
}
-Thread::Condition::Condition()
+ConditionVariable::ConditionVariable()
{
#ifdef WIN32
InitializeConditionVariable(&nativeCondition);
@@ -56,15 +55,14 @@
#endif
}
-Thread::Condition::~Condition()
+ConditionVariable::~ConditionVariable()
{
#ifndef WIN32
- Signal();
pthread_cond_destroy(&nativeCondition);
#endif
}
-void Thread::Condition::Wait(Thread::Mutex& mutex)
+void ConditionVariable::Wait(Mutex& mutex)
{
#ifdef WIN32
SleepConditionVariableCS(&nativeCondition, &mutex.nativeMutex, INFINITE);
@@ -73,7 +71,7 @@
#endif
}
-void Thread::Condition::Signal()
+void ConditionVariable::Signal()
{
#ifdef WIN32
WakeConditionVariable(&nativeCondition);
@@ -89,17 +87,17 @@
void Thread::Start()
{
#ifdef WIN32
- thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CallRun, this, 0, 0);
+ nativeThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CallRun, this, 0, 0);
#else
- pthread_create(&thread, 0, (void *(*)(void*)) &CallRun, this);
+ pthread_create(&nativeThread, 0, (void *(*)(void*)) &CallRun, this);
#endif
}
void Thread::Join()
{
#ifdef WIN32
- WaitForSingleObject(thread, INFINITE);
+ WaitForSingleObject(nativeThread, INFINITE);
#else
- pthread_join(thread, 0);
+ pthread_join(nativeThread, 0);
#endif
}
« no previous file with comments | « src/Thread.h ('k') | test/Thread.cpp » ('j') | test/Thread.cpp » ('J')

Powered by Google App Engine
This is Rietveld