syncprims-impl.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifndef LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H
  25. #define LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H
  26. #include <log4cplus/config.hxx>
  27. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  28. #pragma once
  29. #endif
  30. #if ! defined (INSIDE_LOG4CPLUS)
  31. # error "This header must not be be used outside log4cplus' implementation files."
  32. #endif
  33. #include <stdexcept>
  34. #include <log4cplus/thread/syncprims.h>
  35. #include <mutex>
  36. #include <thread>
  37. #include <condition_variable>
  38. namespace log4cplus { namespace thread { namespace impl {
  39. LOG4CPLUS_EXPORT void LOG4CPLUS_ATTRIBUTE_NORETURN
  40. syncprims_throw_exception (char const * const msg,
  41. char const * const file, int line);
  42. class SharedMutex
  43. : public SharedMutexImplBase
  44. {
  45. public:
  46. SharedMutex ();
  47. ~SharedMutex ();
  48. void rdlock () const;
  49. void wrlock () const;
  50. void rdunlock () const;
  51. void wrunlock () const;
  52. private:
  53. Mutex m1;
  54. Mutex m2;
  55. Mutex m3;
  56. Semaphore w;
  57. mutable unsigned writer_count;
  58. Semaphore r;
  59. mutable unsigned reader_count;
  60. SharedMutex (SharedMutex const &);
  61. SharedMutex & operator = (SharedMutex const &);
  62. };
  63. } } } // namespace log4cplus { namespace thread { namespace impl {
  64. // Include the appropriate implementations of the classes declared
  65. // above.
  66. #include <log4cplus/thread/impl/syncprims-cxx11.h>
  67. #undef LOG4CPLUS_THROW_RTE
  68. #endif // LOG4CPLUS_THREAD_SYNCPRIMS_IMPL_H