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

Unified Diff: src/Thread.h

Issue 10026001: Cross-platform thread primitives (Closed)
Patch Set: Created March 29, 2013, 5:26 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 | « libadblockplus.gyp ('k') | src/Thread.cpp » ('j') | src/Thread.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/Thread.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/Thread.h
@@ -0,0 +1,59 @@
+#ifndef ADBLOCKPLUS_THREAD_H
+#define ADBLOCKPLUS_THREAD_H
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <pthread.h>
+#endif
+
+namespace AdblockPlus
+{
+ class Thread
+ {
+ public:
+ class Mutex
Wladimir Palant 2013/04/03 13:14:47 Why not make that class public? I think it will be
Felix Dahlke 2013/04/03 16:27:59 It is public, just nested in Thread. Would you pre
Wladimir Palant 2013/04/03 19:30:16 AdblockPlus::Thread::Mutex just sounds wrong - it
Felix Dahlke 2013/04/04 02:52:58 Sure, moved them to the top level.
+ {
+ public:
+#ifdef WIN32
+ CRITICAL_SECTION nativeMutex;
+#else
+ pthread_mutex_t nativeMutex;
+#endif
+
+ Mutex();
+ ~Mutex();
+ void Lock();
+ void Unlock();
+ };
+
+ class Condition
+ {
+ public:
+ Condition();
+ ~Condition();
+ void Wait(Mutex& mutex);
+ void Signal();
+
+ private:
+#ifdef WIN32
Wladimir Palant 2013/04/03 13:14:47 CONDITION_VARIABLE nativeCondition; missing here?
Felix Dahlke 2013/04/03 16:27:59 Yes, somehow messed up the patch it seems, Oleksan
+#else
+ pthread_cond_t nativeCondition;
+#endif
+ };
+
+ virtual ~Thread();
+ virtual void Run() = 0;
+ void Start();
+ void Join();
+
+ private:
+#ifdef WIN32
+ HANDLE thread;
Wladimir Palant 2013/04/03 13:14:47 Rename this into nativeThread for consistency?
Felix Dahlke 2013/04/03 16:27:59 Absolutely, done.
+#else
+ pthread_t thread;
+#endif
+ };
+}
+
+#endif
« no previous file with comments | « libadblockplus.gyp ('k') | src/Thread.cpp » ('j') | src/Thread.cpp » ('J')

Powered by Google App Engine
This is Rietveld