Thread
Go to the documentation of this file.
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//
// Thread - C++ Thread class
// ~~~~~~~~
//
#ifndef _OPENTHREADS_THREAD_
#define _OPENTHREADS_THREAD_
#include <sys/types.h>
#include <OpenThreads/Mutex>
#include <OpenThreads/Affinity>
namespace OpenThreads {
extern OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors();
extern OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(const Affinity& affinity);
class OPENTHREAD_EXPORT_DIRECTIVE Thread {
public:
static int SetConcurrency(int concurrencyLevel);
static int GetConcurrency();
enum ThreadPriority {
THREAD_PRIORITY_MAX,
THREAD_PRIORITY_HIGH,
THREAD_PRIORITY_NOMINAL,
THREAD_PRIORITY_LOW,
THREAD_PRIORITY_MIN,
THREAD_PRIORITY_DEFAULT
};
enum ThreadPolicy {
THREAD_SCHEDULE_FIFO,
THREAD_SCHEDULE_ROUND_ROBIN,
THREAD_SCHEDULE_TIME_SHARE,
THREAD_SCHEDULE_DEFAULT
};
Thread();
virtual ~Thread();
static Thread *CurrentThread();
static size_t CurrentThreadId();
static void Init();
static int YieldCurrentThread();
static ThreadPriority GetMasterPriority() {return s_masterThreadPriority;};
size_t getThreadId();
size_t getProcessId();
int start();
int startThread();
int testCancel();
virtual int cancel();
int setSchedulePriority(ThreadPriority priority);
int getSchedulePriority();
int setSchedulePolicy(ThreadPolicy policy);
int getSchedulePolicy();
int setStackSize(size_t size);
size_t getStackSize();
void printSchedulingInfo();
int detach();
int join();
int setCancelModeDisable();
int setCancelModeAsynchronous();
int setCancelModeDeferred();
bool isRunning();
virtual void run() = 0;
virtual void cancelCleanup() {};
void* getImplementation(){ return _prvData; };
int setProcessorAffinity( const Affinity& affinity);
static int microSleep( unsigned int microsec);
private:
friend class ThreadPrivateActions;
Thread(const Thread &/*t*/) {};
Thread &operator=(const Thread &/*t*/) {return *(this);};
void * _prvData;
static ThreadPriority s_masterThreadPriority;
static bool s_isInitialized;
};
}
#endif // !_OPENTHREADS_THREAD_
Affinity
OPENTHREAD_EXPORT_DIRECTIVE
#define OPENTHREAD_EXPORT_DIRECTIVE
Definition Exports:20
Mutex
OpenThreads::Affinity
Simple container for specifying which CPU a thread should have affinity with. An empty Affinity....
Definition Affinity:34
OpenThreads::Thread
This class provides an object-oriented thread interface.
Definition Thread:48
OpenThreads::Thread::SetConcurrency
static int SetConcurrency(int concurrencyLevel)
OpenThreads::Thread::microSleep
static int microSleep(unsigned int microsec)
OpenThreads::Thread::ThreadPriority
ThreadPriority
Definition Thread:77
OpenThreads::Thread::THREAD_PRIORITY_DEFAULT
@ THREAD_PRIORITY_DEFAULT
Definition Thread:84
OpenThreads::Thread::THREAD_PRIORITY_NOMINAL
@ THREAD_PRIORITY_NOMINAL
Definition Thread:81
OpenThreads::Thread::THREAD_PRIORITY_LOW
@ THREAD_PRIORITY_LOW
Definition Thread:82
OpenThreads::Thread::THREAD_PRIORITY_HIGH
@ THREAD_PRIORITY_HIGH
Definition Thread:80
OpenThreads::Thread::THREAD_PRIORITY_MIN
@ THREAD_PRIORITY_MIN
Definition Thread:83
OpenThreads::Thread::THREAD_PRIORITY_MAX
@ THREAD_PRIORITY_MAX
Definition Thread:79
OpenThreads::Thread::setCancelModeAsynchronous
int setCancelModeAsynchronous()
OpenThreads::Thread::ThreadPrivateActions
friend class ThreadPrivateActions
Definition Thread:362
OpenThreads::Thread::setSchedulePriority
int setSchedulePriority(ThreadPriority priority)
OpenThreads::Thread::getImplementation
void * getImplementation()
Definition Thread:337
OpenThreads::Thread::cancelCleanup
virtual void cancelCleanup()
Definition Thread:335
OpenThreads::Thread::setStackSize
int setStackSize(size_t size)
OpenThreads::Thread::ThreadPolicy
ThreadPolicy
Definition Thread:91
OpenThreads::Thread::THREAD_SCHEDULE_FIFO
@ THREAD_SCHEDULE_FIFO
Definition Thread:93
OpenThreads::Thread::THREAD_SCHEDULE_DEFAULT
@ THREAD_SCHEDULE_DEFAULT
Definition Thread:96
OpenThreads::Thread::THREAD_SCHEDULE_ROUND_ROBIN
@ THREAD_SCHEDULE_ROUND_ROBIN
Definition Thread:94
OpenThreads::Thread::THREAD_SCHEDULE_TIME_SHARE
@ THREAD_SCHEDULE_TIME_SHARE
Definition Thread:95
OpenThreads::Thread::printSchedulingInfo
void printSchedulingInfo()
OpenThreads::Thread::setSchedulePolicy
int setSchedulePolicy(ThreadPolicy policy)
OpenThreads::Thread::Thread
Thread()
OpenThreads::Thread::setCancelModeDisable
int setCancelModeDisable()
OpenThreads::Thread::YieldCurrentThread
static int YieldCurrentThread()
OpenThreads::Thread::setProcessorAffinity
int setProcessorAffinity(const Affinity &affinity)
OpenThreads::Thread::startThread
int startThread()
OpenThreads::Thread::CurrentThreadId
static size_t CurrentThreadId()
OpenThreads::Thread::getSchedulePriority
int getSchedulePriority()
OpenThreads::Thread::isRunning
bool isRunning()
OpenThreads::Thread::testCancel
int testCancel()
OpenThreads::Thread::join
int join()
OpenThreads::Thread::getStackSize
size_t getStackSize()
OpenThreads::Thread::cancel
virtual int cancel()
OpenThreads::Thread::detach
int detach()
OpenThreads::Thread::CurrentThread
static Thread * CurrentThread()
OpenThreads::Thread::getThreadId
size_t getThreadId()
OpenThreads::Thread::GetConcurrency
static int GetConcurrency()
OpenThreads::Thread::~Thread
virtual ~Thread()
OpenThreads::Thread::start
int start()
OpenThreads::Thread::getSchedulePolicy
int getSchedulePolicy()
OpenThreads::Thread::getProcessId
size_t getProcessId()
OpenThreads::Thread::Init
static void Init()
OpenThreads::Thread::run
virtual void run()=0
OpenThreads::Thread::setCancelModeDeferred
int setCancelModeDeferred()
OpenThreads::Thread::GetMasterPriority
static ThreadPriority GetMasterPriority()
Definition Thread:147
OpenThreads
Definition Affinity:26
OpenThreads::SetProcessorAffinityOfCurrentThread
OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(const Affinity &affinity)
OpenThreads::GetNumberOfProcessors
OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors()