@@ -33,7 +33,7 @@ class semaphore {
3333
3434 bool open (char const *name, std::uint32_t count) noexcept {
3535 close ();
36- if (!shm_.acquire (name, 0 )) {
36+ if (!shm_.acquire (name, 1 )) {
3737 ipc::error (" [open_semaphore] fail shm.acquire: %s\n " , name);
3838 return false ;
3939 }
@@ -61,27 +61,22 @@ class semaphore {
6161
6262 bool wait (std::uint64_t tm) noexcept {
6363 if (!valid ()) return false ;
64- switch (tm) {
65- case 0 :
66- return true ;
67- case invalid_value:
64+ if (tm == invalid_value) {
6865 if (::sem_wait (h_) != 0 ) {
6966 ipc::error (" fail sem_wait[%d]: %s\n " , errno);
7067 return false ;
7168 }
72- return true ;
73- default : {
74- auto ts = detail::make_timespec (tm);
75- if (::sem_timedwait (h_, &ts) != 0 ) {
76- if (errno != ETIMEDOUT) {
77- ipc::error (" fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n " ,
78- errno, tm, ts.tv_sec , ts.tv_nsec );
79- }
80- return false ;
69+ } else {
70+ auto ts = detail::make_timespec (tm);
71+ if (::sem_timedwait (h_, &ts) != 0 ) {
72+ if (errno != ETIMEDOUT) {
73+ ipc::error (" fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n " ,
74+ errno, tm, ts.tv_sec , ts.tv_nsec );
8175 }
76+ return false ;
8277 }
83- return true ;
8478 }
79+ return true ;
8580 }
8681
8782 bool post (std::uint32_t count) noexcept {
0 commit comments