activemq-cpp-3.9.5
Threading.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_INTERNAL_UTIL_CONCURRENT_THREADING_H_
19#define _DECAF_INTERNAL_UTIL_CONCURRENT_THREADING_H_
20
21#include <decaf/util/Config.h>
22
23#include <decaf/lang/Thread.h>
24
25namespace decaf {
26namespace internal {
27namespace util {
28namespace concurrent {
29
30 using decaf::lang::Thread;
31
32 class ThreadLocalImpl;
33 struct ThreadHandle;
34 struct MonitorHandle;
35
36 class DECAF_API Threading {
37 private:
38
39 Threading();
40 Threading(const Threading&);
41 Threading& operator= (const Threading&);
42
43 public:
44
50 static void initialize();
51
57 static void shutdown();
58
63 static void lockThreadsLib();
64
68 static void unlockThreadsLib();
69
73 static void dumpRunningThreads();
74
75 public: // Monitors
76
84 static MonitorHandle* takeMonitor(bool alreadyLocked = false);
85
94 static void returnMonitor(MonitorHandle* monitor, bool alreadyLocked = false);
95
104 static void enterMonitor(MonitorHandle* monitor);
105
118 static bool tryEnterMonitor(MonitorHandle* monitor);
119
130 static void exitMonitor(MonitorHandle* monitor);
131
151 static bool waitOnMonitor(MonitorHandle* monitor, long long mills, int nanos);
152
163 static void notifyWaiter(MonitorHandle* monitor);
164
175 static void notifyAllWaiters(MonitorHandle* monitor);
176
182 static bool isMonitorLocked(MonitorHandle* monitor);
183
184 public: // Threads
185
201 static ThreadHandle* createNewThread(Thread* parant, const char* name,
202 long long stackSize);
203
211 static void start(ThreadHandle* thread);
212
230 static bool join(ThreadHandle* thread, long long mills, int nanos);
231
232 static void interrupt(ThreadHandle* thread);
233 static bool interrupted();
234 static bool isInterrupted(ThreadHandle* thread, bool reset);
235
236 static void yeild();
237 static bool sleep(long long mills, int nanos);
238
239 static long long getThreadId(ThreadHandle* thread);
240
241 static int getThreadPriority(ThreadHandle* thread);
242
243 static void setThreadPriority(ThreadHandle* thread, int priority);
244
245 static const char* getThreadName(ThreadHandle* thread);
246
247 static void setThreadName(ThreadHandle* thread, const char* name);
248
250
251 static bool isThreadAlive(ThreadHandle* thread);
252
253 static void destroyThread(ThreadHandle* thread);
254
270 static ThreadHandle* createThreadWrapper(decaf::lang::Thread* parent, const char* name);
271
276
281
290 static void park(Thread* thread);
291
304 static bool park(Thread* thread, long long mills, int nanos);
305
314 static void unpark(Thread* thread);
315
316 public: // Thread local storage
317
329 static int createThreadLocalSlot(ThreadLocalImpl* threadLocal);
330
331 static void* getThreadLocalValue(int slot);
332
333 static void setThreadLocalValue(int slot, void* value);
334
335 static void destoryThreadLocalSlot(int slot);
336
338
339 private:
340
341 static ThreadHandle* attachToCurrentThread();
342 static void detachFromCurrentThread(ThreadHandle* thread);
343 static void monitorEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
344 static bool monitorTryEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
345 static void monitorExitUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
346 };
347
348}}}}
349
350#endif /* _DECAF_INTERNAL_UTIL_CONCURRENT_THREADING_H_ */
State
Represents the various states that the Thread can be in during its lifetime.
Definition Thread.h:84
static void lockThreadsLib()
Locks the Threading library allowing an object to perform some operations safely in a multi-threaded ...
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...
static bool waitOnMonitor(MonitorHandle *monitor, long long mills, int nanos)
Waits on a monitor to be signaled by another thread.
static void setThreadLocalValue(int slot, void *value)
static const char * getThreadName(ThreadHandle *thread)
static bool isMonitorLocked(MonitorHandle *monitor)
Query the monitor object to determine if it is currently locked.
static ThreadHandle * createThreadWrapper(decaf::lang::Thread *parent, const char *name)
Creates and returns a ThreadHandle that references the currently running thread.
static MonitorHandle * takeMonitor(bool alreadyLocked=false)
Gets a monitor for use as a locking mechanism.
static void initialize()
Called by the Decaf Runtime at startup to allow the Platform Threading code to initialize any necessa...
static void dumpRunningThreads()
Diagnostic method dumps all threads info to console.
static long long getThreadId(ThreadHandle *thread)
static void setThreadName(ThreadHandle *thread, const char *name)
static ThreadHandle * getCurrentThreadHandle()
static void notifyAllWaiters(MonitorHandle *monitor)
Notifies all waiting threads for the given Monitor.
static void unpark(Thread *thread)
If the target thread is not currently parked then this method sets the un-park token for the thread a...
static void enterMonitor(MonitorHandle *monitor)
Monitor locking method.
static bool tryEnterMonitor(MonitorHandle *monitor)
Monitor locking method.
static void start(ThreadHandle *thread)
Starts the given thread running, if the thread is already running then this method has no effect.
static bool isInterrupted(ThreadHandle *thread, bool reset)
static void destroyThread(ThreadHandle *thread)
static void park(Thread *thread)
Removes the given thread from scheduling unless a call to unpark has already reset the park token in ...
static void shutdown()
Called by the Decaf Runtime at Shutdown to allow the Platform Threading code to return any resources ...
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 ...
static void interrupt(ThreadHandle *thread)
static void unlockThreadsLib()
Unlocks the Threading library when locked.
static bool sleep(long long mills, int nanos)
static int getThreadPriority(ThreadHandle *thread)
static int createThreadLocalSlot(ThreadLocalImpl *threadLocal)
Allocates a slot in the library for a new ThreadLocalImpl to store its values for each thread.
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 ...
static void exitMonitor(MonitorHandle *monitor)
Exit the acquired monitor giving up the lock that is held and allowing other threads to acquire the m...
static void setThreadPriority(ThreadHandle *thread, int priority)
static Thread::State getThreadState(ThreadHandle *thread)
static void returnMonitor(MonitorHandle *monitor, bool alreadyLocked=false)
Returns a given monitor to the Monitor pool after the Monitor is no longer needed.
static bool isThreadAlive(ThreadHandle *thread)
static void notifyWaiter(MonitorHandle *monitor)
Notify a single waiter on the given Monitor instance, if there is no thread currently waiting on the ...
A Thread is a concurrent unit of execution.
Definition Thread.h:64
#define DECAF_API
Definition Config.h:29
Definition Atomics.h:26
Definition ByteArrayAdapter.h:30
Definition AprPool.h:26
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25