Skip to content

Commit ad92caa

Browse files
committed
change spinlock
1 parent 34c692b commit ad92caa

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/components/sync/queue_spinlock.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class QueueSpinLock final {
1616
host.Acquire(this);
1717
}
1818
~Guard() {
19+
Release();
20+
}
21+
22+
void Release() {
1923
host.Release(this);
2024
}
2125

src/fiber/awaiter/mutex_awaiter.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <components/intrusive/list.h>
1010
#include <components/sync/spinLock.h>
11+
#include <components/sync/queue_spinlock.h>
1112
#include <fiber/awaiter/awaiter.h>
1213

1314
namespace NFibers {
@@ -16,25 +17,27 @@ template <class M>
1617
class AsyncMutexWaiter : public IAwaiter,
1718
public NComponents::Node<AsyncMutexWaiter<M>> {
1819
public:
19-
using Guard = std::unique_lock<typename M::Spinlock>;
20+
using Guard = NSync::QueueSpinLock::Guard;
2021

21-
AsyncMutexWaiter(M* mutex, Guard guard)
22-
: mutex(mutex), guard(std::move(guard)){};
22+
AsyncMutexWaiter(M* async_mutex, Guard& guard)
23+
: async_mutex(async_mutex), guard(guard){};
2324

2425
void AwaitSuspend(StoppedFiber handle) override {
2526
assert(handle.IsValid());
2627

2728
stopped_handle = handle;
28-
mutex->Park(this);
29-
guard.release()->unlock();
29+
async_mutex->Park(this);
30+
31+
// guard.release()->unlock();
32+
guard.Release();
3033
}
3134

3235
void Schedule() { stopped_handle.Schedule(); }
3336

3437
private:
35-
M* mutex;
38+
M* async_mutex;
3639
StoppedFiber stopped_handle;
37-
Guard guard;
40+
Guard& guard;
3841
};
3942

4043
} // namespace NFibers

src/fiber/sync/async_mutex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace NFibers {
1111
void AsyncMutex::Lock() {
1212
Waiter::Guard guard(spinlock_);
1313
if (locked_) {
14-
Waiter waiter(this, std::move(guard));
14+
Waiter waiter(this, guard);
1515
Suspend(&waiter);
1616
} else {
1717
locked_ = true;

src/fiber/sync/async_mutex.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
#include <components/intrusive/list.h>
1010
#include <components/sync/spinLock.h>
11+
#include <components/sync/queue_spinlock.h>
1112
#include <fiber/awaiter/mutex_awaiter.h>
1213

1314
namespace NFibers {
1415

1516
class AsyncMutex {
16-
using Spinlock = NSync::SpinLock;
17+
using Spinlock = NSync::QueueSpinLock;
1718
using Waiter = AsyncMutexWaiter<AsyncMutex>;
1819

1920
friend Waiter;

0 commit comments

Comments
 (0)