activemq-cpp-3.6.0
decaf::internal::util::concurrent::Threading Class Reference

#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 MonitorHandletakeMonitor (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 ThreadHandlecreateNewThread (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 ThreadHandlecreateThreadWrapper (decaf::lang::Thread *parent, const char *name)
 Creates and returns a ThreadHandle that references the currently running thread.
static ThreadgetCurrentThread ()
static ThreadHandlegetCurrentThreadHandle ()
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)

Member Function Documentation

static ThreadHandle* decaf::internal::util::concurrent::Threading::createNewThread ( Thread parant,
const char *  name,
long long  stackSize 
)
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.

Parameters
parentThe parent Thread object that the new thread is owned by.
nameName given to the new Thread, used for debugging purposes.
stackSizeThe size to allocate for the new thread's stack.
Returns
a new ThreadHandle that identifies the thread and allows the parent to interact with it.
static int decaf::internal::util::concurrent::Threading::createThreadLocalSlot ( ThreadLocalImpl threadLocal)
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.

Parameters
threadLocalThe ThreadLocalImpl to assign a storage slot.
Returns
a new storage slot Id for the given ThreadLocalImpl's value to be assigned.
static ThreadHandle* decaf::internal::util::concurrent::Threading::createThreadWrapper ( decaf::lang::Thread parent,
const char *  name 
)
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.

Parameters
parentThe Decaf thread instace to associate with this thread handle.
nameThe name to assign to the returned ThreadHandle.
Returns
a new ThreadHandle instance for the parent Decaf Thread.
static void decaf::internal::util::concurrent::Threading::destoryThreadLocalSlot ( int  slot)
static
static void decaf::internal::util::concurrent::Threading::destroyThread ( ThreadHandle thread)
static
static void decaf::internal::util::concurrent::Threading::dumpRunningThreads ( )
static

Diagnostic method dumps all threads info to console.

static void decaf::internal::util::concurrent::Threading::enterMonitor ( MonitorHandle monitor)
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.

Parameters
monitorThe handle to the monitor that the current thread is attempting to lock.
static void decaf::internal::util::concurrent::Threading::exitMonitor ( MonitorHandle monitor)
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.

Parameters
monitorHandle to the monitor instance that is to be excited.
Exceptions
IllegalMonitorStateExceptionif the caller is not the owner of the monitor.
static Thread* decaf::internal::util::concurrent::Threading::getCurrentThread ( )
static
Returns
the Decaf Thread pointer instance for the currently running thread.
static ThreadHandle* decaf::internal::util::concurrent::Threading::getCurrentThreadHandle ( )
static
Returns
the ThreadHandle instance for the currently running thread.
static long long decaf::internal::util::concurrent::Threading::getThreadId ( ThreadHandle thread)
static
static void* decaf::internal::util::concurrent::Threading::getThreadLocalValue ( int  slot)
static
static const char* decaf::internal::util::concurrent::Threading::getThreadName ( ThreadHandle thread)
static
static int decaf::internal::util::concurrent::Threading::getThreadPriority ( ThreadHandle thread)
static
static Thread::State decaf::internal::util::concurrent::Threading::getThreadState ( ThreadHandle thread)
static
static void decaf::internal::util::concurrent::Threading::initialize ( )
static

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 decaf::internal::util::concurrent::Threading::interrupt ( ThreadHandle thread)
static
static bool decaf::internal::util::concurrent::Threading::interrupted ( )
static
static bool decaf::internal::util::concurrent::Threading::isInterrupted ( ThreadHandle thread,
bool  reset 
)
static
static bool decaf::internal::util::concurrent::Threading::isMonitorLocked ( MonitorHandle monitor)
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 bool decaf::internal::util::concurrent::Threading::isThreadAlive ( ThreadHandle thread)
static
static bool decaf::internal::util::concurrent::Threading::join ( ThreadHandle thread,
long long  mills,
int  nanos 
)
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.

