Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7#include <optional>
8
11
12namespace contur {
13
15 class Mutex final : public ISyncPrimitive
16 {
17 public:
20
22 ~Mutex() override;
23
25 Mutex(const Mutex &) = delete;
26
28 Mutex &operator=(const Mutex &) = delete;
30 Mutex(Mutex &&) noexcept;
31
33 Mutex &operator=(Mutex &&) noexcept;
34
37 [[nodiscard]] Result<void> acquire(ProcessId pid) override;
38
41 [[nodiscard]] Result<void> release(ProcessId pid) override;
42
44 [[nodiscard]] Result<void> tryAcquire(ProcessId pid) override;
45
47 [[nodiscard]] std::string_view name() const noexcept override;
48
50 [[nodiscard]] SyncLayer layer() const noexcept override;
51
54
56 [[nodiscard]] PriorityLevel effectivePriority(ProcessId pid) const noexcept;
57
59 [[nodiscard]] PriorityLevel basePriority(ProcessId pid) const noexcept;
60
62 [[nodiscard]] bool isLocked() const noexcept;
63
65 [[nodiscard]] std::optional<ProcessId> owner() const noexcept;
66
68 [[nodiscard]] std::size_t recursionDepth() const noexcept;
69
71 [[nodiscard]] std::size_t waitingCount() const noexcept;
72
73 private:
74 struct Impl;
75 std::unique_ptr<Impl> impl_;
76 };
77
78} // namespace contur
Common interface for synchronization primitives.
SyncLayer layer() const noexcept override
Layer classification for synchronization model split.
PriorityLevel basePriority(ProcessId pid) const noexcept
Registered base priority.
Mutex(const Mutex &)=delete
Copy construction is disabled.
Mutex(Mutex &&) noexcept
Move-constructs mutex state.
bool isLocked() const noexcept
True when the mutex is owned by some process.
std::unique_ptr< Impl > impl_
Definition mutex.h:75
Mutex & operator=(const Mutex &)=delete
Copy assignment is disabled.
PriorityLevel effectivePriority(ProcessId pid) const noexcept
Effective priority after inheritance boosts.
Mutex()
Constructs an unlocked mutex.
~Mutex() override
Destroys mutex.
std::size_t recursionDepth() const noexcept
Reentrancy depth for owner.
Result< void > tryAcquire(ProcessId pid) override
Attempts immediate acquire without enqueueing waiters.
Result< void > registerProcessPriority(ProcessId pid, PriorityLevel basePriority)
Registers process base priority used by inheritance logic.
std::string_view name() const noexcept override
Primitive name for diagnostics.
std::optional< ProcessId > owner() const noexcept
Current owner process ID, if locked.
std::size_t waitingCount() const noexcept
Number of waiting processes.
Result< void > acquire(ProcessId pid) override
Acquires the mutex for process pid.
Result< void > release(ProcessId pid) override
Releases the mutex held by process pid.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
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.