openscenegraph
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
362 friend class ThreadPrivateActions;
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
Simple container for specifying which CPU a thread should have affinity with. An empty Affinity....
Definition Affinity:34
This class provides an object-oriented thread interface.
Definition Thread:48
static int SetConcurrency(int concurrencyLevel)
static int microSleep(unsigned int microsec)
ThreadPriority
Definition Thread:77
@ THREAD_PRIORITY_NOMINAL
Definition Thread:81
@ THREAD_PRIORITY_LOW
Definition Thread:82
@ THREAD_PRIORITY_HIGH
Definition Thread:80
@ THREAD_PRIORITY_MIN
Definition Thread:83
@ THREAD_PRIORITY_MAX
Definition Thread:79
int setCancelModeAsynchronous()
int setSchedulePriority(ThreadPriority priority)
void * getImplementation()
Definition Thread:337
virtual void cancelCleanup()
Definition Thread:335
int setStackSize(size_t size)
ThreadPolicy
Definition Thread:91
@ THREAD_SCHEDULE_FIFO
Definition Thread:93
@ THREAD_SCHEDULE_ROUND_ROBIN
Definition Thread:94
@ THREAD_SCHEDULE_TIME_SHARE
Definition Thread:95
int setSchedulePolicy(ThreadPolicy policy)
static int YieldCurrentThread()
int setProcessorAffinity(const Affinity &affinity)
static size_t CurrentThreadId()
virtual int cancel()
static Thread * CurrentThread()
static int GetConcurrency()
static void Init()
virtual void run()=0
static ThreadPriority GetMasterPriority()
Definition Thread:147
Definition Affinity:26
OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(const Affinity &affinity)
OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors()