Max OS 0.3
Loading...
Searching...
No Matches
spinlock.h
Go to the documentation of this file.
1
9#ifndef MAXOS_COMMON_SPINLOCK_H
10#define MAXOS_COMMON_SPINLOCK_H
11
12#include <common/vector.h>
13
14
15namespace MaxOS::common {
16
21 class Spinlock {
22
23 private:
24 bool m_locked = false;
25
26 public:
27 Spinlock();
28 ~Spinlock();
29
30 void lock();
31 void unlock();
32 [[nodiscard]] bool is_locked() const;
33
34 void acquire();
35 void release();
36 };
37
38
41
50
51 private:
52 bool m_locked = false;
53 Vector<uint64_t> m_queue;
54
55 static bool must_spin();
56
57 public:
60
61 void lock();
62 void unlock();
63 [[nodiscard]] bool is_locked() const;
64
65 void acquire();
66 void release();
67
68 };
69
70
71}
72
73
74#endif // MAXOS_COMMON_SPINLOCK_H
Enables a resource to be used by only one instance at a time through a combination of spinning and qu...
Definition spinlock.h:49
void acquire()
Acquire the spinlock, spin until the lock is available and sleeping the thread until marked as availa...
Definition spinlock.cpp:101
void lock()
Lock the spinlock once it is available, sleeping until other processes are done with it.
Definition spinlock.cpp:73
void release()
Mark as unlocked, wake the next enqueued thread.
Definition spinlock.cpp:129
void unlock()
Unlock the spinlock.
Definition spinlock.cpp:81
bool is_locked() const
Check if the spinlock is locked.
Definition spinlock.cpp:92
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Enables a resource to be used by only one instance at a time through locking and unlocking.
Definition spinlock.h:21
void lock()
Lock the spinlock once it is available.
Definition spinlock.cpp:24
void release()
Release the spinlock.
Definition spinlock.cpp:59
void unlock()
Unlock the spinlock.
Definition spinlock.cpp:32
bool is_locked() const
Check if the spinlock is locked.
Definition spinlock.cpp:43
void acquire()
Acquire the spinlock: wait until the lock is available, spinning until that happens.
Definition spinlock.cpp:51
constexpr uint8_t BLOCKING_FAST_TRY_LIMIT
How many attempts to acquire the lock should fail before queueing.
Definition spinlock.h:40
Defines a Vector class for dynamically storing an array of elements.