/Src/Dependencies/Boost/boost/signals2/detail/lwm_pthreads.hpp

http://hadesmem.googlecode.com/ · C++ Header · 78 lines · 45 code · 21 blank · 12 comment · 3 complexity · fce4e86380d795a40c741cecf6db0152 MD5 · raw file

  1. //
  2. // boost/signals2/detail/lwm_pthreads.hpp
  3. //
  4. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  5. // Copyright (c) 2008 Frank Mori Hess
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP
  12. #define BOOST_SIGNALS2_LWM_PTHREADS_HPP
  13. // MS compatible compilers support #pragma once
  14. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  15. # pragma once
  16. #endif
  17. #include <pthread.h>
  18. namespace boost
  19. {
  20. namespace signals2
  21. {
  22. class mutex
  23. {
  24. private:
  25. pthread_mutex_t m_;
  26. mutex(mutex const &);
  27. mutex & operator=(mutex const &);
  28. public:
  29. mutex()
  30. {
  31. // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
  32. #if defined(__hpux) && defined(_DECTHREADS_)
  33. pthread_mutex_init(&m_, pthread_mutexattr_default);
  34. #else
  35. pthread_mutex_init(&m_, 0);
  36. #endif
  37. }
  38. ~mutex()
  39. {
  40. pthread_mutex_destroy(&m_);
  41. }
  42. void lock()
  43. {
  44. pthread_mutex_lock(&m_);
  45. }
  46. bool try_lock()
  47. {
  48. return pthread_mutex_trylock(&m_) == 0;
  49. }
  50. void unlock()
  51. {
  52. pthread_mutex_unlock(&m_);
  53. }
  54. };
  55. } // namespace signals2
  56. } // namespace boost
  57. #endif // #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP