Apache log4cxx  Version 0.11.0
thread.h
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 _LOG4CXX_HELPERS_THREAD_H
19 #define _LOG4CXX_HELPERS_THREAD_H
20 
21 #include <log4cxx/log4cxx.h>
22 #include <log4cxx/helpers/pool.h>
23 
24 #if !defined(LOG4CXX_THREAD_FUNC)
25  #if defined(_WIN32)
26  #if defined(__MINGW32__)
27  #define LOG4CXX_THREAD_FUNC
28  #else
29  #define LOG4CXX_THREAD_FUNC __stdcall
30  #endif
31  #else
32  #define LOG4CXX_THREAD_FUNC
33  #endif
34 #endif
35 
36 extern "C" {
37  typedef struct apr_thread_t apr_thread_t;
38  typedef struct apr_thread_cond_t apr_thread_cond_t;
39  typedef struct apr_thread_mutex_t apr_thread_mutex_t;
40 }
41 
42 
43 namespace log4cxx
44 {
45 namespace helpers
46 {
47 class Pool;
48 class ThreadLocal;
49 
50 typedef void* (LOG4CXX_THREAD_FUNC* Runnable)(apr_thread_t* thread, void* data);
51 namespace ThreadLaunch
52 {
53 extern "C" void* LOG4CXX_THREAD_FUNC launcher(apr_thread_t* thread, void* data);
54 }
55 
59 class LOG4CXX_EXPORT Thread
60 {
61  public:
65  Thread();
69  ~Thread();
70 
74  void run(Runnable start, void* data);
75  void join();
76 
77  inline bool isActive()
78  {
79  return thread != 0;
80  }
81 
88  static void sleep(int millis);
92  static void currentThreadInterrupt();
96  void interrupt();
101  static bool interrupted();
102 
103  bool isAlive();
104  bool isCurrentThread() const;
105  void ending();
106 
107 
108  private:
109  Pool p;
110  apr_thread_t* thread;
111  volatile unsigned int alive;
112  volatile unsigned int interruptedStatus;
113  apr_thread_mutex_t* interruptedMutex;
114  apr_thread_cond_t* interruptedCondition;
115  Thread(const Thread&);
116  Thread& operator=(const Thread&);
117  friend void* LOG4CXX_THREAD_FUNC ThreadLaunch::launcher(apr_thread_t* thread, void* data);
118 };
119 } // namespace helpers
120 } // namespace log4cxx
121 
122 #endif //_LOG4CXX_HELPERS_THREAD_H
This class implements an approximation of java.util.Thread.
Definition: thread.h:59
Definition: pool.h:32
Definition: appender.h:33