3#include <condition_variable>
32 std::condition_variable readerCanEnter_;
33 std::condition_variable writerCanEnter_;
35 int writersWaiting_ = 0;
47 explicit FrameSlot(std::counting_semaphore<>& slots);
55 std::counting_semaphore<>* slots_;
62 std::shared_lock<BusLock>
bus;
63 std::unique_lock<std::mutex>
drive;
69 std::shared_lock<BusLock>
bus;
109 [[nodiscard]] std::unique_lock<BusLock>
lockBus();
124 std::unique_ptr<std::mutex[]> drives_;
125 std::counting_semaphore<> frameSlots_{
kFrameSlots};
A reader/writer lock that lets no new reader in while a writer waits.
Definition control_plane_locks.h:23
void unlock()
Definition control_plane_locks.cc:22
void lock_shared()
Definition control_plane_locks.cc:32
void unlock_shared()
Definition control_plane_locks.cc:38
void lock()
Definition control_plane_locks.cc:14
The control-plane locks of one fieldbus driver: one for the bus, one per drive.
Definition control_plane_locks.h:87
std::shared_lock< BusLock > lockBusShared()
Excludes only work on the whole bus. For reads of what a scan or a re-map produced,...
Definition control_plane_locks.cc:65
static constexpr std::ptrdiff_t kFrameSlots
Definition control_plane_locks.h:102
std::unique_lock< BusLock > lockBus()
Excludes all other control-plane work. For work on the whole bus.
Definition control_plane_locks.cc:63
DriveLock lockDrive(uint16_t position)
Excludes work on the whole bus and other work on the same drive.
Definition control_plane_locks.cc:74
BusIoLock lockBusIo()
Excludes only work on the whole bus, and takes a frame slot. For reads that send frames to several dr...
Definition control_plane_locks.cc:69
One of a fixed number of slots for a frame on the wire. Released when destroyed.
Definition control_plane_locks.h:45
FrameSlot(const FrameSlot &)=delete
~FrameSlot()
Definition control_plane_locks.cc:52
FrameSlot & operator=(const FrameSlot &)=delete
FrameSlot & operator=(FrameSlot &&)=delete
Definition al_status_codes.cc:5
The bus lock held shared, and a frame slot. The slot goes first.
Definition control_plane_locks.h:68
FrameSlot frame
Definition control_plane_locks.h:70
std::shared_lock< BusLock > bus
Definition control_plane_locks.h:69
The bus lock held shared, the lock of one drive, and a frame slot.
Definition control_plane_locks.h:61
std::shared_lock< BusLock > bus
Definition control_plane_locks.h:62
std::unique_lock< std::mutex > drive
Definition control_plane_locks.h:63
FrameSlot frame
Definition control_plane_locks.h:64