OFFIS DCMTK  Version 3.6.0
threads.h
Go to the documentation of this file.
1 // Module: Log4CPLUS
2 // File: threads.h
3 // Created: 6/2001
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2001-2010 Tad E. Smith
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 
23 #ifndef _LOG4CPLUS_THREADS_HEADER_
24 #define _LOG4CPLUS_THREADS_HEADER_
25 
26 #include "dcmtk/oflog/config.h"
27 #include "dcmtk/oflog/tstring.h"
29 
30 
31 namespace log4cplus { namespace thread {
32 
36 class Guard
37 {
38 public:
40  Guard(LOG4CPLUS_MUTEX_PTR_DECLARE mutex)
41  : _mutex (mutex)
42  {
43  LOG4CPLUS_MUTEX_LOCK( _mutex );
44  }
45 
48  {
49  LOG4CPLUS_MUTEX_UNLOCK( _mutex );
50  }
51 
52 private:
53  LOG4CPLUS_MUTEX_PTR_DECLARE _mutex;
54 
55  // disable copy
56  Guard(const Guard&);
57  Guard& operator=(const Guard&);
58 };
59 
60 
61 #ifndef LOG4CPLUS_SINGLE_THREADED
62 
63 LOG4CPLUS_EXPORT void blockAllSignals();
64 LOG4CPLUS_EXPORT tstring getCurrentThreadName();
65 
66 
67 struct ThreadStart;
68 
69 
76 class LOG4CPLUS_EXPORT AbstractThread
77  : public virtual log4cplus::helpers::SharedObject
78 {
79 public:
81  bool isRunning() const { return running; }
82  LOG4CPLUS_THREAD_KEY_TYPE getThreadId() const;
83  LOG4CPLUS_THREAD_HANDLE_TYPE getThreadHandle () const;
84  virtual void start();
85  void join () const;
86 
87 protected:
88  // Force objects to be constructed on the heap
89  virtual ~AbstractThread();
90  virtual void run() = 0;
91 
92 private:
93  bool running;
94 
95  // Friends.
96  friend struct ThreadStart;
97 
98 # ifdef LOG4CPLUS_USE_PTHREADS
99  pthread_t handle;
100 
101 # elif defined(LOG4CPLUS_USE_WIN32_THREADS)
102  HANDLE handle;
103  unsigned thread_id;
104 
105 # endif
106 
107  // Disallow copying of instances of this class.
109  AbstractThread& operator=(const AbstractThread&);
110 };
111 
113 
114 
115 #endif // LOG4CPLUS_SINGLE_THREADED
116 
117 
118 } } // namespace log4cplus { namespace thread {
119 
120 
121 #endif // _LOG4CPLUS_THREADS_HEADER_
122 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2