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; } }; }