AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
AJAThread Class Reference

#include <thread.h>

Public Member Functions

 AJAThread ()
 
virtual ~AJAThread ()
 
virtual AJAStatus Start ()
 
virtual AJAStatus Stop (uint32_t timeout=0xffffffff)
 
virtual AJAStatus Kill (uint32_t exitCode)
 
virtual bool Active ()
 
virtual bool IsCurrentThread ()
 
virtual AJAStatus SetPriority (AJAThreadPriority priority)
 
virtual AJAStatus GetPriority (AJAThreadPriority *pPriority)
 
virtual AJAStatus SetRealTime (AJAThreadRealTimePolicy policy, int priority)
 
virtual AJAStatus ThreadRun ()
 
virtual AJAStatus ThreadInit ()
 
virtual bool ThreadLoop ()
 
virtual AJAStatus ThreadFlush ()
 
virtual bool Terminate ()
 
virtual AJAStatus Attach (AJAThreadFunction *pThreadFunction, void *pUserContext)
 
virtual AJAStatus SetThreadName (const char *name)
 

Static Public Member Functions

static uint64_t GetThreadId ()
 

Related Functions

(Note that these are not member functions.)

typedef void AJAThreadFunction(AJAThread *pThread, void *pContext)
 

Detailed Description

System independent class for creating and controlling threads.

This class can be used 2 ways. If an external thread function is attached, the Start() method creates a thread and invokes the attached function. It is up to the attached function to query the Terminate() method to determine when the a Stop() has been issued. If no external thread function is attached, the Start() method creates a thread and invokes the ThreadRun() method. ThreadRun() calls ThreadInit() and then calls ThreadLoop() continuously until a Stop is issued at which time if calls ThreadFlush(). A subclass can override any of the functions it requires but should at least override ThreadLoop() to do some work then wait an appropriate amount of time.

Definition at line 69 of file thread.h.

Constructor & Destructor Documentation

◆ AJAThread()

AJAThread::AJAThread ( )

Definition at line 22 of file thread.cpp.

◆ ~AJAThread()

AJAThread::~AJAThread ( )
virtual

Definition at line 28 of file thread.cpp.

Member Function Documentation

◆ Active()

bool AJAThread::Active ( )
virtual

Is the thread active.

Returns
true Thread active false Thread inactive

Definition at line 116 of file thread.cpp.

◆ Attach()

AJAStatus AJAThread::Attach ( AJAThreadFunction pThreadFunction,
void *  pUserContext 
)
virtual

Attach an external thread function.

The external function is called when the thread starts and returns when Terminate() is true or the task is complete.

Parameters
[in]pThreadFunctionExternal thread entry point
[in]pUserContextContext passed to external thread function. return AJA_STATUS_SUCCESS External function attached

Definition at line 169 of file thread.cpp.

◆ GetPriority()

AJAStatus AJAThread::GetPriority ( AJAThreadPriority pPriority)
virtual

Get the thread priority.

Returns
AJA_STATUS_SUCCESS Priority returned AJA_STATUS_NULL PPriority is null

Definition at line 142 of file thread.cpp.

◆ GetThreadId()

uint64_t AJAThread::GetThreadId ( )
static

Get the Thread Id of the current running thread

Returns
The thread Id of the current thread, expressed as a 64 bit unsigned integer

Definition at line 180 of file thread.cpp.

◆ IsCurrentThread()

bool AJAThread::IsCurrentThread ( )
virtual

Is this the current running thread.

Returns
true Thread current false Thread not current

Definition at line 124 of file thread.cpp.

◆ Kill()

AJAStatus AJAThread::Kill ( uint32_t  exitCode)
virtual

Kill the thread.

Returns
AJA_STATUS_SUCCESS Thread killed AJA_STATUS_FAIL Thread could not be killed

Definition at line 108 of file thread.cpp.

◆ SetPriority()

AJAStatus AJAThread::SetPriority ( AJAThreadPriority  priority)
virtual

Set the thread priority.

Parameters
[in]priorityNew thread priority.
Returns
AJA_STATUS_SUCCESS Thread priority set AJA_STATUS_RANGE Unknown priority AJA_STATUS_FAIL Priority not set

Definition at line 133 of file thread.cpp.

◆ SetRealTime()

AJAStatus AJAThread::SetRealTime ( AJAThreadRealTimePolicy  policy,
int  priority 
)
virtual

Set the thread to be realtime.

Parameters
[in]AJAThreadRealTimePolicyThread policy int Realtime priority
Returns
AJA_STATUS_SUCCESS Thread priority set AJA_STATUS_RANGE Unknown priority AJA_STATUS_FAIL Priority not set

Definition at line 151 of file thread.cpp.

◆ SetThreadName()

AJAStatus AJAThread::SetThreadName ( const char *  name)
virtual

Sets the thread name

NOTE: This call must be made from within the thread.

Parameters
[in]nameName to assign to the thread

Definition at line 176 of file thread.cpp.

◆ Start()

AJAStatus AJAThread::Start ( )
virtual

Start the thread.

Returns
AJA_STATUS_SUCCESS Thread started AJA_STATUS_FAIL Thread start failed

Definition at line 91 of file thread.cpp.

◆ Stop()

AJAStatus AJAThread::Stop ( uint32_t  timeout = 0xffffffff)
virtual

Stop the thread.

Parameters
[in]timeoutWait timeout in milliseconds (0xffffffff infinite).
Returns
AJA_STATUS_SUCCESS Thread stopped AJA_STATUS_TIMEOUT Thread stop timeout AJA_STATUS_FAIL Thread stop wait failure

Definition at line 100 of file thread.cpp.

◆ Terminate()

bool AJAThread::Terminate ( )
virtual

The thread must terminate.

Threads call this function to determine when to stop.

Returns
true Thread stop requested false Thread can continue

Definition at line 160 of file thread.cpp.

◆ ThreadFlush()

AJAStatus AJAThread::ThreadFlush ( )
virtual

Flush the thread resources.

Override this function to cleanup before the thread exits.

Returns
AJA_STATUS_SUCCESS Thread flush successful AJA_STATUS_FAIL Thread flush failed

Definition at line 81 of file thread.cpp.

◆ ThreadInit()

AJAStatus AJAThread::ThreadInit ( )
virtual

Initialize the thread resources.

Override this function to initialize thread resources before executing the inner loop.

Returns
AJA_STATUS_SUCCESS Initialize successful AJA_STATUS_FAIL Initialize failed

Definition at line 63 of file thread.cpp.

◆ ThreadLoop()

bool AJAThread::ThreadLoop ( )
virtual

The thread inner loop.

Override this function to repeat a task while the thread is active.

Returns
true Loop continues false Loop stops

Definition at line 71 of file thread.cpp.

◆ ThreadRun()

AJAStatus AJAThread::ThreadRun ( )
virtual

Controlling function for the new thread.

This function calls ThreadInit() once then continuously call ThreadLoop until Terminate() is true or ThreadLoop() returns false. ThreadFlush() is called last. Override this function for complete control of the thread.

Returns
AJA_STATUS_SUCCESS No thread errors AJA_STATUS_FAIL ThreadInit or ThreadFlush returned failure.

Definition at line 38 of file thread.cpp.

Friends And Related Function Documentation

◆ AJAThreadFunction

typedef void AJAThreadFunction(AJAThread *pThread, void *pContext)
related

Template for external thread entry point.

Definition at line 22 of file thread.h.


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