log4cplus
2.0.0
|
00001 // -*- C++ -*- 00002 // Copyright (C) 2009-2015, Vaclav Haisman. All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without modifica- 00005 // tion, are permitted provided that the following conditions are met: 00006 // 00007 // 1. Redistributions of source code must retain the above copyright notice, 00008 // this list of conditions and the following disclaimer. 00009 // 00010 // 2. Redistributions in binary form must reproduce the above copyright notice, 00011 // this list of conditions and the following disclaimer in the documentation 00012 // and/or other materials provided with the distribution. 00013 // 00014 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00015 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00016 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00017 // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00018 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 00019 // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00020 // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00021 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 00025 #ifndef LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H 00026 #define LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H 00027 00028 #include <log4cplus/config.hxx> 00029 00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00031 #pragma once 00032 #endif 00033 00034 #if ! defined (INSIDE_LOG4CPLUS) 00035 # error "This header must not be be used outside log4cplus' implementation files." 00036 #endif 00037 00038 #include <stdexcept> 00039 #include <log4cplus/thread/syncprims.h> 00040 #include <mutex> 00041 #include <thread> 00042 #include <condition_variable> 00043 00044 00045 namespace log4cplus { namespace thread { namespace impl { 00046 00047 00048 LOG4CPLUS_EXPORT void LOG4CPLUS_ATTRIBUTE_NORETURN 00049 syncprims_throw_exception (char const * const msg, 00050 char const * const file, int line); 00051 00052 00053 class SharedMutex 00054 : public SharedMutexImplBase 00055 { 00056 public: 00057 SharedMutex (); 00058 ~SharedMutex (); 00059 00060 void rdlock () const; 00061 void wrlock () const; 00062 void rdunlock () const; 00063 void wrunlock () const; 00064 00065 private: 00066 Mutex m1; 00067 Mutex m2; 00068 Mutex m3; 00069 Semaphore w; 00070 mutable unsigned writer_count; 00071 Semaphore r; 00072 mutable unsigned reader_count; 00073 00074 SharedMutex (SharedMutex const &); 00075 SharedMutex & operator = (SharedMutex const &); 00076 }; 00077 00078 00079 } } } // namespace log4cplus { namespace thread { namespace impl { 00080 00081 00082 // Include the appropriate implementations of the classes declared 00083 // above. 00084 00085 #include <log4cplus/thread/impl/syncprims-cxx11.h> 00086 00087 #undef LOG4CPLUS_THROW_RTE 00088 00089 00090 #endif // LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H