You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
5.8 KiB

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