log4cplus  2.1.0
syncprims-impl.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without modifica-
5 // tion, are permitted provided that the following conditions are met:
6 //
7 // 1. Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
15 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17 // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
19 // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
20 // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 #ifndef LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H
26 #define LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H
27 
28 #include <log4cplus/config.hxx>
29 
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
31 #pragma once
32 #endif
33 
34 #if ! defined (INSIDE_LOG4CPLUS)
35 # error "This header must not be be used outside log4cplus' implementation files."
36 #endif
37 
38 #include <stdexcept>
40 #include <mutex>
41 #include <thread>
42 #include <condition_variable>
43 
44 
45 namespace log4cplus { namespace thread { namespace impl {
46 
47 
49  syncprims_throw_exception (char const * const msg,
50  char const * const file, int line);
51 
52 
54  : public SharedMutexImplBase
55 {
56 public:
59 
60  void rdlock () const;
61  void wrlock () const;
62  void rdunlock () const;
63  void wrunlock () const;
64 
65 private:
66  Mutex m1;
67  Mutex m2;
68  Mutex m3;
69  Semaphore w;
70  mutable unsigned writer_count;
71  Semaphore r;
72  mutable unsigned reader_count;
73 
74  SharedMutex (SharedMutex const &);
75  SharedMutex & operator = (SharedMutex const &);
76 };
77 
78 
79 } } } // namespace log4cplus { namespace thread { namespace impl {
80 
81 
82 // Include the appropriate implementations of the classes declared
83 // above.
84 
86 
87 #undef LOG4CPLUS_THROW_RTE
88 
89 
90 #endif // LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H
#define LOG4CPLUS_ATTRIBUTE_NORETURN
Definition: config.hxx:133
LOG4CPLUS_EXPORT void LOG4CPLUS_ATTRIBUTE_NORETURN syncprims_throw_exception(char const *const msg, char const *const file, int line)
This file contains implementations of synchronization primitives using the C++11 API.
#define LOG4CPLUS_EXPORT
Definition: win32.h:141