1 // -*- C++ -*-
2 // Module:  Log4CPLUS
3 // File:    threads.h
4 // Created: 6/2001
5 // Author:  Tad E. Smith
6 //
7 //
8 // Copyright 2001-2010 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 //     http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
22 /** @file */
23 
24 #ifndef DCMTK_LOG4CPLUS_THREADS_HEADER_
25 #define DCMTK_LOG4CPLUS_THREADS_HEADER_
26 
27 #include "dcmtk/oflog/config.h"
28 
29 #if defined (DCMTK_LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include "dcmtk/oflog/tstring.h"
34 #include "dcmtk/oflog/helpers/pointer.h"
35 
36 
37 namespace dcmtk {
38 namespace log4cplus { namespace thread {
39 
40 
41 DCMTK_LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName();
42 DCMTK_LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2();
43 DCMTK_LOG4CPLUS_EXPORT void yield();
44 DCMTK_LOG4CPLUS_EXPORT void blockAllSignals();
45 
46 
47 #ifndef DCMTK_LOG4CPLUS_SINGLE_THREADED
48 
49 class ThreadImplBase
50     : public virtual log4cplus::helpers::SharedObject
51 {
52 protected:
53     virtual ~ThreadImplBase ();
54 };
55 
56 
57 /**
58  * There are many cross-platform C++ Threading libraries.  The goal of
59  * this class is not to replace (or match in functionality) those
60  * libraries.  The goal of this class is to provide a simple Threading
61  * class with basic functionality.
62  */
63 class DCMTK_LOG4CPLUS_EXPORT AbstractThread
64     : public virtual log4cplus::helpers::SharedObject
65 {
66 public:
67     AbstractThread();
68     bool isRunning() const;
69     virtual void start();
70     void join () const;
71     virtual void run() = 0;
72 
73 protected:
74     // Force objects to be constructed on the heap
75     virtual ~AbstractThread();
76 
77 private:
78     helpers::SharedObjectPtr<ThreadImplBase> thread;
79 
80     // Disallow copying of instances of this class.
81     AbstractThread(const AbstractThread&);
82     AbstractThread& operator=(const AbstractThread&);
83 };
84 
85 typedef helpers::SharedObjectPtr<AbstractThread> AbstractThreadPtr;
86 
87 
88 #endif // DCMTK_LOG4CPLUS_SINGLE_THREADED
89 
90 
91 } } // namespace log4cplus { namespace thread {
92 } // end namespace dcmtk
93 
94 
95 #endif // DCMTK_LOG4CPLUS_THREADS_HEADER_
96 
97