syncprims-pub-impl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // -*- C++ -*-
  2. // Copyright (C) 2010-2015, 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_PUB_IMPL_H
  25. #define LOG4CPLUS_THREAD_SYNCPRIMS_PUB_IMPL_H
  26. #include <log4cplus/config.hxx>
  27. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  28. #pragma once
  29. #endif
  30. #if (defined (LOG4CPLUS_INLINES_ARE_EXPORTED) \
  31. && defined (LOG4CPLUS_BUILD_DLL)) \
  32. || defined (LOG4CPLUS_ENABLE_SYNCPRIMS_PUB_IMPL)
  33. #include <log4cplus/thread/syncprims.h>
  34. #if defined (LOG4CPLUS_SINGLE_THREADED)
  35. # define LOG4CPLUS_THREADED(x)
  36. # define LOG4CPLUS_THREADED2(x, y) (y)
  37. #else
  38. # include <log4cplus/thread/impl/syncprims-impl.h>
  39. # define LOG4CPLUS_THREADED(x) (x)
  40. # define LOG4CPLUS_THREADED2(x, y) (x)
  41. #endif
  42. namespace log4cplus { namespace thread {
  43. //
  44. //
  45. //
  46. LOG4CPLUS_INLINE_EXPORT
  47. MutexImplBase::~MutexImplBase ()
  48. { }
  49. //
  50. //
  51. //
  52. LOG4CPLUS_INLINE_EXPORT
  53. Mutex::Mutex (Mutex::Type LOG4CPLUS_THREADED (t))
  54. : mtx (LOG4CPLUS_THREADED2 (new impl::Mutex (t),
  55. static_cast<MutexImplBase *>(0)))
  56. { }
  57. LOG4CPLUS_INLINE_EXPORT
  58. Mutex::~Mutex ()
  59. {
  60. LOG4CPLUS_THREADED (delete static_cast<impl::Mutex *>(mtx));
  61. }
  62. LOG4CPLUS_INLINE_EXPORT
  63. void
  64. Mutex::lock () const
  65. {
  66. LOG4CPLUS_THREADED (static_cast<impl::Mutex *>(mtx)->lock ());
  67. }
  68. LOG4CPLUS_INLINE_EXPORT
  69. void
  70. Mutex::unlock () const
  71. {
  72. LOG4CPLUS_THREADED (static_cast<impl::Mutex *>(mtx)->unlock ());
  73. }
  74. //
  75. //
  76. //
  77. LOG4CPLUS_INLINE_EXPORT
  78. SemaphoreImplBase::~SemaphoreImplBase ()
  79. { }
  80. //
  81. //
  82. //
  83. LOG4CPLUS_INLINE_EXPORT
  84. Semaphore::Semaphore (unsigned LOG4CPLUS_THREADED (max),
  85. unsigned LOG4CPLUS_THREADED (initial))
  86. : sem (LOG4CPLUS_THREADED2 (new impl::Semaphore (max, initial),
  87. static_cast<SemaphoreImplBase *>(0)))
  88. { }
  89. LOG4CPLUS_INLINE_EXPORT
  90. Semaphore::~Semaphore ()
  91. {
  92. LOG4CPLUS_THREADED (delete static_cast<impl::Semaphore *>(sem));
  93. }
  94. LOG4CPLUS_INLINE_EXPORT
  95. void
  96. Semaphore::lock () const
  97. {
  98. LOG4CPLUS_THREADED (static_cast<impl::Semaphore *>(sem)->lock ());
  99. }
  100. LOG4CPLUS_INLINE_EXPORT
  101. void
  102. Semaphore::unlock () const
  103. {
  104. LOG4CPLUS_THREADED (static_cast<impl::Semaphore *>(sem)->unlock ());
  105. }
  106. //
  107. //
  108. //
  109. LOG4CPLUS_INLINE_EXPORT
  110. FairMutexImplBase::~FairMutexImplBase ()
  111. { }
  112. //
  113. //
  114. //
  115. LOG4CPLUS_INLINE_EXPORT
  116. FairMutex::FairMutex ()
  117. : mtx (LOG4CPLUS_THREADED2 (new impl::FairMutex,
  118. static_cast<FairMutexImplBase *>(0)))
  119. { }
  120. LOG4CPLUS_INLINE_EXPORT
  121. FairMutex::~FairMutex ()
  122. {
  123. LOG4CPLUS_THREADED (delete static_cast<impl::FairMutex *>(mtx));
  124. }
  125. LOG4CPLUS_INLINE_EXPORT
  126. void
  127. FairMutex::lock () const
  128. {
  129. LOG4CPLUS_THREADED (static_cast<impl::FairMutex *>(mtx)->lock ());
  130. }
  131. LOG4CPLUS_INLINE_EXPORT
  132. void
  133. FairMutex::unlock () const
  134. {
  135. LOG4CPLUS_THREADED (static_cast<impl::FairMutex *>(mtx)->unlock ());
  136. }
  137. //
  138. //
  139. //
  140. LOG4CPLUS_INLINE_EXPORT
  141. ManualResetEventImplBase::~ManualResetEventImplBase ()
  142. { }
  143. //
  144. //
  145. //
  146. LOG4CPLUS_INLINE_EXPORT
  147. ManualResetEvent::ManualResetEvent (bool LOG4CPLUS_THREADED (sig))
  148. : ev (LOG4CPLUS_THREADED2 (new impl::ManualResetEvent (sig),
  149. static_cast<ManualResetEventImplBase *>(0)))
  150. { }
  151. LOG4CPLUS_INLINE_EXPORT
  152. ManualResetEvent::~ManualResetEvent ()
  153. {
  154. LOG4CPLUS_THREADED (delete static_cast<impl::ManualResetEvent *>(ev));
  155. }
  156. LOG4CPLUS_INLINE_EXPORT
  157. void
  158. ManualResetEvent::signal () const
  159. {
  160. LOG4CPLUS_THREADED (static_cast<impl::ManualResetEvent *>(ev)->signal ());
  161. }
  162. LOG4CPLUS_INLINE_EXPORT
  163. void
  164. ManualResetEvent::wait () const
  165. {
  166. LOG4CPLUS_THREADED (static_cast<impl::ManualResetEvent *>(ev)->wait ());
  167. }
  168. LOG4CPLUS_INLINE_EXPORT
  169. bool
  170. ManualResetEvent::timed_wait (unsigned long LOG4CPLUS_THREADED (msec)) const
  171. {
  172. #if defined (LOG4CPLUS_SINGLE_THREADED)
  173. return true;
  174. #else
  175. return static_cast<impl::ManualResetEvent *>(ev)->timed_wait (msec);
  176. #endif
  177. }
  178. LOG4CPLUS_INLINE_EXPORT
  179. void
  180. ManualResetEvent::reset () const
  181. {
  182. LOG4CPLUS_THREADED (static_cast<impl::ManualResetEvent *>(ev)->reset ());
  183. }
  184. //
  185. //
  186. //
  187. LOG4CPLUS_INLINE_EXPORT
  188. SharedMutexImplBase::~SharedMutexImplBase ()
  189. { }
  190. //
  191. //
  192. //
  193. LOG4CPLUS_INLINE_EXPORT
  194. SharedMutex::SharedMutex ()
  195. : sm (LOG4CPLUS_THREADED2 (new impl::SharedMutex,
  196. static_cast<SharedMutexImplBase *>(0)))
  197. { }
  198. LOG4CPLUS_INLINE_EXPORT
  199. SharedMutex::~SharedMutex ()
  200. { }
  201. LOG4CPLUS_INLINE_EXPORT
  202. void
  203. SharedMutex::rdlock () const
  204. {
  205. LOG4CPLUS_THREADED (static_cast<impl::SharedMutex *>(sm)->rdlock ());
  206. }
  207. LOG4CPLUS_INLINE_EXPORT
  208. void
  209. SharedMutex::wrlock () const
  210. {
  211. LOG4CPLUS_THREADED (static_cast<impl::SharedMutex *>(sm)->wrlock ());
  212. }
  213. LOG4CPLUS_INLINE_EXPORT
  214. void
  215. SharedMutex::rdunlock () const
  216. {
  217. LOG4CPLUS_THREADED (static_cast<impl::SharedMutex *>(sm)->rdunlock ());
  218. }
  219. LOG4CPLUS_INLINE_EXPORT
  220. void
  221. SharedMutex::wrunlock () const
  222. {
  223. LOG4CPLUS_THREADED (static_cast<impl::SharedMutex *>(sm)->wrunlock ());
  224. }
  225. } } // namespace log4cplus { namespace thread {
  226. #endif // LOG4CPLUS_ENABLE_SYNCPRIMS_PUB_IMPL
  227. #endif // LOG4CPLUS_THREAD_SYNCPRIMS_PUB_IMPL_H