|
| | ShmControl (char const *name, size_t capacity, std::optional< numapp::MemPolicy > mem_policy=std::nullopt, int mmap_flags=0) |
| | Create a new (owned) named shared memory segment.
|
| |
| | ShmControl (char const *name) |
| | Open an existing (not owned) shared memory segment in read only mode.
|
| |
| | ~ShmControl () noexcept |
| |
| | ShmControl (ShmControl &&rhs) noexcept |
| | Moves from rhs into this.
|
| |
| ShmControl & | operator= (ShmControl &&rhs) noexcept |
| | Moves from rhs into this.
|
| |
| constexpr void | AtomicLoadState () noexcept |
| | Load queue state from shared memory.
|
| |
| constexpr void | AtomicStoreState () noexcept |
| | Store queue range state to shared memory.
|
| |
| void | Signal () |
| | Signal objects blocking on AwaitSignal.
|
| |
| template<class Rep, class Period, class Predicate> |
| bool | AwaitSignal (std::chrono::duration< Rep, Period > timeout, Predicate pred) noexcept |
| | Await notification signal from writer.
|
| |
| constexpr void | Pop () |
| | Pop first element in queue.
|
| |
| constexpr bool | IsFull () const noexcept |
| |
| constexpr bool | IsEmpty () const noexcept |
| |
| constexpr bool | IsClosed () const noexcept |
| |
| constexpr void | Close () noexcept |
| | Close queue for further writing.
|
| |
| std::error_code | Push (const T &element) noexcept |
| | Push element to back of queue, if IsFull() it will overwrite first element.
|
| |
| std::error_code | Push (const T *data, size_t n) noexcept |
| |
| reference | operator[] (size_type index) |
| |
| const_reference | operator[] (size_type index) const |
| |
| constexpr size_type | Size () const noexcept |
| |
| constexpr value_type * | GetBuffer () const noexcept |
| |
| constexpr value_type * | GetQueuePtr () const noexcept |
| |
| constexpr ConstIterator | Begin () const noexcept |
| |
| constexpr ConstIterator | End () const noexcept |
| |
| | ShmControlBase (char const *name, QueueInfo queue_info, std::optional< numapp::MemPolicy > mem_policy=std::nullopt, int mmap_flags=0) |
| | Owner constructor.
|
| |
| | ShmControlBase (char const *name) |
| | Non-owner constructor.
|
| |
| | ShmControlBase (ShmControlBase &&rhs) noexcept |
| |
| ShmControlBase & | operator= (ShmControlBase &&rhs) noexcept |
| |
| char const * | TopicName () const noexcept |
| |
| char const * | ShmObjectName () const |
| |
| constexpr size_t | Capacity () const noexcept |
| |
| constexpr uint8_t | FileVersion () const noexcept |
| |
| constexpr pid_t | OwnerPid () const noexcept |
| |
template<class T, class ConditionPolicy, class ShmTraits = BoostInterprocessTraits>
class ipcq::detail::ShmControl< T, ConditionPolicy, ShmTraits >
ShmControl provides the basic data model for the queue and low level operations on the shared memory queue, some of which are atomic.
The shared data model for the queue includes:
- a Range describing the valid range of the data and
- the capacity of the circular buffer.
This information can be compressed into a single unsigned long long value which can be atomically read or writen.
The atomic operations are:
ShmControl does not encode knowledge of the buffer semantics. It merely provides the shared access patterns to it.
Two mappings are created to the shm segment, one for the control block and one for the queue. It's not really important, but if each region is mapped individually, there's less chance that an accidental overwrite of the queue region affects the control region. It also make offset calculations simpler since the control block is not accounted for.
Writer Protocol
Writers to the queue should adhere to the following protocol to ensure data consistency or detect inconsistent states:
To write one or more elements:
- Reserve enough room for elements to be written by calling
Pop() once for each element to write.
- "Publish" change of queue state by calling
AtomicStoreState().
- Add elements by calling
Push().
- "Publish" change of queue again by calling
AtomicStoreState().
Reader Protocol
- Read current queue state with
AtomicLoadState()
- Verify that iterator is valid.
- Copy.
- Read current queue state with
AtomicLoadState()
- Verify that iterator is still valid.
- Verify that copied element has the expected counter value.
Important
boost interprocess uses mmap on linux, and it is possible that write combine is used under unknown circumstances. If write combining is enabled then the strong memory ordering is no longer true.
Implementation Notes
boost::shared_memory_object corresponds to a file handle, opened with open(2). boost::shared_memory_object::truncate corresponds to ftruncate(2).
boost::mapped_region construction corresponds to a call to mmap(2) which in the case of ShmControl also allocate, lock and populate the memory using MAP_LOCKED and MAP_POPULATE.
User control over memory policy for the allocation is made possible because ShmControl in the "writer" is always the one that creates the boost::shared_memory_object and can then make sure that the chosen memory policy is applied when the allocation is performed in mmap(2).
Definition at line 658 of file shm.hpp.