Skip to content

Commit c4fc58e

Browse files
authored
fix async-simple no discard when call spinlock::coScopedLock (#884)
* fix async-simple no discard when call spinlock::coScopedLock * remove useless header
1 parent 45d5061 commit c4fc58e

File tree

1 file changed

+7
-4
lines changed
  • include/ylt/thirdparty/async_simple/coro

1 file changed

+7
-4
lines changed

include/ylt/thirdparty/async_simple/coro/SpinLock.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ class SpinLock {
6060
}
6161
}
6262

63-
void unlock() noexcept { _locked.store(false, std::memory_order_release); }
63+
void unlock() noexcept {
64+
assert(_locked.load(std::memory_order_acquire) == true);
65+
_locked.store(false, std::memory_order_release);
66+
}
6467

65-
Lazy<std::unique_lock<SpinLock>> coScopedLock() {
66-
co_await coLock();
67-
co_return std::unique_lock<SpinLock>{*this, std::adopt_lock};
68+
[[nodiscard]] Lazy<std::unique_lock<SpinLock>> coScopedLock() {
69+
co_await coLock();
70+
co_return std::unique_lock<SpinLock>{*this, std::adopt_lock};
6871
}
6972

7073
private:

0 commit comments

Comments
 (0)