1 // -*- C++ -*-
2 // Module:  Log4CPLUS
3 // File:    threads.h
4 // Created: 6/2001
5 // Author:  Tad E. Smith
6 //
7 //
8 // Copyright 2001-2013 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 LOG4CPLUS_THREADS_HEADER_
25 #define LOG4CPLUS_THREADS_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/tstring.h>
34 #include <log4cplus/helpers/pointer.h>
35 
36 
37 namespace log4cplus { namespace thread {
38 
39 
40 LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName();
41 LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2();
42 LOG4CPLUS_EXPORT void yield();
43 LOG4CPLUS_EXPORT void blockAllSignals();
44 
45 
46 #ifndef LOG4CPLUS_SINGLE_THREADED
47 
48 class ThreadImplBase
49     : public virtual log4cplus::helpers::SharedObject
50 {
51 protected:
52     virtual ~ThreadImplBase ();
53 };
54 
55 
56 /**
57  * There are many cross-platform C++ Threading libraries.  The goal of
58  * this class is not to replace (or match in functionality) those
59  * libraries.  The goal of this class is to provide a simple Threading
60  * class with basic functionality.
61  */
62 class LOG4CPLUS_EXPORT AbstractThread
63     : public virtual log4cplus::helpers::SharedObject
64 {
65 public:
66     AbstractThread();
67     bool isRunning() const;
68     virtual void start();
69     void join () const;
70     virtual void run() = 0;
71 
72 protected:
73     // Force objects to be constructed on the heap
74     virtual ~AbstractThread();
75 
76 private:
77     helpers::SharedObjectPtr<ThreadImplBase> thread;
78 
79     // Disallow copying of instances of this class.
80     AbstractThread(const AbstractThread&);
81     AbstractThread& operator=(const AbstractThread&);
82 };
83 
84 typedef helpers::SharedObjectPtr<AbstractThread> AbstractThreadPtr;
85 
86 
87 #endif // LOG4CPLUS_SINGLE_THREADED
88 
89 
90 } } // namespace log4cplus { namespace thread {
91 
92 
93 #endif // LOG4CPLUS_THREADS_HEADER_
94 
95