7 #include "Arp/System/Commons/Threading/LockGuard.hpp"
8 #include "Arp/System/Commons/Threading/Mutex.hpp"
9 #include "Arp/System/Nm/NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp"
14 namespace Arp {
namespace System {
namespace Nm
17 template<
typename ArgumentsType>
38 bool IsFree(
size_t index)
const;
41 bool IsFullUnsynced()
const;
42 bool IsFreeUnsynced(
size_t index)
const;
45 std::vector<ArgumentsType> arguments;
46 std::vector<size_t> freeList;
51 template<
typename ArgumentsType>
54 : arguments(capacity), freeList(capacity)
56 std::iota(freeList.begin(), freeList.end(), 1);
59 template<
typename ArgumentsType>
60 typename NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::InsertResult
61 NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::Insert(
const ArgumentsType& argument)
64 if (this->IsFullUnsynced())
66 return {this->arguments.size(),
false};
69 size_t current = this->next;
70 this->arguments.at(current) = argument;
71 this->next = std::exchange(this->freeList.at(current), this->arguments.size());
72 return {current,
true};
75 template<
typename ArgumentsType>
76 typename NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::RemoveResult
77 NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::Remove(
size_t index)
79 LockGuard lock(this->mutex);
80 if ((index >= this->arguments.size()) || this->IsFreeUnsynced(index))
85 this->freeList.at(index) = this->next;
87 return {this->arguments.at(index),
true};
90 template<
typename ArgumentsType>
91 bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFull()
const
93 LockGuard lock(this->mutex);
94 return this->IsFullUnsynced();
97 template<
typename ArgumentsType>
98 bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFree(
size_t index)
const
100 LockGuard lock(this->mutex);
101 return this->IsFreeUnsynced(index);
104 template<
typename ArgumentsType>
105 bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFullUnsynced()
const
107 return this->next == this->arguments.size();
110 template<
typename ArgumentsType>
111 bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFreeUnsynced(
size_t index)
const
113 return (index < this->arguments.size()) &&
114 ((this->next == index) ||
115 (std::find(this->freeList.begin(), this->freeList.end(), index) != this->freeList.end()));
Simple lock guard, acquiring lock on construction and release it on destruction.
Definition: LockGuard.hpp:15
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:26
Internal base class for ArgumentsBuffer
Definition: NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp:19
Definition: NonBlockingNotificationRegistration3ArgumentsBuffer.hpp:20
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API
Definition: NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp:38
Definition: NonBlockingNotificationRegistration3ArgumentsBuffer.hpp:31