Rewrite IThreader implementation around new synchronization primitives (bug 5862, r=fyren).

This commit is contained in:
David Anderson
2013-08-19 20:58:02 -07:00
parent 582162460f
commit 45856816c1
15 changed files with 212 additions and 542 deletions
+1
View File
@@ -38,6 +38,7 @@
*/
#include <IShareSys.h>
#include <ke_thread_utils.h>
#define SMINTERFACE_THREADER_NAME "IThreader"
#define SMINTERFACE_THREADER_VERSION 3
+11 -6
View File
@@ -20,6 +20,7 @@
#include <assert.h>
#if defined(_MSC_VER)
# include <windows.h>
# include <WinBase.h>
#else
# include <pthread.h>
#endif
@@ -56,8 +57,13 @@
// When Wait() returns, the lock is automatically re-acquired. This operation
// is NOT atomic. In between waking up and re-acquiring the lock, another
// thread may steal the lock and issue another event. Applications must
// account for this. For example, a message pump should check that there are no
// messages left to process before blocking again.
// account for this. For example, a message pump should check that there are
// no messages left to process before blocking again.
//
// Likewise, it is also not defined whether a Signal() will have any effect
// while a thread is not waiting on the monitor. This is yet another reason
// the above paragraph is so important - applications should, under a lock of
// the condition variable - check for state changes before waiting.
//
// -- Threads --
//
@@ -72,13 +78,13 @@
namespace ke {
// Abstraction for accessing the current thread.
// Abstraction for getting a unique thread identifier. Debug-only.
#if defined(_MSC_VER)
typedef HANDLE ThreadId;
typedef DWORD ThreadId;
static inline ThreadId GetCurrentThreadId()
{
return GetCurrentThread();
return ::GetCurrentThreadId();
}
#else
typedef pthread_t ThreadId;
@@ -238,4 +244,3 @@ class IRunnable
#endif
#endif // _include_sourcepawn_threads_
+4
View File
@@ -120,6 +120,10 @@ class Thread
WaitForSingleObject(thread_, INFINITE);
}
HANDLE handle() const {
return thread_;
}
private:
static DWORD WINAPI Main(LPVOID arg) {
((IRunnable *)arg)->Run();
+6
View File
@@ -22,6 +22,7 @@
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#if defined(_MSC_VER)
# include <intrin.h>
#endif
@@ -56,6 +57,8 @@ ReturnAndVoid(T &t)
return saved;
}
// Wrapper that automatically deletes its contents. The pointer can be taken
// to avoid destruction.
template <typename T>
class AutoPtr
{
@@ -89,6 +92,9 @@ class AutoPtr
delete t_;
t_ = t;
}
bool operator !() const {
return !t_;
}
};
// Bob Jenkin's one-at-a-time hash function[1].