Ark Server API (ASE) - Wiki
|
#include <Thread.h>
Classes | |
class | FunctorRunnable |
Creates and returns a unique id for a thread. More... | |
Public Types | |
enum | Priority { PRIO_LOWEST = PRIO_LOWEST_IMPL , PRIO_LOW = PRIO_LOW_IMPL , PRIO_NORMAL = PRIO_NORMAL_IMPL , PRIO_HIGH = PRIO_HIGH_IMPL , PRIO_HIGHEST = PRIO_HIGHEST_IMPL } |
Thread priorities. More... | |
enum | Policy { POLICY_DEFAULT = POLICY_DEFAULT_IMPL } |
typedef ThreadImpl::TIDImpl | TID |
typedef void(* | Callable) (void *) |
Public Member Functions | |
Thread () | |
Thread (const std::string &name) | |
Creates a thread. Call start() to start it. | |
~Thread () | |
Creates a named thread. Call start() to start it. | |
int | id () const |
Destroys the thread. | |
TID | tid () const |
Returns the unique thread ID of the thread. | |
std::string | name () const |
Returns the native thread ID of the thread. | |
std::string | getName () const |
Returns the name of the thread. | |
void | setName (const std::string &name) |
Returns the name of the thread. | |
void | setPriority (Priority prio) |
Sets the name of the thread. | |
Priority | getPriority () const |
void | setOSPriority (int prio, int policy=POLICY_DEFAULT) |
Returns the thread's priority. | |
int | getOSPriority () const |
void | setStackSize (int size) |
int | getStackSize () const |
void | start (Runnable &target) |
void | start (Poco::SharedPtr< Runnable > pTarget) |
void | start (Callable target, void *pData=0) |
template<class Functor > | |
void | startFunc (const Functor &fn) |
Starts the thread with the given target and parameter. | |
template<class Functor > | |
void | startFunc (Functor &&fn) |
Starts the thread with the given functor object or lambda. | |
void | join () |
void | join (long milliseconds) |
bool | tryJoin (long milliseconds) |
bool | isRunning () const |
void | wakeUp () |
Static Public Member Functions | |
static int | getMinOSPriority (int policy=POLICY_DEFAULT) |
static int | getMaxOSPriority (int policy=POLICY_DEFAULT) |
static bool | trySleep (long milliseconds) |
Returns true if the thread is running. | |
static void | sleep (long milliseconds) |
static void | yield () |
static Thread * | current () |
Yields cpu to other threads. | |
static TID | currentTid () |
Protected Member Functions | |
ThreadLocalStorage & | tls () |
Returns the native thread ID for the current thread. | |
void | clearTLS () |
Returns a reference to the thread's local storage. | |
std::string | makeName () |
Clears the thread's local storage. | |
Static Protected Member Functions | |
static int | uniqueId () |
Creates a unique name for a thread. | |
Private Member Functions | |
Thread (const Thread &) | |
Thread & | operator= (const Thread &) |
Private Member Functions inherited from Poco::ThreadImpl | |
ThreadImpl () | |
~ThreadImpl () | |
TIDImpl | tidImpl () const |
void | setPriorityImpl (int prio) |
int | getPriorityImpl () const |
void | setOSPriorityImpl (int prio, int policy=0) |
int | getOSPriorityImpl () const |
void | setStackSizeImpl (int size) |
int | getStackSizeImpl () const |
void | startImpl (SharedPtr< Runnable > pTarget) |
void | joinImpl () |
bool | joinImpl (long milliseconds) |
bool | isRunningImpl () const |
void | createImpl (Entry ent, void *pData) |
void | threadCleanup () |
Private Attributes | |
int | _id |
std::string | _name |
ThreadLocalStorage * | _pTLS |
Event | _event |
FastMutex | _mutex |
Friends | |
class | ThreadLocalStorage |
class | PooledThread |
Additional Inherited Members | |
Private Types inherited from Poco::ThreadImpl | |
enum | Priority { PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST , PRIO_LOW_IMPL = THREAD_PRIORITY_BELOW_NORMAL , PRIO_NORMAL_IMPL = THREAD_PRIORITY_NORMAL , PRIO_HIGH_IMPL = THREAD_PRIORITY_ABOVE_NORMAL , PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST } |
enum | Policy { POLICY_DEFAULT_IMPL = 0 } |
typedef DWORD | TIDImpl |
typedef void(* | Callable) (void *) |
typedef unsigned(__stdcall * | Entry) (void *) |
Static Private Member Functions inherited from Poco::ThreadImpl | |
static int | getMinOSPriorityImpl (int policy) |
static int | getMaxOSPriorityImpl (int policy) |
static void | sleepImpl (long milliseconds) |
static void | yieldImpl () |
static ThreadImpl * | currentImpl () |
static TIDImpl | currentTidImpl () |
static unsigned __stdcall | runnableEntry (void *pThread) |
This class implements a platform-independent wrapper to an operating system thread.
Every Thread object gets a unique (within its process) numeric thread ID. Furthermore, a thread can be assigned a name. The name of a thread can be changed at any time.
typedef void(* Poco::ThreadImpl::Callable) (void *) |
Definition at line 34 of file Thread_WIN32.h.
typedef ThreadImpl::TIDImpl Poco::Thread::TID |
enum Poco::Thread::Policy |
Poco::Thread::Thread | ( | ) |
Poco::Thread::Thread | ( | const std::string & | name | ) |
Creates a thread. Call start() to start it.
Poco::Thread::~Thread | ( | ) |
Creates a named thread. Call start() to start it.
|
private |
|
protected |
Returns a reference to the thread's local storage.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Returns the minimum operating system-specific priority value, which can be passed to setOSPriority() for the given policy.
Definition at line 358 of file Thread.h.
|
inlinestatic |
|
inline |
|
inline |
Sets the thread's priority, using an operating system specific priority value. Use getMinOSPriority() and getMaxOSPriority() to obtain mininum and maximum priority values. Additionally, a scheduling policy can be specified. The policy is currently only used on POSIX platforms where the values SCHED_OTHER (default), SCHED_FIFO and SCHED_RR are supported.
Definition at line 346 of file Thread.h.
Priority Poco::Thread::getPriority | ( | ) | const |
Sets the thread's priority.
Some platform only allow changing a thread's priority if the process has certain privileges.
|
inline |
|
inline |
void Poco::Thread::join | ( | ) |
void Poco::Thread::join | ( | long | milliseconds | ) |
Waits until the thread completes execution. If multiple threads try to join the same thread, the result is undefined.
|
protected |
Clears the thread's local storage.
|
inline |
void Poco::Thread::setName | ( | const std::string & | name | ) |
Returns the name of the thread.
|
inline |
void Poco::Thread::setPriority | ( | Priority | prio | ) |
Sets the name of the thread.
|
inline |
Returns the maximum operating system-specific priority value, which can be passed to setOSPriority() for the given policy.
Definition at line 364 of file Thread.h.
|
inlinestatic |
Wakes up the thread which is in the state of interruptible sleep. For threads that are not suspended, calling this function has the effect of preventing the subsequent trySleep() call to put thread in a suspended state.
Definition at line 322 of file Thread.h.
void Poco::Thread::start | ( | Callable | target, |
void * | pData = 0 ) |
Starts the thread with the given target.
The Thread ensures that the given target stays alive while the thread is running.
void Poco::Thread::start | ( | Poco::SharedPtr< Runnable > | pTarget | ) |
Starts the thread with the given target.
Note that the given Runnable object must remain valid during the entire lifetime of the thread, as only a reference to it is stored internally.
void Poco::Thread::start | ( | Runnable & | target | ) |
Returns the thread's stack size in bytes. If the default stack size is used, 0 is returned.
|
inline |
|
inline |
|
inline |
|
protected |
Returns the native thread ID for the current thread.
bool Poco::Thread::tryJoin | ( | long | milliseconds | ) |
Waits for at most the given interval for the thread to complete. Throws a TimeoutException if the thread does not complete within the specified time interval.
|
static |
Returns true if the thread is running.
|
staticprotected |
Creates a unique name for a thread.
void Poco::Thread::wakeUp | ( | ) |
Starts an interruptible sleep. When trySleep() is called, the thread will remain suspended until:
Function returns true if sleep attempt was completed, false if sleep was interrupted by a wakeUp() call. A frequent scenario where trySleep()/wakeUp() pair of functions is useful is with threads spending most of the time idle, with periodic activity between the idle times; trying to sleep (as opposed to sleeping) allows immediate ending of idle thread from the outside.
The trySleep() and wakeUp() calls should be used with understanding that the suspended state is not a true sleep, but rather a state of waiting for an event, with timeout expiration. This makes order of calls significant; calling wakeUp() before calling trySleep() will prevent the next trySleep() call to actually suspend the thread (which, in some scenarios, may be desirable behavior).
|
inlinestatic |
|
private |