Browse Source

nonlib/Thread: Separate running() logic from thread descriptor.

tags/non-daw-v1.2.0
Jonathan Moore Liles 10 years ago
parent
commit
ab88b2d3ec
2 changed files with 9 additions and 1 deletions
  1. +6
    -0
      nonlib/Thread.C
  2. +3
    -1
      nonlib/Thread.H

+ 6
- 0
nonlib/Thread.C View File

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

+ 3
- 1
nonlib/Thread.H View File

@@ -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…
Cancel
Save