log4cplus  2.0.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 
47 LOG4CPLUS_EXPORT void yield();
49 
50 
51 #ifndef LOG4CPLUS_SINGLE_THREADED
52 
53 
61  : public virtual log4cplus::helpers::SharedObject
62 {
63 public:
65  // Disallow copying of instances of this class.
66  AbstractThread(const AbstractThread&) = delete;
67  AbstractThread& operator=(const AbstractThread&) = delete;
68 
69  bool isRunning() const;
70  virtual void start();
71  void join () const;
72  virtual void run() = 0;
73 
74 protected:
75  // Force objects to be constructed on the heap
76  virtual ~AbstractThread();
77 
78 private:
79  enum Flags
80  {
81  fRUNNING = 1,
82  fJOINED = 2
83  };
84 
85  std::unique_ptr<std::thread> thread;
86  mutable std::atomic<int> flags;
87 };
88 
90 
91 
92 #endif // LOG4CPLUS_SINGLE_THREADED
93 
94 
95 } } // namespace log4cplus { namespace thread {
96 
97 
98 #endif // LOG4CPLUS_THREADS_HEADER_
LOG4CPLUS_EXPORT void setCurrentThreadName(const log4cplus::tstring &name)
There are many cross-platform C++ Threading libraries.
Definition: threads.h:60
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
LOG4CPLUS_EXPORT void blockAllSignals()
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName()
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2()
helpers::SharedObjectPtr< AbstractThread > AbstractThreadPtr
Definition: threads.h:89
std::basic_string< tchar > tstring
Definition: tstring.h:39
LOG4CPLUS_EXPORT void yield()
void join(tstring &result, Iterator start, Iterator last, tstring const &sep)
Join a list of items into a string.
Definition: stringhelper.h:250
LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring &name)