10#if __has_include("defs.h")
14#include "safe_winsock.h"
29 virtual bool open (
const std::string&
name,
size_t size);
30 virtual bool close ();
36 const std::string&
name ()
const;
39 void wtmo (DWORD msec);
41 void rtmo (DWORD msec);
45 virtual bool write (
const void* data);
46 virtual bool read (
void* data);
58 void get (
void* data)
const;
59 void put (
const void* data);
90template <
class S,
class B = shmem_base>
96 bool open (
const char*
name,
size_t sz =
sizeof (S));
104 template <
class S,
class B>
106 template <
class S,
class B>
111template <
class S,
class B>
116template <
class S,
class B>
118 : B (
name, sizeof (S)){};
121template <
class S,
class B>
124 return B::open (
name, sz);
128template <
class S,
class B>
135template <
class S,
class B>
165template <
class S,
class B = shmem_base>
175 const S* operator->()
177 return mem.dataptr ();
181 return const_cast<const S*
> (mem.dataptr ());
188template <
class S,
class B>
193 throw std::runtime_error (
"rdlock failure");
219template <
class S,
class B = shmem_base>
232 return mem.dataptr ();
236 return mem.dataptr ();
243template <
class S,
class B>
244lockw<S, B>::lockw (shmem<S, B>& mem_)
248 throw std::runtime_error (
"wrlock failed");
339template <
class S,
class B>
342 return (
const S*)B::dataptr ();
346template <
class S,
class B>
349 return (S*)B::dataptr ();
S * operator->()
Dereferences pointer to shared memory area.
Definition shmem.h:230
DWORD wtmo() const
Return current write timeout value (in milliseconds)
Definition shmem.h:291
virtual void wrunlock()
Release a previously obtained writer lock.
Definition shmem.cpp:261
virtual void rdunlock()
Release a previously obtained reader lock.
Definition shmem.cpp:193
DWORD rtmo() const
Return current timeout value for read operations (in milliseconds)
Definition shmem.h:305
void put(const void *data)
Write new data into the SMA.
Definition shmem.h:312
virtual bool rdlock()
Obtain a reader lock on SMA.
Definition shmem.cpp:167
shmem_base()
Default constructor.
Definition shmem.cpp:19
bool is_opened() const
Return true if shared memory is opened.
Definition shmem.h:263
virtual ~shmem_base()
Destructor.
Definition shmem.cpp:61
virtual bool wrlock()
Obtain a writer lock on SMA.
Definition shmem.cpp:213
const void * dataptr() const
Return a pointer to content of SMA (const variant)
Definition shmem.h:326
const std::string & name() const
Return the name of the shared memory area.
Definition shmem.h:277
virtual bool read(void *data)
Obtain a reader lock and retrieve SMA content.
Definition shmem.cpp:299
virtual bool write(const void *data)
Obtain writer lock and update SMA.
Definition shmem.cpp:282
size_t size() const
Return size of shared memory area.
Definition shmem.h:270
bool created() const
Definition shmem.h:256
void get(void *data) const
Retrieve current content of SMA.
Definition shmem.h:319
virtual bool open(const std::string &name, size_t size)
Open a SMA.
Definition shmem.cpp:78
virtual bool close()
Close a SMA.
Definition shmem.cpp:137
Shared memory area with support for single-writer multiple-readers.
Definition shmem.h:92
shmem()
Default constructor.
Definition shmem.h:112
shmem(const char *name)
Creates and opens a shared memory area with the given name.
Definition shmem.h:117
void operator<<(const S &data)
Update (write) the content of a shared memory area.
Definition shmem.h:136
S * dataptr()
Return a pointer to content of SMA (const variant)
Definition shmem.h:347
const S * dataptr() const
Return a pointer to content of SMA (const variant)
Definition shmem.h:340
bool open(const char *name, size_t sz=sizeof(S))
Opens a shared memory area.
Definition shmem.h:122
void operator>>(S &data)
Read the content of shared memory area.
Definition shmem.h:129