xtd 0.2.0
lock_guard.h
Go to the documentation of this file.
1 #pragma once
5 #include "../object.h"
6 #include "../using.h"
7 #include "monitor.h"
8 
10 namespace xtd {
12  namespace threading {
30  class core_export_ lock_guard final : public object {
31  public:
33 
38  template<typename object_t>
39  explicit lock_guard(const object_t& obj) : obj_(monitor::get_ptr(obj)) {monitor::enter_ptr(obj_);}
41 
43  ~lock_guard();
45 
47 
56  void pulse();
57 
64  void pulse_all();
65 
80  bool wait(int32 milliseconds_timeout);
81 
95  bool wait(const time_span& timeout);
96 
109  bool wait();
111 
112  private:
113  lock_guard() = delete;
114  monitor::object_ptr obj_;
115  };
116  }
117 }
118 
179 #define lock_guard_(object)\
180  using_ (xtd::threading::lock_guard __xtd_lock_guard__(object))
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition: lock_guard.h:30
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
lock_guard(const object_t &obj)
Create a xtd::threaing::lock_guard object and acquires an exclusive lock on the specified obj...
Definition: lock_guard.h:39
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents a time interval.
Definition: time_span.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains a constant used to specify an infinite amount of time. This class cannot be inherited...
Definition: timeout.h:31
Contains xtd::threading::monitor class.
Provides a mechanism that synchronizes access to objects.
Definition: monitor.h:127