From 27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e Mon Sep 17 00:00:00 2001 From: Denis Oliver Kropp Date: Tue, 19 Oct 2010 15:56:15 +0200 Subject: pluggit --- src/Thread.cxx | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/Thread.cxx (limited to 'src/Thread.cxx') 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; + } +}; + +} + -- cgit