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
20namespace dispenso {
21
26class Latch {
27 public:
34
39 if (impl_.intrusiveStatus().fetch_sub(n, std::memory_order_acq_rel) == 1) {
40 impl_.notify(0);
41 }
42 }
43
53 return impl_.intrusiveStatus().load(std::memory_order_acquire) == 0;
54 }
55
60 impl_.wait(0);
61 }
62
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
void arrive_and_wait() noexcept
Definition latch.h:66
void count_down(uint32_t n=1) noexcept
Definition latch.h:38
Latch(uint32_t threadGroupCount) noexcept
Definition latch.h:33
bool try_wait() const noexcept
Definition latch.h:52
void wait() const noexcept
Definition latch.h:59
detail::OpResult< T > OpResult
Definition pipeline.h:29