Thread_t Class Reference

Thread class.

#include <UTThread.h>

Inheritance diagram for Thread_t:
LinkedListNode_t< Thread_t > MessageLoop_t App_t IdleMessageLoop_t

List of all members.

Public Member Functions

 Thread_t (thread_priority_t priority=eTHREADPRI_normal)
virtual ~Thread_t ()
virtual void Start (int32 stack_size=0)
void SetPriority (thread_priority_t priority)
thread_id_t ThreadId () const
thread_priority_t Priority () const
virtual void WaitForThreadToExit ()
virtual void Main ()=0
bool IsMainThread () const

Static Public Member Functions

static void RegisterMainThread (Thread_t *main_thread)
static thread_id_t MainThreadId ()
static int CountThreads ()
static bool IsThreadingSafe ()

Detailed Description

Definition at line 103 of file UTThread.h.


Constructor & Destructor Documentation

Thread_t::Thread_t ( thread_priority_t  priority = eTHREADPRI_normal  ) 

Constructor for a thread. Once the child class has been constructed, the Start function may be called. Under windows, use of eTHREADPRI_time_critical or above can interfere with serial port driver function (the serial port driver will then be running at an equal or lower priority and unable to respond in time, either to service the UART FIFO or to flow off the peer device).

virtual Thread_t::~Thread_t (  )  [virtual]

Destructor for a thread. Before the thread is deleted, WaitForThreadToExit must be called. WaitForThreadToExit can often be called from the child class destructor, but that depends on the design of the child class's relationship with further layers of inheritance.


Member Function Documentation

virtual void Thread_t::Start ( int32  stack_size = 0  )  [virtual]

Starts the thread. If the stack size is 0, an appropriate default is used. Once the thread is running, it will call the Main function, which must be implemented by the actual thread subclass. If this is the main thread (registered using RegisterMainThread), Main will be called directly from Start and will not return until the thread has exited.

Reimplemented in MessageLoop_t, and App_t.

void Thread_t::SetPriority ( thread_priority_t  priority  ) 

Sets the thread priority. If the thread whose priority is to be set is the main application thread, it should be or have been registered using RegisterMainThread.

thread_id_t Thread_t::ThreadId (  )  const [inline]

Returns the ID of the thread. The thread ID is in the same value space as the current_thread_id() function.

Definition at line 226 of file UTThread.h.

thread_priority_t Thread_t::Priority (  )  const [inline]

Returns the priority at which the thread is running, was running, or will run when it is started.

Definition at line 233 of file UTThread.h.

virtual void Thread_t::WaitForThreadToExit (  )  [virtual]

Called from another thread, waits for the thread to exit. It is up to the child class to implement a mechanism to communicate when the thread should quit. Event driven mechanisms are preferred if at all possible.

Reimplemented in MessageLoop_t.

virtual void Thread_t::Main (  )  [pure virtual]

Pure virtual function implemented by a child class to implement the thread entry point. When it is time for the thread to quit, it should simply return from Main.

Implemented in MessageLoop_t, and App_t.

static void Thread_t::RegisterMainThread ( Thread_t main_thread  )  [static]

Registers a thread object representing the main thread. Start should not be called; instead the Main function can be called directly.

static thread_id_t Thread_t::MainThreadId (  )  [static]

Returns the thread ID of the main thread, which must exist or an assertion failure will occur.

bool Thread_t::IsMainThread (  )  const [inline]

Returns true if this is the main thread, with RegisterMainThread having been called on it.

Definition at line 240 of file UTThread.h.

int Thread_t::CountThreads (  )  [inline, static]

Returns the number of thread objects in existance (note: not the number of OS threads).

Definition at line 247 of file UTThread.h.

bool Thread_t::IsThreadingSafe (  )  [inline, static]

Returns true if threading is safe, or specifically, if main has been called and has not returned yet.

Definition at line 254 of file UTThread.h.


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

Generated on Tue Dec 14 22:35:07 2010 for UT library by  doxygen 1.6.1