Skip to content

Commit

Permalink
Semaphore wait keeps uninterrupted, while add wait_interruptible
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <coldwings@me.com>
  • Loading branch information
Coldwings committed Feb 28, 2024
1 parent f4a2f7e commit 799437b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion thread/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ TEST(interrupt, semaphore) {
// any errno except 0 is able to stop waiting
photon::thread_interrupt(th, reason);
});
auto ret = sem.wait(1); // nobody
auto ret = sem.wait_interruptible(1); // nobody
ERRNO err;
EXPECT_EQ(-1, ret);
EXPECT_EQ(reason, err.no);
Expand Down
2 changes: 1 addition & 1 deletion thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ R"(
{
return cvar_do_wait((thread_list*)&q, m, timeout, spinlock_lock, spinlock_unlock);
}
int semaphore::wait(uint64_t count, Timeout timeout)
int semaphore::wait_interruptible(uint64_t count, Timeout timeout)
{
if (count == 0) return 0;
splock.lock();
Expand Down
9 changes: 4 additions & 5 deletions thread/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,14 @@ namespace photon
{
public:
explicit semaphore(uint64_t count = 0) : m_count(count) { }
int wait(uint64_t count, Timeout timeout = {});
int wait_uninterruptible(uint64_t count, Timeout timeout = {}) {
int wait(uint64_t count, Timeout timeout = {}) {
int ret = 0;
do {
ret = wait(count, timeout);
} while (!timeout.expired() &&
(ret == 0 || (ret < 0 && errno == ESHUTDOWN)));
ret = wait_interruptible(count, timeout);
} while (ret < 0 && (errno != ESHUTDOWN && errno != ETIMEDOUT));
return ret;
}
int wait_interruptible(uint64_t count, Timeout timeout = {});
int signal(uint64_t count)
{
if (count == 0) return 0;
Expand Down

0 comments on commit 799437b

Please sign in to comment.