aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/coro/active_work.cpp
blob: 3ecd1c3a8a6882d188214a1c86523dca0f00bf37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "active_work.h"
#include <cassert>

namespace vespalib::coro {

bool
ActiveWork::join_awaiter::await_suspend(std::coroutine_handle<> handle) noexcept
{
    self._waiting = handle;
    return (self._pending.fetch_sub(1, std::memory_order_acq_rel) > 1);
}

ActiveWork::~ActiveWork()
{
    // NB: join must be called, even if there is no other work
    assert(_pending.load(std::memory_order_relaxed) == 0);
}

}