3#include "Arp/System/Core/TypeName.hxx"
4#include "Arp/System/Commons/Ipc/SharedMemory.hpp"
5#include "Arp/System/Commons/Threading/Thread.hpp"
6#include "boost/interprocess/allocators/allocator.hpp"
7#include "boost/interprocess/containers/string.hpp"
8#include "boost/interprocess/containers/vector.hpp"
9#include "boost/interprocess/containers/list.hpp"
10#include "boost/interprocess/containers/map.hpp"
11#include "boost/interprocess/containers/set.hpp"
15#ifdef ARP_PLATFORM_LINUX
19namespace Arp {
namespace System {
namespace Commons {
namespace Ipc
25template<
class Derived>
29 using Base = SharedMemory;
30 using DerivedType = Derived;
31 using SharedMemory = boost::interprocess::managed_shared_memory;
32 using SegmentManager = SharedMemory::segment_manager;
33 using SharedMemoryPermission = boost::interprocess::permissions;
37 using Ptr = boost::interprocess::offset_ptr<T>;
41 using ConstPtr = boost::interprocess::offset_ptr<const T>;
49 class Allocator :
public boost::interprocess::allocator<T, SegmentManager>
52 using AllocatorBase = boost::interprocess::allocator<T, SegmentManager>;
53 using segment_manager = SegmentManager;
54 using value_type =
typename AllocatorBase::value_type;
55 using pointer =
typename AllocatorBase::pointer;
56 using const_pointer =
typename AllocatorBase::const_pointer;
57 using void_pointer =
typename AllocatorBase::void_pointer;
58 using reference =
typename AllocatorBase::reference;
59 using const_reference =
typename AllocatorBase::const_reference;
60 using size_type =
typename AllocatorBase::size_type;
61 using difference_type =
typename AllocatorBase::difference_type;
62 using version =
typename AllocatorBase::version;
83#ifdef ARP_PLATFORM_LINUX
89 pthread_mutexattr_t attr;
90 pthread_mutexattr_init(&attr);
92 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
93 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
94 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
96 pthread_mutex_init(&this->mutex, &attr);
98 pthread_mutexattr_destroy(&attr);
106 pthread_mutex_destroy(&this->mutex);
112 pthread_mutex_lock(&this->mutex);
116 return (pthread_mutex_trylock(&this->mutex) == 0);
120 pthread_mutex_unlock(&this->mutex);
124 pthread_mutex_t mutex;
130 Mutex(
void) =
default;
140 return this->mutex.try_lock();
144 this->mutex.unlock();
148 boost::interprocess::interprocess_mutex mutex;
164 template <
class TMutex>
170 this->pMutex->Lock();
181 this->pMutex->Unlock();
191 using String = boost::interprocess::basic_string<char, std::char_traits<char>,
Allocator<char>>;
194 using vector = boost::interprocess::vector<T, Allocator<T>>;
197 using list = boost::interprocess::list<T, Allocator<T>>;
199 template <
class TKey,
class T,
class TCompare = std::less<TKey>>
200 using map = boost::interprocess::map<TKey, T, TCompare, Allocator<std::pair<const TKey, T>>>;
202 template <
class T,
class TCompare = std::less<T>>
203 using set = boost::interprocess::set<T, TCompare, Allocator<T>>;
208template<
class Derived>
210 : Base(
TypeName<DerivedType>().GetSafeName())
214template<
class Derived>
216 : Base(
TypeName<DerivedType>().GetSafeName(), memorySize)
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
Definition: SharedData.hxx:50
Definition: SharedData.hxx:128
Definition: SharedData.hxx:153
Definition: SharedData.hxx:166
Definition: SharedData.hxx:27
SharedMemoryImpl sharedMemoryImpl
Actual implementation of the shared memory functionality.
Definition: SharedMemory.hpp:72
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:27
Root namespace for the PLCnext API
Definition: SharedData.hxx:75