Max OS 0.3
Loading...
Searching...
No Matches
block.h
Go to the documentation of this file.
1
9#ifndef MAXOS_PROCESSES_BLOCK_H
10#define MAXOS_PROCESSES_BLOCK_H
11
12#include <libcommon/vector.h>
13
14namespace MaxOS::processes {
15
17 constexpr uint8_t BLOCKING_FAST_TRY_LIMIT = UINT8_MAX;
18
29
30 private:
31 bool m_locked = false;
32 common::Vector<uint64_t> m_queue;
33
34 static bool must_spin();
35
36 public:
39
40 void lock();
41 void unlock();
42 [[nodiscard]] bool is_locked() const;
43
44 void acquire();
45 void release();
46
47 };
48
49};
50
51#endif //MAXOS_PROCESSES_BLOCK_H
constexpr uint8_t BLOCKING_FAST_TRY_LIMIT
How many attempts to acquire the lock should fail before queueing.
Definition block.h:17
Enables a resource to be used by only one instance at a time through a combination of spinning and qu...
Definition block.h:28
void acquire()
Acquire the spinlock, spin until the lock is available and sleeping the thread until marked as availa...
Definition block.cpp:49
void lock()
Lock the spinlock once it is available, sleeping until other processes are done with it.
Definition block.cpp:23
void release()
Mark as unlocked, wake the next enqueued thread.
Definition block.cpp:68
void unlock()
Unlock the spinlock.
Definition block.cpp:30
bool is_locked() const
Check if the spinlock is locked.
Definition block.cpp:39