activemq-cpp-3.8.2
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 
25 namespace decaf {
26 namespace internal {
27 namespace util {
28 namespace concurrent {
29 
30  using decaf::lang::Thread;
31 
32  class ThreadLocalImpl;
33  struct ThreadHandle;
34  struct MonitorHandle;
35 
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 
249  static Thread::State getThreadState(ThreadHandle* thread);
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 
275  static Thread* getCurrentThread();
276 
280  static ThreadHandle* getCurrentThreadHandle();
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 
337  private:
338 
339  static ThreadHandle* attachToCurrentThread();
340 
341  static void monitorEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
342  static bool monitorTryEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
343  static void monitorExitUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
344  };
345 
346 }}}}
347 
348 #endif /* _DECAF_INTERNAL_UTIL_CONCURRENT_THREADING_H_ */
A Thread is a concurrent unit of execution.
Definition: Thread.h:64
#define DECAF_API
Definition: Config.h:29
State
Represents the various states that the Thread can be in during its lifetime.
Definition: Thread.h:84
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25