From ab88b2d3ece8cf0b2d5e48b93b441a953d94e8f2 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 14 Feb 2015 16:13:48 -0800 Subject: [PATCH] nonlib/Thread: Separate running() logic from thread descriptor. --- nonlib/Thread.C | 6 ++++++ nonlib/Thread.H | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nonlib/Thread.C b/nonlib/Thread.C index acee63f..de30601 100644 --- a/nonlib/Thread.C +++ b/nonlib/Thread.C @@ -30,12 +30,14 @@ pthread_key_t Thread::_current = 0; Thread::Thread ( ) { _thread = 0; + _running = false; _name = 0; } Thread::Thread ( const char *name ) { _thread = 0; + _running = false; _name = name; } @@ -57,6 +59,7 @@ Thread::set ( const char *name ) { _thread = pthread_self(); _name = name; + _running = true; pthread_setspecific( _current, (void*)this ); } @@ -83,6 +86,8 @@ Thread::run_thread ( void *arg ) pthread_setspecific( _current, td.t ); + ((Thread*)td.t)->_running = true; + return td.entry_point( td.arg ); } @@ -130,5 +135,6 @@ Thread::join ( void ) void Thread::exit ( void *retval ) { + _running = false; pthread_exit( retval ); } diff --git a/nonlib/Thread.H b/nonlib/Thread.H index feb6b68..ad405ad 100644 --- a/nonlib/Thread.H +++ b/nonlib/Thread.H @@ -31,6 +31,8 @@ class Thread pthread_t _thread; const char * _name; + volatile bool _running; + static void * run_thread ( void *arg ); public: @@ -46,7 +48,7 @@ public: const char *name ( void ) const { return _name; } void name ( const char *name ) { _name = name; } - bool running ( void ) const { return _thread; } + bool running ( void ) const { return _running; } void set ( const char *name ); void set ( void ) { set( _name ); } bool clone ( void *(*entry_point)(void *), void *arg );