summaryrefslogtreecommitdiff
path: root/src/Thread.cxx
diff options
context:
space:
mode:
authorDenis Oliver Kropp <dok@directfb.org>2010-10-19 15:56:15 +0200
committerDenis Oliver Kropp <dok@directfb.org>2010-10-19 15:56:15 +0200
commit27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e (patch)
treeefee63b09d2f9b73e2ae73a9448660a3cf73c4e6 /src/Thread.cxx
downloadpluggit-27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e.tar.gz
pluggit-27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e.tar.bz2
pluggit-27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e.zip
pluggit
Diffstat (limited to 'src/Thread.cxx')
-rw-r--r--src/Thread.cxx71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/Thread.cxx b/src/Thread.cxx
new file mode 100644
index 0000000..a8f1e32
--- /dev/null
+++ b/src/Thread.cxx
@@ -0,0 +1,71 @@
+namespace PluggIt {
+
+class Thread
+{
+ private Runnable *m_target;
+ private string m_name;
+
+ private DirectThread *m_thread;
+ private volatile bool m_interrupted;
+
+
+ public Thread( Runnable *target, string name = "" ) {
+ m_target = target;
+ m_name = name;
+
+ m_thread = NULL;
+ m_interrupted = false;
+ }
+
+ virtual ~Thread() {
+ if (m_thread)
+ direct_thread_destroy( m_thread );
+ }
+
+ public bool start() {
+ if (m_thread)
+ return false;
+
+ m_thread = direct_thread_create( DTT_DEFAULT, main, m_target, m_name.c_str() );
+
+ return m_thread != NULL;
+ }
+
+ public bool interrupt() {
+ if (!m_thread)
+ return false;
+
+ m_interrupted = true;
+
+ return true;
+ }
+
+ public bool isInterrupted() {
+ return m_interrupted;
+ }
+
+ public bool join() {
+ if (!m_thread)
+ return false;
+
+ direct_thread_join( m_thread );
+ direct_thread_destroy( m_thread );
+
+ m_thread = NULL;
+ m_interrupted = false;
+
+ return true;
+ }
+
+
+ private static void *main( DirectThread *thread, void *arg ) {
+ Runnable *target = (Runnable*) arg;
+
+ target->run();
+
+ return NULL;
+ }
+};
+
+}
+