Update semaphore_linux.h

This commit is contained in:
木头云 2021-09-12 21:51:08 +08:00 committed by GitHub
parent d37a6740ea
commit cd4b28380c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,7 @@ public:
} }
bool wait(std::uint64_t tm) noexcept { bool wait(std::uint64_t tm) noexcept {
if (h == invalid()) return false; if (!valid()) return false;
switch (tm) { switch (tm) {
case 0: case 0:
return true; return true;
@ -72,7 +72,7 @@ public:
return true; return true;
default: { default: {
auto ts = detail::make_timespec(tm); auto ts = detail::make_timespec(tm);
if (::sem_timedwait(h, &ts) != 0) { if (::sem_timedwait(h_, &ts) != 0) {
if (errno != ETIMEDOUT) { if (errno != ETIMEDOUT) {
ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n", ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
errno, tm, ts.tv_sec, ts.tv_nsec); errno, tm, ts.tv_sec, ts.tv_nsec);
@ -85,7 +85,7 @@ public:
} }
bool post(std::uint32_t count) noexcept { bool post(std::uint32_t count) noexcept {
if (h_ == invalid()) return false; if (!valid()) return false;
for (std::uint32_t i = 0; i < count; ++i) { for (std::uint32_t i = 0; i < count; ++i) {
if (::sem_post(h_) != 0) { if (::sem_post(h_) != 0) {
ipc::error("fail sem_post[%d]: %s\n", errno); ipc::error("fail sem_post[%d]: %s\n", errno);