@@ -33,7 +33,7 @@ class semaphore {
33
33
34
34
bool open (char const *name, std::uint32_t count) noexcept {
35
35
close ();
36
- if (!shm_.acquire (name, 0 )) {
36
+ if (!shm_.acquire (name, 1 )) {
37
37
ipc::error (" [open_semaphore] fail shm.acquire: %s\n " , name);
38
38
return false ;
39
39
}
@@ -61,27 +61,22 @@ class semaphore {
61
61
62
62
bool wait (std::uint64_t tm) noexcept {
63
63
if (!valid ()) return false ;
64
- switch (tm) {
65
- case 0 :
66
- return true ;
67
- case invalid_value:
64
+ if (tm == invalid_value) {
68
65
if (::sem_wait (h_) != 0 ) {
69
66
ipc::error (" fail sem_wait[%d]: %s\n " , errno);
70
67
return false ;
71
68
}
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 );
81
75
}
76
+ return false ;
82
77
}
83
- return true ;
84
78
}
79
+ return true ;
85
80
}
86
81
87
82
bool post (std::uint32_t count) noexcept {
0 commit comments