Parameters
threadThe target thread to join.
millsThe number of milliseconds to wait.
nanosThe number of nanoseconds to wait [0-999999].
Returns
true if the timeout period expired, false otherwise.
Exceptions
InterruptedExceptionif the Join was interrupted.
IllegalArgumentExceptionif the value of mills or nanos is invalid.
static void decaf::internal::util::concurrent::Threading::lockThreadsLib ( )
static

Locks the Threading library allowing an object to perform some operations safely in a multi-threaded environment.

static void decaf::internal::util::concurrent::Threading::notifyAllWaiters ( MonitorHandle monitor)
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.

Parameters
monitorThe monitor handle that is to have all of its waiting thread signaled.
Exceptions
IllegalMonitorStateExceptionif the caller does not own the monitor.
static void decaf::internal::util::concurrent::Threading::notifyWaiter ( MonitorHandle 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.

Parameters
monitorThe monitor handle that is to have a single waiting thread signaled.
Exceptions
IllegalMonitorStateExceptionif the caller does not own the monitor.
static void decaf::internal::util::concurrent::Threading::park ( Thread thread)
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.

Parameters
threadThe target thread to park.
static bool decaf::internal::util::concurrent::Threading::park ( Thread thread,
long long  mills,
int  nanos 
)
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.

Parameters
threadThe target thread to park.
millsThe time in milliseconds to park the target thread.
nanosThe additional time in nanoseconds to park the target thread.
static void decaf::internal::util::concurrent::Threading::returnMonitor ( MonitorHandle monitor,
bool  alreadyLocked = false 
)
static

Returns a given monitor to the Monitor pool after the Monitor is no longer needed.

Parameters
monitorThe handle of the Monitor to return to the Monitor pool.
Exceptions
IllegalMonitorStateExceptionif the monitor is in use when returned.
static void decaf::internal::util::concurrent::Threading::setThreadLocalValue ( int  slot,
void *  value 
)
static
static void decaf::internal::util::concurrent::Threading::setThreadName ( ThreadHandle thread,
const char *  name 
)
static
static void decaf::internal::util::concurrent::Threading::setThreadPriority ( ThreadHandle thread,
int  priority 
)
static
static void decaf::internal::util::concurrent::Threading::shutdown ( )
static

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 bool decaf::internal::util::concurrent::Threading::sleep ( long long  mills,
int  nanos 
)
static
static void decaf::internal::util::concurrent::Threading::start ( ThreadHandle thread)
static

Starts the given thread running, if the thread is already running then this method has no effect.

Parameters
threadThe thread instance to start.
static MonitorHandle* decaf::internal::util::concurrent::Threading::takeMonitor ( bool  alreadyLocked = false)
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.

Returns
handle to a Monitor instance that has been initialized.
static bool decaf::internal::util::concurrent::Threading::tryEnterMonitor ( MonitorHandle monitor)
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.

Parameters
monitorThe handle to the monitor that the current thread is attempting to lock.
Returns
true if the caller obtains the lock on the Monitor, false otherwise.
static void decaf::internal::util::concurrent::Threading::unlockThreadsLib ( )
static

Unlocks the Threading library when locked.

static void decaf::internal::util::concurrent::Threading::unpark ( Thread thread)
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.

Parameters
threadThe thread to unpark.
static bool decaf::internal::util::concurrent::Threading::waitOnMonitor ( MonitorHandle monitor,
long long  mills,
int  nanos 
)
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.

Parameters
monitorHandle to the monitor that the calling thread is to wait on for a signal.
millsThe time in milliseconds to wait for the monitor to be signaled.
nanosThe time in nanoseconds to wait for the monitor to be signaled.
Returns
true if the timeout given expires before the caller was signaled.
Exceptions
IllegalMonitorStateExceptionif the caller does not own the monitor.
static void decaf::internal::util::concurrent::Threading::yeild ( )
static

The documentation for this class was generated from the following file: