poly_lockable.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/thread for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_THREAD_POLY_LOCKABLE_HPP
  11. #define BOOST_THREAD_POLY_LOCKABLE_HPP
  12. #include <boost/thread/detail/delete.hpp>
  13. #include <boost/chrono/chrono.hpp>
  14. namespace boost
  15. {
  16. //[basic_poly_lockable
  17. class basic_poly_lockable
  18. {
  19. public:
  20. virtual ~basic_poly_lockable() = 0;
  21. virtual void lock() = 0;
  22. virtual void unlock() = 0;
  23. };
  24. //]
  25. // A proper name for basic_poly_lockable, consistent with naming scheme of other polymorphic wrappers
  26. typedef basic_poly_lockable poly_basic_lockable;
  27. //[poly_lockable
  28. class poly_lockable : public basic_poly_lockable
  29. {
  30. public:
  31. virtual ~poly_lockable() = 0;
  32. virtual bool try_lock() = 0;
  33. };
  34. //]
  35. //[timed_poly_lockable
  36. class timed_poly_lockable: public poly_lockable
  37. {
  38. public:
  39. virtual ~timed_poly_lockable()=0;
  40. virtual bool try_lock_until(chrono::system_clock::time_point const & abs_time)=0;
  41. virtual bool try_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
  42. template <typename Clock, typename Duration>
  43. bool try_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
  44. {
  45. return try_lock_until(chrono::time_point_cast<Clock::time_point>(abs_time));
  46. }
  47. virtual bool try_lock_for(chrono::nanoseconds const & relative_time)=0;
  48. template <typename Rep, typename Period>
  49. bool try_lock_for(chrono::duration<Rep, Period> const & rel_time)
  50. {
  51. return try_lock_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
  52. }
  53. };
  54. //]
  55. // A proper name for timed_poly_lockable, consistent with naming scheme of other polymorphic wrappers
  56. typedef timed_poly_lockable poly_timed_lockable;
  57. }
  58. #endif