Skip to content

Commit

Permalink
fix async-simple no discard when call spinlock::coScopedLock
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jan 20, 2025
1 parent 45d5061 commit 9f9e599
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/ylt/thirdparty/async_simple/coro/SpinLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef ASYNC_SIMPLE_CORO_SPIN_LOCK_H
#define ASYNC_SIMPLE_CORO_SPIN_LOCK_H

#include <atomic>
#ifndef ASYNC_SIMPLE_USE_MODULES
#include <mutex>
#include <thread>
Expand Down Expand Up @@ -60,11 +61,14 @@ class SpinLock {
}
}

void unlock() noexcept { _locked.store(false, std::memory_order_release); }
void unlock() noexcept {
assert(_locked.load(std::memory_order_acquire) == true);
_locked.store(false, std::memory_order_release);
}

Lazy<std::unique_lock<SpinLock>> coScopedLock() {
co_await coLock();
co_return std::unique_lock<SpinLock>{*this, std::adopt_lock};
[[nodiscard]] Lazy<std::unique_lock<SpinLock>> coScopedLock() {
co_await coLock();
co_return std::unique_lock<SpinLock>{*this, std::adopt_lock};
}

private:
Expand Down

0 comments on commit 9f9e599

Please sign in to comment.