Scopira  20080306
scopira::tool::thread Class Reference

#include <thread_pthreads.h>

Inheritance diagram for scopira::tool::thread:
scopira::tool::job_i scopira::tool::runnable_i scopira::tool::job_i scopira::tool::runnable_i scopira::tool::object scopira::tool::object scopira::tool::object scopira::tool::object

Classes

class  myQThread
 

Public Types

typedef pthread_key_t tlskey_t
 
typedef int tlskey_t
 

Public Member Functions

 thread (runnable_i *target)
 
 thread (runfunc_t func, void *arg)
 
virtual ~thread ()
 destructor
 
virtual void run (void)
 the run core
 
virtual void start (void)
 starts the actually execution of the thread and its run core
 
virtual void notify_stop (void)
 
virtual void wait_stop (void)
 suspeds caller until this thread stops
 
virtual bool is_running (void) const
 is this thread currently running?
 
 thread (runnable_i *target)
 
 thread (runfunc_t func, void *arg)
 
virtual ~thread ()
 destructor
 
virtual void run (void)
 the run core
 
virtual void start (void)
 starts the actually execution of the thread and its run core
 
virtual void notify_stop (void)
 
virtual void wait_stop (void)
 suspeds caller until this thread stops
 
virtual bool is_running (void) const
 is this thread currently running?
 
- Public Member Functions inherited from scopira::tool::object
virtual ~object ()
 
int add_ref (void) const
 
bool sub_ref (void) const
 
void auto_ref (void) const
 
int current_ref (void) const
 
virtual scopira::tool::oflow_iprint (scopira::tool::oflow_i &o) const
 
virtual bool load (scopira::tool::iobjflow_i &in)
 
virtual void save (scopira::tool::oobjflow_i &out) const
 
bool is_alive_object (void) const
 
bool is_dead_object (void) const
 

Static Public Member Functions

static void sleep (int msec)
 
static void open_tls (tlskey_t &outkey)
 
static void close_tls (tlskey_t k)
 
static void set_tls (tlskey_t k, const void *val)
 
static void * get_tls (tlskey_t k)
 
static void sleep (int msec)
 
static void open_tls (tlskey_t &outkey)
 
static void close_tls (tlskey_t k)
 
static void set_tls (tlskey_t k, void *val)
 
static void * get_tls (tlskey_t k)
 

Static Protected Member Functions

static void * voidrun (void *arg)
 

Protected Attributes

runnable_idm_target
 
runfunc_t dm_runfunc
 
void * dm_runfunc_arg
 
volatile bool dm_running
 
pthread_t dm_thread
 
scopira::tool::thread::myQThread dm_thread
 

Additional Inherited Members

- Protected Member Functions inherited from scopira::tool::object
 object (void)
 
 object (bool neverusecounter)
 

Detailed Description

An operating system thread object.

Author
Aleksander Demko

Constructor & Destructor Documentation

◆ thread() [1/4]

scopira::tool::thread::thread ( runnable_i target)

runnable_i Constructor.

If you pass a non-null target, that target's run method will be executed on start().

If you pass null, this->run() will be run, so you should descendat from thread and override it to make it do something.

Parameters
targetthe runnable target
Author
Aleksander Demko

◆ thread() [2/4]

scopira::tool::thread::thread ( runfunc_t  func,
void *  arg 
)

function pointer constructor. This version uses a function with argument instead runnable_i objects.

Parameters
functhe runfunc_t... it should return 0
argthe argument that is passed to your function... this should be a this object or something, probably. This may be null (heck, it doesn't even have to be a valid pointer...)
Author
Aleksander Demko

◆ thread() [3/4]

scopira::tool::thread::thread ( runnable_i target)

runnable_i Constructor.

If you pass a non-null target, that target's run method will be executed on start().

If you pass null, this->run() will be run, so you should descendat from thread and override it to make it do something.

Parameters
targetthe runnable target
Author
Aleksander Demko

◆ thread() [4/4]

scopira::tool::thread::thread ( runfunc_t  func,
void *  arg 
)

function pointer constructor. This version uses a function with argument instead runnable_i objects.

Parameters
functhe runfunc_t... it should return 0
argthe argument that is passed to your function... this should be a this object or something, probably. This may be null (heck, it doesn't even have to be a valid pointer...)
Author
Aleksander Demko

Member Function Documentation

◆ close_tls() [1/2]

static void scopira::tool::thread::close_tls ( tlskey_t  k)
static

close a TLS slot in all thread instances.

Author
Aleksander Demko

◆ close_tls() [2/2]

static void scopira::tool::thread::close_tls ( tlskey_t  k)
static

close a TLS slot in all thread instances.

Author
Aleksander Demko

◆ get_tls() [1/2]

static void* scopira::tool::thread::get_tls ( tlskey_t  k)
static

Get a TLS slot of the CURRENT thread. TLS data values default to null (0). Please note that this applies to the active thread, and may not be directed at individual thread objects.

Author
Aleksander Demko

◆ get_tls() [2/2]

static void* scopira::tool::thread::get_tls ( tlskey_t  k)
static

Get a TLS slot of the CURRENT thread. TLS data values default to null (0). Please note that this applies to the active thread, and may not be directed at individual thread objects.

Author
Aleksander Demko

◆ notify_stop() [1/2]

virtual void scopira::tool::thread::notify_stop ( void  )
virtual

doesnt actually do anything descendant classes might want to implement something if convinient

Implements scopira::tool::job_i.

◆ notify_stop() [2/2]

virtual void scopira::tool::thread::notify_stop ( void  )
virtual

doesnt actually do anything descendant classes might want to implement something if convinient

Implements scopira::tool::job_i.

◆ open_tls() [1/2]

static void scopira::tool::thread::open_tls ( tlskey_t &  outkey)
static

opens a TLS (thread local storage) slot in all current and future threads. You must call this once before doing any set/get calls. The initial value of the storage in each thread instance will be 0 (null).

outkey is where the new key is stored.

Author
Aleksander Demko

◆ open_tls() [2/2]

static void scopira::tool::thread::open_tls ( tlskey_t &  outkey)
static

opens a TLS (thread local storage) slot in all current and future threads. You must call this once before doing any set/get calls. The initial value of the storage in each thread instance will be 0 (null).

outkey is where the new key is stored.

Author
Aleksander Demko

◆ set_tls() [1/2]

static void scopira::tool::thread::set_tls ( tlskey_t  k,
const void *  val 
)
static

Set a TLS slot of the CURRENT thread. TLS data values default to null (0). Please note that this applies to the active thread, and may not be directed at individual thread objects.

Author
Aleksander Demko

◆ set_tls() [2/2]

static void scopira::tool::thread::set_tls ( tlskey_t  k,
void *  val 
)
static

Set a TLS slot of the CURRENT thread. TLS data values default to null (0). Please note that this applies to the active thread, and may not be directed at individual thread objects.

Author
Aleksander Demko

◆ sleep() [1/2]

static void scopira::tool::thread::sleep ( int  msec)
static

cause the current thread to sleep

Parameters
msecthe number of msec (1000=second) to wait
Returns
true if got a notification event, false if timed out

◆ sleep() [2/2]

static void scopira::tool::thread::sleep ( int  msec)
static

cause the current thread to sleep

Parameters
msecthe number of msec (1000=second) to wait
Returns
true if got a notification event, false if timed out

The documentation for this class was generated from the following files: