Skip to content

Commit

Permalink
up mm
Browse files Browse the repository at this point in the history
  • Loading branch information
k-morozov committed Jul 30, 2024
1 parent 2e3ae71 commit d36baaf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/sync/queue_spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class QueueSpinLock final {

private:
void Acquire(Guard* guard) {
auto ancestor = tail_.exchange(guard, std::memory_order_acquire);
auto ancestor = tail_.exchange(guard/*, std::memory_order_acquire*/);
if (ancestor == nullptr) {
guard->SetOwner();
return;
Expand Down
9 changes: 5 additions & 4 deletions src/fiber/awaiter/wait_group_awaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <mutex>

#include <components/intrusive/list.h>
#include <components/sync/queue_spinlock.h>
#include <fiber/awaiter/awaiter.h>

namespace NFibers {
Expand All @@ -15,23 +16,23 @@ template <class W>
class WaitGroupWaiter : public IAwaiter,
public NComponents::Node<WaitGroupWaiter<W>> {
public:
using Guard = std::unique_lock<typename W::Spinlock>;
using Guard = NSync::QueueSpinLock::Guard;

WaitGroupWaiter(W* wg, Guard guard) : wg(wg), guard(std::move(guard)){};
WaitGroupWaiter(W* wg, Guard& guard) : wg(wg), guard(guard){};

void AwaitSuspend(StoppedFiber fiber) override {
assert(fiber.IsValid());

stopped_fiber = fiber;
wg->Park(this);
guard.release()->unlock();
guard.Release();
}

void Schedule() { stopped_fiber.Schedule(); }

private:
W* wg;
Guard guard;
Guard& guard;
StoppedFiber stopped_fiber;
};

Expand Down
2 changes: 1 addition & 1 deletion src/fiber/sync/wait_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void WaitGroup::Done() {
void WaitGroup::Wait() {
Waiter::Guard guard(spinlock_);
if (counter_ > 0) {
Waiter wg_waiter(this, std::move(guard));
Waiter wg_waiter(this, guard);
Suspend(&wg_waiter);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/fiber/sync/wait_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

#include <components/intrusive/list.h>
#include <components/sync/spinLock.h>
#include <components/sync/queue_spinlock.h>
#include <fiber/awaiter/wait_group_awaiter.h>

namespace NFibers {

class WaitGroup {
using Spinlock = NSync::SpinLock;
using Spinlock = NSync::QueueSpinLock;
using Waiter = WaitGroupWaiter<WaitGroup>;

friend Waiter;
Expand Down

0 comments on commit d36baaf

Please sign in to comment.