From 77a6c3512a44dfe6540dde71946e6484fe4f173f Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期一, 10 五月 2021 16:05:28 +0800 Subject: [PATCH] test lock code. --- src/robust.h | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/robust.h b/src/robust.h index d2d94e9..8657122 100644 --- a/src/robust.h +++ b/src/robust.h @@ -86,6 +86,8 @@ class NullMutex { public: + template <class... T> + explicit NullMutex(T &&...t) {} // easy test. bool try_lock() { return true; } void lock() {} void unlock() {} @@ -113,8 +115,10 @@ mkdir(dir.c_str(), 0777); return dir + "/fm_" + std::to_string(id); } - static int Open(id_t id) { return open(GetPath(id).c_str(), O_CREAT | O_RDWR, 0666); } + static int Open(id_t id) { return open(GetPath(id).c_str(), O_CREAT | O_RDONLY, 0666); } static int Close(int fd) { return close(fd); } + void FLock(); + void FUnlock(); id_t id_; int fd_; std::mutex mtx_; @@ -132,17 +136,11 @@ { public: SemMutex(key_t key) : - key_(key), sem_id_(semget(key, 1, 0666 | IPC_CREAT)) + key_(key), sem_id_(semget(key, 1, 0666)) { if (sem_id_ == -1) { throw "error create semaphore."; } - union semun init_val; - init_val.val = 1; - semctl(sem_id_, 0, SETVAL, init_val); } - ~SemMutex() - { - // semctl(sem_id_, 0, IPC_RMID, semun{}); - } + ~SemMutex() {} bool try_lock() { -- Gitblit v1.8.0