8#include "Arp/System/Commons/Threading/LockGuard.hpp" 
    9#include "Arp/System/Commons/Threading/Mutex.hpp" 
   10#include "Arp/System/Nm/NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp" 
   15namespace Arp { 
namespace System { 
namespace Nm
 
   18template<
typename ArgumentsType>
 
   39    bool IsFree(
size_t index) 
const;
 
   42    bool IsFullUnsynced() 
const;
 
   43    bool IsFreeUnsynced(
size_t index) 
const;
 
   46    std::vector<ArgumentsType> arguments;
 
   47    std::vector<size_t> freeList;
 
   52template<
typename ArgumentsType>
 
   55    : arguments(capacity), freeList(capacity)
 
   57    std::iota(freeList.begin(), freeList.end(), 1);
 
   60template<
typename ArgumentsType>
 
   65    if (this->IsFullUnsynced())
 
   67        return {this->arguments.size(), 
false};
 
   70    size_t current = this->next;
 
   71    this->arguments.at(current) = argument;
 
   72    this->next = std::exchange(this->freeList.at(current), this->arguments.size());
 
   73    return {current, 
true};
 
   76template<
typename ArgumentsType>
 
   77typename NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::RemoveResult
 
   78NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::Remove(
size_t index)
 
   80    LockGuard lock(this->mutex);
 
   81    if ((index >= this->arguments.size()) || this->IsFreeUnsynced(index))
 
   86    this->freeList.at(index) = this->next;
 
   88    return {this->arguments.at(index), 
true};
 
   91template<
typename ArgumentsType>
 
   92bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFull()
 const 
   94    LockGuard lock(this->mutex);
 
   95    return this->IsFullUnsynced();
 
   98template<
typename ArgumentsType>
 
   99bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFree(
size_t index)
 const 
  101    LockGuard lock(this->mutex);
 
  102    return this->IsFreeUnsynced(index);
 
  105template<
typename ArgumentsType>
 
  106bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFullUnsynced()
 const 
  108    return this->next == this->arguments.size();
 
  111template<
typename ArgumentsType>
 
  112bool NonBlockingNotificationRegistration3ArgumentsBuffer<ArgumentsType>::IsFreeUnsynced(
size_t index)
 const 
  114    return (index < this->arguments.size()) &&
 
  115           ((this->next == index) ||
 
  116            (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:17
 
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:27
 
Internal base class for ArgumentsBuffer
Definition: NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp:20
 
Definition: NonBlockingNotificationRegistration3ArgumentsBuffer.hpp:21
 
Root namespace for the PLCnext API
 
Definition: NonBlockingNotificationRegistration3ArgumentsBufferBase.hpp:39
 
Definition: NonBlockingNotificationRegistration3ArgumentsBuffer.hpp:32