OpenThreads
Thread
Go to the documentation of this file.
1/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14
15//
16// Thread - C++ Thread class
17// ~~~~~~~~
18//
19
20#ifndef _OPENTHREADS_THREAD_
21#define _OPENTHREADS_THREAD_
22
23#include <sys/types.h>
24
25#include <OpenThreads/Mutex>
26#include <OpenThreads/Affinity>
27
28namespace OpenThreads {
29
37
42
43
49
50public:
51
63 static int SetConcurrency(int concurrencyLevel);
64
72 static int GetConcurrency();
73
87
99
104
108 virtual ~Thread();
109
110
115
119 static size_t CurrentThreadId();
120
121
126 static void Init();
127
136 static int YieldCurrentThread();
137
147 static ThreadPriority GetMasterPriority() {return s_masterThreadPriority;};
148
149
155 size_t getThreadId();
156
163 size_t getProcessId();
164
175 int start();
177
186
187
193 virtual int cancel();
194
216
226
242
252
263 int setStackSize(size_t size);
264
272 size_t getStackSize();
273
278
284 int detach();
285
291 int join();
292
299
307
315
321 bool isRunning();
322
327 virtual void run() = 0;
328
335 virtual void cancelCleanup() {};
336
337 void* getImplementation(){ return _prvData; };
338
345 int setProcessorAffinity( const Affinity& affinity);
346
347
355 static int microSleep( unsigned int microsec);
356
357private:
358
363
367 Thread(const Thread &/*t*/) {};
368
372 Thread &operator=(const Thread &/*t*/) {return *(this);};
373
377 void * _prvData;
378
382 static ThreadPriority s_masterThreadPriority;
383
387 static bool s_isInitialized;
388};
389
390}
391
392#endif // !_OPENTHREADS_THREAD_
#define OPENTHREAD_EXPORT_DIRECTIVE
Definition Exports:20
Definition Affinity:26
OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(const Affinity &affinity)
Set the processor affinity of current thread.
OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors()
Get the number of processors.
Simple container for specifying which CPU a thread should have affinity with.
Definition Affinity:34
This class provides an object-oriented thread interface.
Definition Thread:48
static int SetConcurrency(int concurrencyLevel)
Set the concurrency level for a running application.
static int microSleep(unsigned int microsec)
microSleep method, equivalent to the posix usleep(microsec).
ThreadPriority
Enumerated Type for thread priority.
Definition Thread:77
@ THREAD_PRIORITY_DEFAULT
Priority scheduling default.
Definition Thread:84
@ THREAD_PRIORITY_NOMINAL
An average priority.
Definition Thread:81
@ THREAD_PRIORITY_LOW
A low (but not min) setting.
Definition Thread:82
@ THREAD_PRIORITY_HIGH
A high (but not max) setting.
Definition Thread:80
@ THREAD_PRIORITY_MIN
The miniumum possible priority.
Definition Thread:83
@ THREAD_PRIORITY_MAX
The maximum possible priority.
Definition Thread:79
int setCancelModeAsynchronous()
Mark the thread to cancel asynchronously on Thread::cancel().
friend class ThreadPrivateActions
The Private Actions class is allowed to operate on private data.
Definition Thread:362
int setSchedulePriority(ThreadPriority priority)
Set the thread's schedule priority.
void * getImplementation()
Definition Thread:337
virtual void cancelCleanup()
Thread's cancel cleanup routine, called upon cancel(), after the cancellation has taken place,...
Definition Thread:335
int setStackSize(size_t size)
Set the thread's desired stack size (in bytes).
ThreadPolicy
Enumerated Type for thread scheduling policy.
Definition Thread:91
@ THREAD_SCHEDULE_FIFO
First in, First out scheduling.
Definition Thread:93
@ THREAD_SCHEDULE_DEFAULT
Default scheduling.
Definition Thread:96
@ THREAD_SCHEDULE_ROUND_ROBIN
Round-robin scheduling (LINUX_DEFAULT)
Definition Thread:94
@ THREAD_SCHEDULE_TIME_SHARE
Time-share scheduling (IRIX DEFAULT)
Definition Thread:95
void printSchedulingInfo()
Print the thread's scheduling information to stdout.
int setSchedulePolicy(ThreadPolicy policy)
Set the thread's scheduling policy (if able)
Thread()
Constructor.
int setCancelModeDisable()
Disable thread cancellation altogether.
static int YieldCurrentThread()
Yield the processor.
int setProcessorAffinity(const Affinity &affinity)
Set the Thread's processor affinity to all, a single CPU or multiple CPU's This call must be made bef...
static size_t CurrentThreadId()
Return the id of the current thread.
int getSchedulePriority()
Get the thread's schedule priority (if able)
bool isRunning()
Query the thread's running status.
int testCancel()
Test the cancel state of the thread.
int join()
Join the calling process with the thread.
size_t getStackSize()
Get the thread's desired stack size.
virtual int cancel()
Cancel the thread.
int detach()
Detach the thread from the calling process.
static Thread * CurrentThread()
Return a pointer to the current running thread, returns NULL for a non OpenThreads thread.
size_t getThreadId()
Get a unique thread id.
static int GetConcurrency()
Get the concurrency level for a running application.
virtual ~Thread()
Destructor.
int start()
Start the thread.
int getSchedulePolicy()
Get the thread's policy (if able)
size_t getProcessId()
Get the thread's process id.
static void Init()
Initialize Threading in a program.
virtual void run()=0
Thread's run method.
int setCancelModeDeferred()
Mark the thread to cancel at the earliest convenience on Thread::cancel() (This is the default)
static ThreadPriority GetMasterPriority()
This method will return the ThreadPriority of the master process.
Definition Thread:147

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenThreads by doxygen 1.14.0.