uvcc
libuv C++ bindings
threading.hpp
1 
2 #ifndef UVCC_THREAD__HPP
3 #define UVCC_THREAD__HPP
4 
5 #include <uv.h>
6 
7 #include <stdexcept> // runtime_error
8 
9 
10 namespace uv
11 {
12 
13 
14 class mutex
15 {
16 public: /*types*/
17  using uv_t = ::uv_mutex_t;
18 
19 private: /*data*/
20  uv_t uv_mutex;
21 
22 public: /*constructors*/
23  ~mutex() noexcept { ::uv_mutex_destroy(&uv_mutex); }
24  mutex() { if (::uv_mutex_init(&uv_mutex) < 0) throw std::runtime_error(__PRETTY_FUNCTION__); }
25 
26  mutex(const mutex&) = delete;
27  mutex& operator =(const mutex&) = delete;
28 
29  mutex(mutex&&) = delete;
30  mutex& operator =(mutex&&) = delete;
31 
32 public: /*interface*/
33  void lock() noexcept { ::uv_mutex_lock(&uv_mutex); }
34  bool try_lock() noexcept { return ::uv_mutex_trylock(&uv_mutex) == 0; }
35  void unlock() noexcept { ::uv_mutex_unlock(&uv_mutex); }
36 
37 public: /*conversion operators*/
38  explicit operator const uv_t*() const noexcept { return &uv_mutex; }
39  explicit operator uv_t*() noexcept { return &uv_mutex; }
40 };
41 
42 
43 }
44 
45 
46 #endif
Namespace for all uvcc definitions.
Definition: buffer.hpp:17