OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Thread.h
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 
27 namespace OpenThreads {
28 
36 
44 
50 
51 public:
52 
64  static int SetConcurrency(int concurrencyLevel);
65 
73  static int GetConcurrency();
74 
79 
85  THREAD_PRIORITY_DEFAULT
87  };
88 
92  enum ThreadPolicy {
93 
97  THREAD_SCHEDULE_DEFAULT
99  };
100 
104  Thread();
105 
109  virtual ~Thread();
110 
111 
115  static Thread *CurrentThread();
116 
117 
122  static void Init();
123 
132  static int YieldCurrentThread();
133 
143  static ThreadPriority GetMasterPriority() {return s_masterThreadPriority;};
144 
145 
151  int getThreadId();
152 
159  size_t getProcessId();
160 
171  int start();
172  int startThread();
173 
181  int testCancel();
182 
183 
189  virtual int cancel();
190 
211  int setSchedulePriority(ThreadPriority priority);
212 
221  int getSchedulePriority();
222 
237  int setSchedulePolicy(ThreadPolicy policy);
238 
247  int getSchedulePolicy();
248 
259  int setStackSize(size_t size);
260 
268  size_t getStackSize();
269 
273  void printSchedulingInfo();
274 
280  int detach();
281 
287  int join();
288 
294  int setCancelModeDisable();
295 
302  int setCancelModeAsynchronous();
303 
310  int setCancelModeDeferred();
311 
317  bool isRunning();
318 
323  virtual void run() = 0;
324 
331  virtual void cancelCleanup() {};
332 
333  void* getImplementation(){ return _prvData; };
334 
343  int setProcessorAffinity( unsigned int cpunum );
344 
352  static int microSleep( unsigned int microsec);
353 
354 private:
355 
359  friend class ThreadPrivateActions;
360 
364  Thread(const Thread &/*t*/) {};
365 
369  Thread &operator=(const Thread &/*t*/) {return *(this);};
370 
374  void * _prvData;
375 
379  static ThreadPriority s_masterThreadPriority;
380 
384  static bool s_isInitialized;
385 };
386 
387 }
388 
389 #endif // !_OPENTHREADS_THREAD_
This class provides an object-oriented thread interface.
Definition: Thread.h:49
#define OPENTHREAD_EXPORT_DIRECTIVE
Definition: Exports.h:20
void * getImplementation()
Definition: Thread.h:333
OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors()
static ThreadPriority GetMasterPriority()
Definition: Thread.h:143
virtual void cancelCleanup()
Definition: Thread.h:331
OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(unsigned int cpunum)