dispenso
A library for task parallelism
Loading...
Searching...
No Matches
latch.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) Meta Platforms, Inc. and affiliates.
3
*
4
* This source code is licensed under the MIT license found in the
5
* LICENSE file in the root directory of this source tree.
6
*/
7
14
#pragma once
15
16
#include <dispenso/platform.h>
17
18
#include <dispenso/detail/completion_event_impl.h>
19
20
namespace
dispenso {
21
26
class
Latch
{
27
public
:
33
explicit
Latch
(
uint32_t
threadGroupCount
)
noexcept
: impl_(
threadGroupCount
) {}
34
38
void
count_down
(
uint32_t
n
= 1)
noexcept
{
39
if
(impl_.intrusiveStatus().fetch_sub(
n
, std::memory_order_acq_rel) == 1) {
40
impl_.notify(0);
41
}
42
}
43
52
bool
try_wait
()
const
noexcept
{
53
return
impl_.intrusiveStatus().load(std::memory_order_acquire) == 0;
54
}
55
59
void
wait
()
const
noexcept
{
60
impl_.wait(0);
61
}
62
66
void
arrive_and_wait
()
noexcept
{
67
if
(impl_.intrusiveStatus().fetch_sub(1, std::memory_order_acq_rel) > 1) {
68
impl_.wait(0);
69
}
else
{
70
impl_.notify(0);
71
}
72
}
73
74
private
:
75
detail::CompletionEventImpl impl_;
76
};
77
78
}
// namespace dispenso
dispenso::Latch
Definition
latch.h:26
dispenso::Latch::arrive_and_wait
void arrive_and_wait() noexcept
Definition
latch.h:66
dispenso::Latch::count_down
void count_down(uint32_t n=1) noexcept
Definition
latch.h:38
dispenso::Latch::Latch
Latch(uint32_t threadGroupCount) noexcept
Definition
latch.h:33
dispenso::Latch::try_wait
bool try_wait() const noexcept
Definition
latch.h:52
dispenso::Latch::wait
void wait() const noexcept
Definition
latch.h:59
dispenso::OpResult
detail::OpResult< T > OpResult
Definition
pipeline.h:29
dispenso
latch.h
Generated by
1.9.8