Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126732
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/thread.cpp b/util/thread.cpp
new file mode 100644
index 00000000..15e6ed26
--- /dev/null
+++ b/util/thread.cpp
@@ -0,0 +1,32 @@
+#include <pthread.h>
+#include "thread.h"
+
+namespace Util{
+
+Thread::Thread():
+done(false){
+ pthread_mutex_init(&doneLock, NULL);
+}
+
+void Thread::start(void * (*thread)(void *), void * arg){
+ done = false;
+ pthread_create(&this->thread, NULL, thread, arg);
+}
+
+bool Thread::isRunning(){
+ pthread_mutex_lock(&doneLock);
+ bool what = done;
+ pthread_mutex_unlock(&doneLock);
+ return what;
+}
+
+void Thread::kill(){
+ pthread_cancel(thread);
+}
+
+Thread::~Thread(){
+ /* FIXME: Should we join the thread? */
+ /* pthread_join(thread); */
+}
+
+}
diff --git a/util/thread.h b/util/thread.h
new file mode 100644
index 00000000..f9702211
--- /dev/null
+++ b/util/thread.h
@@ -0,0 +1,29 @@
+#ifndef _paintown_thread_h
+#define _paintown_thread_h
+
+#include <pthread.h>
+
+namespace Util{
+
+class Thread{
+public:
+ /* does not start a new thread yet */
+ Thread();
+
+ /* starts a thread */
+ void start(void * (*thread)(void *), void * arg);
+
+ bool isRunning();
+ void kill();
+
+ virtual ~Thread();
+
+protected:
+ pthread_mutex_t doneLock;
+ pthread_t thread;
+ volatile bool done;
+};
+
+}
+
+#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:45 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69095
Default Alt Text
(1 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline