Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7
10
11namespace contur {
12
14 class Semaphore final : public ISyncPrimitive
15 {
16 public:
18 explicit Semaphore(std::size_t initialCount = 1, std::size_t maxCount = 1);
19
21 ~Semaphore() override;
22
24 Semaphore(const Semaphore &) = delete;
25
27 Semaphore &operator=(const Semaphore &) = delete;
29 Semaphore(Semaphore &&) noexcept;
30
32 Semaphore &operator=(Semaphore &&) noexcept;
33
35 [[nodiscard]] Result<void> acquire(ProcessId pid) override;
36
38 [[nodiscard]] Result<void> release(ProcessId pid) override;
39
41 [[nodiscard]] Result<void> tryAcquire(ProcessId pid) override;
42
44 [[nodiscard]] std::string_view name() const noexcept override;
45
47 [[nodiscard]] SyncLayer layer() const noexcept override;
48
51
53 [[nodiscard]] PriorityLevel effectivePriority(ProcessId pid) const noexcept;
54
56 [[nodiscard]] PriorityLevel basePriority(ProcessId pid) const noexcept;
57
59 [[nodiscard]] std::size_t count() const noexcept;
60
62 [[nodiscard]] std::size_t maxCount() const noexcept;
63
65 [[nodiscard]] std::size_t waitingCount() const noexcept;
66
67 private:
68 struct Impl;
69 std::unique_ptr<Impl> impl_;
70 };
71
72} // namespace contur
Common interface for synchronization primitives.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Result< void > release(ProcessId pid) override
Releases one semaphore unit.
~Semaphore() override
Destroys semaphore.
Result< void > registerProcessPriority(ProcessId pid, PriorityLevel basePriority)
Registers process base priority used for boost rules.
std::string_view name() const noexcept override
Primitive name for diagnostics.
SyncLayer layer() const noexcept override
Layer classification for synchronization model split.
std::size_t count() const noexcept
Current available count.
PriorityLevel basePriority(ProcessId pid) const noexcept
Registered base priority.
Semaphore(std::size_t initialCount=1, std::size_t maxCount=1)
Constructs semaphore with initial and maximum count.
Semaphore(const Semaphore &)=delete
Copy construction is disabled.
std::unique_ptr< Impl > impl_
Definition semaphore.h:69
Result< void > tryAcquire(ProcessId pid) override
Non-blocking acquire attempt.
PriorityLevel effectivePriority(ProcessId pid) const noexcept
Effective priority after inheritance boosts.
Result< void > acquire(ProcessId pid) override
Acquires one semaphore unit.
std::size_t waitingCount() const noexcept
Number of waiting processes.
Semaphore & operator=(const Semaphore &)=delete
Copy assignment is disabled.
Semaphore(Semaphore &&) noexcept
Move-constructs semaphore state.
std::size_t maxCount() const noexcept
Configured maximum count.
ISyncPrimitive interface for synchronization objects.
Definition block.h:15
PriorityLevel
Discrete priority levels, from highest (Realtime) to lowest (Idle).
Definition priority.h:20
std::uint32_t ProcessId
Unique identifier for a process.
Definition types.h:12
SyncLayer
Distinguishes simulated sync resources from kernel-internal locks.
Process priority levels and the Priority struct.