3 #include "Arp/System/Core/TypeName.hxx" 4 #include "Arp/System/Core/AppDomainSingleton.hxx" 5 #include "Arp/System/Commons/Ipc/SharedMemory.hpp" 6 #include "Arp/System/Commons/Threading/Thread.hpp" 7 #include "boost/interprocess/allocators/allocator.hpp" 8 #include "boost/interprocess/containers/string.hpp" 9 #include "boost/interprocess/containers/vector.hpp" 10 #include "boost/interprocess/containers/list.hpp" 11 #include "boost/interprocess/containers/map.hpp" 12 #include "boost/interprocess/containers/set.hpp" 16 #ifdef ARP_PLATFORM_LINUX 20 namespace Arp {
namespace System {
namespace Commons {
namespace Ipc
26 template<
class Derived>
30 using Base = SharedMemory;
31 using DerivedType = Derived;
33 using SharedMemory = boost::interprocess::managed_shared_memory;
34 using SegmentManager = SharedMemory::segment_manager;
35 using SharedMemoryPermission = boost::interprocess::permissions;
39 using Ptr = boost::interprocess::offset_ptr<T>;
42 using ConstPtr = boost::interprocess::offset_ptr<const T>;
51 static void CreateInstance(
size_t memorySize);
52 static void OpenInstance(
void);
53 static void CloseInstance(
bool removeMemory =
false);
54 static void Remove(
void);
58 static void WaitInstance(
const char* waitMessage,
uint32 timeout = -1);
66 class Allocator :
public boost::interprocess::allocator<T, SegmentManager>
69 using AllocatorBase = boost::interprocess::allocator<T, SegmentManager>;
70 using segment_manager = SegmentManager;
71 using value_type =
typename AllocatorBase::value_type;
72 using pointer =
typename AllocatorBase::pointer;
73 using const_pointer =
typename AllocatorBase::const_pointer;
74 using void_pointer =
typename AllocatorBase::void_pointer;
75 using reference =
typename AllocatorBase::reference;
76 using const_reference =
typename AllocatorBase::const_reference;
77 using size_type =
typename AllocatorBase::size_type;
78 using difference_type =
typename AllocatorBase::difference_type;
79 using version =
typename AllocatorBase::version;
95 #ifdef ARP_PLATFORM_LINUX 101 pthread_mutexattr_t attr;
102 pthread_mutexattr_init(&attr);
104 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
105 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
106 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
108 pthread_mutex_init(&this->mutex, &attr);
110 pthread_mutexattr_destroy(&attr);
118 pthread_mutex_destroy(&this->mutex);
124 pthread_mutex_lock(&this->mutex);
128 pthread_mutex_unlock(&this->mutex);
132 pthread_mutex_t mutex;
138 Mutex(
void) =
default;
139 ~
Mutex(
void) =
default;
148 this->mutex.unlock();
152 boost::interprocess::interprocess_mutex mutex;
168 template <
class TMutex>
174 this->pMutex->Lock();
180 this->pMutex->Unlock();
190 using String = boost::interprocess::basic_string<char, std::char_traits<char>,
Allocator<char>>;
193 using vector = boost::interprocess::vector<T, Allocator<T>>;
196 using list = boost::interprocess::list<T, Allocator<T>>;
198 template <
class TKey,
class T,
class TCompare = std::less<TKey>>
199 using map = boost::interprocess::map<TKey, T, TCompare, Allocator<std::pair<const TKey, T>>>;
201 template <
class T,
class TCompare = std::less<T>>
202 using set = boost::interprocess::set<T, TCompare, Allocator<T>>;
207 template<
class Derived>
213 template<
class Derived>
219 template<
class Derived>
226 template<
class Derived>
233 template<
class Derived>
241 bool instanceExists =
false;
247 instanceExists =
true;
251 Log::Debug(waitMessage);
255 }
while (!instanceExists);
258 template<
class Derived>
273 template<
class Derived>
static Derived & CreateInstance(Args &&... args)
Creates this singleton instance.
Definition: AppDomainSingleton.hxx:74
This (meta programming) class provides the C++ typename of the as template argument passed type...
Definition: TypeName.hxx:55
Definition: SharedData.hxx:156
Definition: SharedData.hxx:27
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
static void Sleep(size_t milliseconds)
Suspends the execution of the calling thread.
static Derived & GetInstance(void)
Gets a reference of the singleton instance.
Definition: AppDomainSingleton.hxx:102
Definition: SharedData.hxx:66
Definition: SharedData.hxx:86
Definition: SharedData.hxx:135
SharedMemoryImpl sharedMemoryImpl
Actual implementation of the shared memory functionality.
Definition: SharedMemory.hpp:141
Definition: SharedData.hxx:169
Root namespace for the PLCnext API
This class implements the singleton pattern for singletons with process wide scope.
Definition: AppDomainSingleton.hxx:24
static void DisposeInstance(void)
Disposes this singleton instance.
Definition: AppDomainSingleton.hxx:119
System components used by the System, Device, Plc or Io domains.
String GetSafeName(void) const
Gets a safe name of the as template parameter given type.
Definition: TypeName.hxx:144
static bool IsCreated(void)
Determines if this singleton instance is created yet.
Definition: AppDomainSingleton.hxx:91
const Arp::String & GetName(void) const
Returns the name of the memory object.
Definition: SharedMemory.hpp:156