The Pedigree Project 0.1
OperationBarrier.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#ifndef PEDIGREE_KERNEL_PROCESS_OPERATIONBARRIER_H
9#define PEDIGREE_KERNEL_PROCESS_OPERATIONBARRIER_H
10#include "pedigree/kernel/compiler.h"
11#include "pedigree/kernel/process/WaitQueue.h"
12
13#include <config.h>
14
23class EXPORTED_PUBLIC OperationBarrier {
24 public:
26 class EXPORTED_PUBLIC Lease {
27 public:
28 Lease();
29 Lease(Lease&& other) noexcept;
30 ~Lease();
31
32 Lease& operator=(Lease&& other) noexcept;
33
34 explicit operator bool() const {
35 return m_Barrier != nullptr;
36 }
37
38 private:
39 friend class OperationBarrier;
40
41 explicit Lease(OperationBarrier* barrier);
42 void reset();
43
44 Lease(const Lease&) = delete;
45 Lease& operator=(const Lease&) = delete;
46
47 OperationBarrier* m_Barrier;
48 };
49
52
54 MUST_USE_RESULT bool tryEnter();
55
62 MUST_USE_RESULT bool tryAcquire(Lease& lease);
63
65 void leave();
66
68 void close();
69
71 MUST_USE_RESULT bool tryCloseIfIdle();
72
74 void wait();
75
77 void closeAndWait();
78
79 bool isOpen();
80 bool isClosedAndDrained();
81
82 private:
83 NOT_COPYABLE_OR_ASSIGNABLE(OperationBarrier);
84
85 WaitQueue m_Waiters;
86 bool m_Open;
87 size_t m_ActiveOperations;
88};
89
90#endif