38 # include <dsn/service_api_c.h> 41 namespace dsn {
namespace service {
51 ~
zlock() { dsn_exlock_destroy(_h); }
53 void lock() { dsn_exlock_lock(_h); }
54 bool try_lock() {
return dsn_exlock_try_lock(_h); }
55 void unlock() { dsn_exlock_unlock(_h); }
77 void lock_read() { dsn_rwlock_nr_lock_read(_h); }
78 void unlock_read() { dsn_rwlock_nr_unlock_read(_h); }
79 bool try_lock_read() {
return dsn_rwlock_nr_try_lock_read(_h); }
81 void lock_write() { dsn_rwlock_nr_lock_write(_h); }
82 void unlock_write() { dsn_rwlock_nr_unlock_write(_h); }
83 bool try_lock_write() {
return dsn_rwlock_nr_try_lock_write(_h); }
106 virtual void signal(
int count = 1) { dsn_semaphore_signal(_h, count); }
108 virtual bool wait(
int timeout_milliseconds = TIME_MS_MAX)
110 if (static_cast<unsigned int>(timeout_milliseconds) == TIME_MS_MAX)
112 dsn_semaphore_wait(_h);
117 return dsn_semaphore_wait_timeout(_h, timeout_milliseconds);
133 zevent(
bool manualReset,
bool initState =
false);
139 bool wait(
int timeout_milliseconds = TIME_MS_MAX);
143 std::atomic<bool> _signaled;
DSN_API dsn_handle_t dsn_exlock_create(bool recursive)
create a recursive? or not exlusive lock
DSN_API dsn_handle_t dsn_semaphore_create(int initial_count)
create a semaphore with initial count equals to inital_count