log4cplus  2.1.0
threads.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: threads.h
4 // Created: 6/2001
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2001-2017 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 
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 <memory>
34 #include <thread>
35 
36 #include <log4cplus/tstring.h>
38 
39 
40 namespace log4cplus { namespace thread {
41 
42 
49 
55 {
56 public:
59 
60 private:
61  struct SignalsBlockerImpl;
62  std::unique_ptr<SignalsBlockerImpl> impl;
63 };
64 
65 
66 #ifndef LOG4CPLUS_SINGLE_THREADED
67 
68 
76  : public virtual log4cplus::helpers::SharedObject
77 {
78 public:
80  // Disallow copying of instances of this class.
81  AbstractThread(const AbstractThread&) = delete;
83 
84  bool isRunning() const;
85  virtual void start();
86  void join () const;
87  virtual void run() = 0;
88 
89 protected:
90  // Force objects to be constructed on the heap
91  virtual ~AbstractThread();
92 
93 private:
94  enum Flags
95  {
96  fRUNNING = 1,
97  fJOINED = 2
98  };
99 
100  std::unique_ptr<std::thread> thread;
101  mutable std::atomic<int> flags;
102 };
103 
105 
106 
107 #endif // LOG4CPLUS_SINGLE_THREADED
108 
109 
110 } } // namespace log4cplus { namespace thread {
111 
112 
113 #endif // LOG4CPLUS_THREADS_HEADER_
There are many cross-platform C++ Threading libraries.
Definition: threads.h:77
AbstractThread & operator=(const AbstractThread &)=delete
AbstractThread(const AbstractThread &)=delete
This class blocks all POSIX signals when created and unblocks them when destroyed.
Definition: threads.h:55
helpers::SharedObjectPtr< AbstractThread > AbstractThreadPtr
Definition: threads.h:104
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName()
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2()
LOG4CPLUS_EXPORT void blockAllSignals()
LOG4CPLUS_EXPORT void yield()
LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring &name)
LOG4CPLUS_EXPORT void setCurrentThreadName(const log4cplus::tstring &name)
std::basic_string< tchar > tstring
Definition: tstring.h:39
#define LOG4CPLUS_EXPORT
Definition: win32.h:141