nonlib/Thread: Separate running() logic from thread descriptor.
This commit is contained in:
parent
7934a71c70
commit
ab88b2d3ec
|
@ -30,12 +30,14 @@ pthread_key_t Thread::_current = 0;
|
||||||
Thread::Thread ( )
|
Thread::Thread ( )
|
||||||
{
|
{
|
||||||
_thread = 0;
|
_thread = 0;
|
||||||
|
_running = false;
|
||||||
_name = 0;
|
_name = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::Thread ( const char *name )
|
Thread::Thread ( const char *name )
|
||||||
{
|
{
|
||||||
_thread = 0;
|
_thread = 0;
|
||||||
|
_running = false;
|
||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ Thread::set ( const char *name )
|
||||||
{
|
{
|
||||||
_thread = pthread_self();
|
_thread = pthread_self();
|
||||||
_name = name;
|
_name = name;
|
||||||
|
_running = true;
|
||||||
|
|
||||||
pthread_setspecific( _current, (void*)this );
|
pthread_setspecific( _current, (void*)this );
|
||||||
}
|
}
|
||||||
|
@ -83,6 +86,8 @@ Thread::run_thread ( void *arg )
|
||||||
|
|
||||||
pthread_setspecific( _current, td.t );
|
pthread_setspecific( _current, td.t );
|
||||||
|
|
||||||
|
((Thread*)td.t)->_running = true;
|
||||||
|
|
||||||
return td.entry_point( td.arg );
|
return td.entry_point( td.arg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,5 +135,6 @@ Thread::join ( void )
|
||||||
void
|
void
|
||||||
Thread::exit ( void *retval )
|
Thread::exit ( void *retval )
|
||||||
{
|
{
|
||||||
|
_running = false;
|
||||||
pthread_exit( retval );
|
pthread_exit( retval );
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ class Thread
|
||||||
pthread_t _thread;
|
pthread_t _thread;
|
||||||
const char * _name;
|
const char * _name;
|
||||||
|
|
||||||
|
volatile bool _running;
|
||||||
|
|
||||||
static void * run_thread ( void *arg );
|
static void * run_thread ( void *arg );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -46,7 +48,7 @@ public:
|
||||||
const char *name ( void ) const { return _name; }
|
const char *name ( void ) const { return _name; }
|
||||||
void name ( const char *name ) { _name = 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 ( const char *name );
|
||||||
void set ( void ) { set( _name ); }
|
void set ( void ) { set( _name ); }
|
||||||
bool clone ( void *(*entry_point)(void *), void *arg );
|
bool clone ( void *(*entry_point)(void *), void *arg );
|
||||||
|
|
Loading…
Reference in New Issue