cisst-saw
Loading...
Searching...
No Matches
osaThread Class Reference

Define a thread object. More...

#include <osaThread.h>

Public Member Functions

 osaThread ()
 ~osaThread ()
void Create (void *(*threadStart)(void), const char *name=0, int priority=0, int policy=SCHED_FIFO)
template<class _userDataType>
void Create (void *(*threadStart)(_userDataType), _userDataType userData=_userDataType(), const char *name=0, int priority=0, int policy=SCHED_FIFO)
template<class _entryType, class _userDataType>
void Create (_entryType *obj, void *(_entryType::*threadStart)(_userDataType), _userDataType userData=_userDataType(), const char *name=0, int priority=0, int policy=SCHED_FIFO)
void CreateFromCurrentThread (const char *name=0, int priority=0, int policy=SCHED_FIFO)
void CreateFromThreadId (const osaThreadId &threadId, const char *name=0, int priority=0, int policy=SCHED_FIFO)
void Delete (void)
void Wait (void)
void WaitForWakeup (void)
void WaitForWakeup (double timeoutInSec)
void Wakeup (void)
const char * GetName (void) const
osaThreadId GetId (void) const
PriorityType GetPriority (void) const
void SetPriority (PriorityType priority)
SchedulingPolicyType GetSchedulingPolicy (void)
void SetSchedulingPolicy (SchedulingPolicyType policy)
void Sleep (double timeInSeconds)
bool IsRunning (void) const
bool IsValid (void) const

Protected Member Functions

void CreateInternal (const char *name, void *func, void *userdata)
void SetThreadName (const char *name)

Friends

class osaThreadTest

Detailed Description

Define a thread object.

The thread class is just a wrapper on the OS-specific thread management functions. For now, wraps functions such as CreateThread, DeleteThread, GetThreadPriority, SetThreadPriority and so on. Additional functionality, such as inter-thread communication, maintenance of state information, etc., are provided by the mtsTask class.

See also
mtsTask

Constructor & Destructor Documentation

◆ osaThread()

osaThread::osaThread ( )

Default constructor. Does nothing.

◆ ~osaThread()

osaThread::~osaThread ( )

Default destructor. Does nothing.

Member Function Documentation

◆ Create() [1/3]

template<class _entryType, class _userDataType>
void osaThread::Create ( _entryType * obj,
void * threadStart (_entryType::*)(_userDataType),
_userDataType userData = _userDataType(),
const char * name = 0,
int priority = 0,
int policy = SCHED_FIFO )
inline

Creates a new thread that will execute the specified class member function. Note that the object is copied to the heap so it remains valid, even if the original object is destroyed.

◆ Create() [2/3]

template<class _userDataType>
void osaThread::Create ( void * threadStart (*)(_userDataType),
_userDataType userData = _userDataType(),
const char * name = 0,
int priority = 0,
int policy = SCHED_FIFO )
inline

Creates a new thread that will execute the specified function, taking a single parameter.

◆ Create() [3/3]

void osaThread::Create ( void * threadStart (*)(void),
const char * name = 0,
int priority = 0,
int policy = SCHED_FIFO )
inline

Creates a new thread that will execute the specified function, with no parameters.

◆ CreateFromCurrentThread()

void osaThread::CreateFromCurrentThread ( const char * name = 0,
int priority = 0,
int policy = SCHED_FIFO )
inline

Initialize the thread object so that it refers to the calling thread, rather than creating a new thread. This allows existing threads to intermix with newly created threads.

◆ CreateFromThreadId()

void osaThread::CreateFromThreadId ( const osaThreadId & threadId,
const char * name = 0,
int priority = 0,
int policy = SCHED_FIFO )
inline

◆ CreateInternal()

void osaThread::CreateInternal ( const char * name,
void * func,
void * userdata )
protected

Creates a new thread.

◆ Delete()

void osaThread::Delete ( void )

Deletes a thread. Deletes (removes from memory) everything associated with a thread, e.g. stack, local data, static variables.

◆ GetId()

osaThreadId osaThread::GetId ( void ) const
inline

Return the thread id.

◆ GetName()

const char * osaThread::GetName ( void ) const
inline

Return the thread name.

◆ GetPriority()

PriorityType osaThread::GetPriority ( void ) const

Get the OS independent priority of the thread.

◆ GetSchedulingPolicy()

SchedulingPolicyType osaThread::GetSchedulingPolicy ( void )

Get the OS independent scheduling policy of the thread. Will not be available on all platforms or will return a constant.

◆ IsRunning()

bool osaThread::IsRunning ( void ) const
inline

Returns if this thread is running.

◆ IsValid()

bool osaThread::IsValid ( void ) const
inline

Returns whether the thread exists (is valid).

◆ SetPriority()

void osaThread::SetPriority ( PriorityType priority)

Set the OS independent priority of the thread.

◆ SetSchedulingPolicy()

void osaThread::SetSchedulingPolicy ( SchedulingPolicyType policy)

Set the OS independent scheduling policy of the thread. Will not be available on all platforms.

◆ SetThreadName()

void osaThread::SetThreadName ( const char * name)
protected

◆ Sleep()

void osaThread::Sleep ( double timeInSeconds)

Delay/suspend execution of the calling thread for the specified time. On some platforms, this method provides a better implementation of osaSleep, provided that it is called from the thread associated with this instance of the class. In this case, the Sleep will also be terminated by any call to Wakeup. If called from a different thread, it just calls osaSleep and is therefore not affected by any calls to Wakeup.

Parameters
timeInSecondsThe amount of time the task is suspended (in seconds)

◆ Wait()

void osaThread::Wait ( void )

Wait for the thread to exit.

◆ WaitForWakeup() [1/2]

void osaThread::WaitForWakeup ( double timeoutInSec)
inline

Wait for thread to receive a "wakeup" signal/event.

◆ WaitForWakeup() [2/2]

void osaThread::WaitForWakeup ( void )
inline

Wait for thread to receive a "wakeup" signal/event.

◆ Wakeup()

void osaThread::Wakeup ( void )
inline

Signal the thread to wake up.

◆ osaThreadTest

friend class osaThreadTest
friend

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