8#if __has_include("defs.h")
12#include "safe_winsock.h"
23 shmem_base (
const std::string& name,
size_t size);
27 virtual bool open (
const std::string& name,
size_t size);
28 virtual bool close ();
34 bool is_opened ()
const
42 const std::string& name ()
const
48 void wtmo (DWORD msec)
56 void rtmo (DWORD msec)
66 virtual bool write (
const void* data);
67 virtual bool read (
void* data);
77 virtual void get (
void* data);
78 virtual void put (
const void* data);
79 void* dataptr ()
const
111template <
class S,
class B = shmem_base>
117 bool open (
const char* name,
size_t sz =
sizeof (S));
124 return (S*)B::dataptr ();
127 template <
class S,
class B>
129 template <
class S,
class B>
134template <
class S,
class B>
139template <
class S,
class B>
141 : B (name, sizeof (S)){};
144template <
class S,
class B>
147 return B::open (name, sz);
151template <
class S,
class B>
158template <
class S,
class B>
188template <
class S,
class B = shmem_base>
198 const S* operator->()
200 return const_cast<const S*
> (mem.dataptr ());
204 return const_cast<const S*
> (mem.dataptr ());
211template <
class S,
class B>
216 throw std::runtime_error (
"rdlock failure");
242template <
class S,
class B = shmem_base>
254 return mem.dataptr ();
258 return mem.dataptr ();
265template <
class S,
class B>
270 throw std::runtime_error (
"wrlock failed");
Smart read pointer for a shared memory area.
Definition shmem.h:190
Smart write pointer for a shared memory area.
Definition shmem.h:244
void wrunlock()
Release a previously obtained writer lock.
Definition shmem.cpp:268
void rdunlock()
Release a previously obtained reader lock.
Definition shmem.cpp:198
virtual void get(void *data)
Retrieve current content of SMA.
Definition shmem.cpp:292
virtual void put(const void *data)
Write new data into the SMA.
Definition shmem.cpp:286
bool rdlock()
Obtain a reader lock on SMA.
Definition shmem.cpp:170
shmem_base()
Default constructor.
Definition shmem.cpp:20
virtual ~shmem_base()
Destructor.
Definition shmem.cpp:62
bool wrlock()
Obtain a writer lock on SMA.
Definition shmem.cpp:218
virtual bool read(void *data)
Obtain a reader lock and retrieve SMA content.
Definition shmem.cpp:318
virtual bool write(const void *data)
Obtain writer lock and update SMA.
Definition shmem.cpp:301
virtual bool open(const std::string &name, size_t size)
Open a SMA.
Definition shmem.cpp:79
virtual bool close()
Close a SMA.
Definition shmem.cpp:140
Shared memory area with support for single-writer multiple-readers.
Definition shmem.h:113
shmem()
Default constructor.
Definition shmem.h:135
shmem(const char *name)
Creates and opens a shared memory area with the given name.
Definition shmem.h:140
void operator<<(const S &data)
Update (write) the content of a shared memory area.
Definition shmem.h:159
bool open(const char *name, size_t sz=sizeof(S))
Opens a shared memory area.
Definition shmem.h:145
void operator>>(S &data)
Read the content of shared memory area.
Definition shmem.h:152