activemq-cpp-3.6.0
|
#include <src/main/decaf/internal/util/concurrent/Threading.h>
Static Public Member Functions | |
static void | initialize () |
Called by the Decaf Runtime at startup to allow the Platform Threading code to initialize any necessary Threading constructs needed to support the features of this class. | |
static void | shutdown () |
Called by the Decaf Runtime at Shutdown to allow the Platform Threading code to return any resources that were allocated at startup for the Threading library. | |
static void | lockThreadsLib () |
Locks the Threading library allowing an object to perform some operations safely in a multi-threaded environment. | |
static void | unlockThreadsLib () |
Unlocks the Threading library when locked. | |
static void | dumpRunningThreads () |
Diagnostic method dumps all threads info to console. | |
static MonitorHandle * | takeMonitor (bool alreadyLocked=false) |
Gets a monitor for use as a locking mechanism. | |
static void | returnMonitor (MonitorHandle *monitor, bool alreadyLocked=false) |
Returns a given monitor to the Monitor pool after the Monitor is no longer needed. | |
static void | enterMonitor (MonitorHandle *monitor) |
Monitor locking method. | |
static bool | tryEnterMonitor (MonitorHandle *monitor) |
Monitor locking method. | |
static void | exitMonitor (MonitorHandle *monitor) |
Exit the acquired monitor giving up the lock that is held and allowing other threads to acquire the monitor. | |
static bool | waitOnMonitor (MonitorHandle *monitor, long long mills, int nanos) |
Waits on a monitor to be signaled by another thread. | |
static void | notifyWaiter (MonitorHandle *monitor) |
Notify a single waiter on the given Monitor instance, if there is no thread currently waiting on the specified monitor then no action is taken. | |
static void | notifyAllWaiters (MonitorHandle *monitor) |
Notifies all waiting threads for the given Monitor. | |
static bool | isMonitorLocked (MonitorHandle *monitor) |
Query the monitor object to determine if it is currently locked. | |
static ThreadHandle * | createNewThread (Thread *parant, const char *name, long long stackSize) |
Creates a new thread instance with the given Thread object as its parent, assigning it the given name and stack size. | |
static void | start (ThreadHandle *thread) |
Starts the given thread running, if the thread is already running then this method has no effect. | |
static bool | join (ThreadHandle *thread, long long mills, int nanos) |
Joins the given thread instance and waits for it to either terminate or for the given timeout period to expire. | |
static void | interrupt (ThreadHandle *thread) |
static bool | interrupted () |
static bool | isInterrupted (ThreadHandle *thread, bool reset) |
static void | yeild () |
static bool | sleep (long long mills, int nanos) |
static long long | getThreadId (ThreadHandle *thread) |
static int | getThreadPriority (ThreadHandle *thread) |
static void | setThreadPriority (ThreadHandle *thread, int priority) |
static const char * | getThreadName (ThreadHandle *thread) |
static void | setThreadName (ThreadHandle *thread, const char *name) |
static Thread::State | getThreadState (ThreadHandle *thread) |
static bool | isThreadAlive (ThreadHandle *thread) |
static void | destroyThread (ThreadHandle *thread) |
static ThreadHandle * | createThreadWrapper (decaf::lang::Thread *parent, const char *name) |
Creates and returns a ThreadHandle that references the currently running thread. | |
static Thread * | getCurrentThread () |
static ThreadHandle * | getCurrentThreadHandle () |
static void | park (Thread *thread) |
Removes the given thread from scheduling unless a call to unpark has already reset the park token in which case this method simple consumes the unpark token and returned. | |
static bool | park (Thread *thread, long long mills, int nanos) |
Removes the given thread from scheduling unless a call to unpark has already reset the park token in which case this method simple consumes the unpark token and returned. | |
static void | unpark (Thread *thread) |
If the target thread is not currently parked then this method sets the un-park token for the thread and returns. | |
static int | createThreadLocalSlot (ThreadLocalImpl *threadLocal) |
Allocates a slot in the library for a new ThreadLocalImpl to store its values for each thread. | |
static void * | getThreadLocalValue (int slot) |
static void | setThreadLocalValue (int slot, void *value) |
static void | destoryThreadLocalSlot (int slot) |
|
static |
Creates a new thread instance with the given Thread object as its parent, assigning it the given name and stack size.
The Thread class provides its own main Runnable for executing task.
parent | The parent Thread object that the new thread is owned by. |
name | Name given to the new Thread, used for debugging purposes. |
stackSize | The size to allocate for the new thread's stack. |
|
static |
Allocates a slot in the library for a new ThreadLocalImpl to store its values for each thread.
The parent ThreadLocalImpl is stored so that the library can call each ThreadLocalImpl to cleanup its resources if there are active objects at the time the library is shutdown or the Thread terminates.
threadLocal | The ThreadLocalImpl to assign a storage slot. |
|
static |
Creates and returns a ThreadHandle that references the currently running thread.
This method is called to obtain a ThreadHandle that references an thread that was not created using the Decaf Thread class. A parent Thread instance is passed to associate with the target thread so that a call to getCurrentThread can return a Decaf Thread as it would for any thread created using Thread.
parent | The Decaf thread instace to associate with this thread handle. |
name | The name to assign to the returned ThreadHandle. |
|
static |
|
static |
|
static |
Diagnostic method dumps all threads info to console.
|
static |
Monitor locking method.
The calling thread blocks until it acquires the monitor. A thread can enter the same monitor more than once, but must then exit the monitor the same number of times.
monitor | The handle to the monitor that the current thread is attempting to lock. |
|
static |
Exit the acquired monitor giving up the lock that is held and allowing other threads to acquire the monitor.
If the calling thread has entered the monitor more than once then it must exit that monitor the same number of times.
monitor | Handle to the monitor instance that is to be excited. |
IllegalMonitorStateException | if the caller is not the owner of the monitor. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Query the monitor object to determine if it is currently locked.
This method is a mainly a diagnostic tool and its return value is not guaranteed to reflect the locked state after its been called as the state can change quickly.
|
static |
|
static |
Joins the given thread instance and waits for it to either terminate or for the given timeout period to expire.
If the value of of the timeout is zero then this method waits forever.
thread | The target thread to join. |
mills | The number of milliseconds to wait. |
nanos | The number of nanoseconds to wait [0-999999]. |
InterruptedException | if the Join was interrupted. |
IllegalArgumentException | if the value of mills or nanos is invalid. |
|
static |
Locks the Threading library allowing an object to perform some operations safely in a multi-threaded environment.
|
static |
Notifies all waiting threads for the given Monitor.
If there are no threads currently waiting on the given monitor instance then no action is taken. The calling thread must own the given monitor otherwise an IllegalMonitorStateException is thrown.
monitor | The monitor handle that is to have all of its waiting thread signaled. |
IllegalMonitorStateException | if the caller does not own the monitor. |
|
static |
Notify a single waiter on the given Monitor instance, if there is no thread currently waiting on the specified monitor then no action is taken.
The calling thread must own the given monitor otherwise an IllegalMonitorStateException is thrown.
monitor | The monitor handle that is to have a single waiting thread signaled. |
IllegalMonitorStateException | if the caller does not own the monitor. |
|
static |
Removes the given thread from scheduling unless a call to unpark has already reset the park token in which case this method simple consumes the unpark token and returned.
thread | The target thread to park. |
|
static |
Removes the given thread from scheduling unless a call to unpark has already reset the park token in which case this method simple consumes the unpark token and returned.
thread | The target thread to park. |
mills | The time in milliseconds to park the target thread. |
nanos | The additional time in nanoseconds to park the target thread. |
|
static |
Returns a given monitor to the Monitor pool after the Monitor is no longer needed.
monitor | The handle of the Monitor to return to the Monitor pool. |
IllegalMonitorStateException | if the monitor is in use when returned. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Starts the given thread running, if the thread is already running then this method has no effect.
thread | The thread instance to start. |
|
static |
Gets a monitor for use as a locking mechanism.
The monitor returned will be initialized and ready for use. Each monitor that is taken must be returned before the Threading library is shutdown.
|
static |
Monitor locking method.
If the calling thread cannot immediately acquire the lock on the monitor then this method returns false, otherwise the thread gains the lock on the monitor and the method returns true. A thread can enter a monitor multiple times, but must ensure that it exits the monitor the same number of times that it entered it.
monitor | The handle to the monitor that the current thread is attempting to lock. |
|
static |
Unlocks the Threading library when locked.
|
static |
If the target thread is not currently parked then this method sets the un-park token for the thread and returns.
If the thread is parked than this method places the thread back in a state where it can be scheduled once more.
thread | The thread to unpark. |
|
static |
Waits on a monitor to be signaled by another thread.
The caller can wait for a given timeout or pass zero for both mills and nanos to indicate it wants to wait forever. If the caller specifies a timeout and that timeout expires before the monitor is signaled this method returns true. The calling thread must own the monitor in order to call this method, otherwise an IllegalMonitorStateException is thrown.
monitor | Handle to the monitor that the calling thread is to wait on for a signal. |
mills | The time in milliseconds to wait for the monitor to be signaled. |
nanos | The time in nanoseconds to wait for the monitor to be signaled. |
IllegalMonitorStateException | if the caller does not own the monitor. |
|
static |