Base class for shared memory objects.
More...
#include <shmem.h>
|
| shmem_base () |
| Default constructor.
|
|
| shmem_base (const std::string &name, size_t size) |
| Create and open a SMA.
|
|
virtual | ~shmem_base () |
| Destructor.
|
|
virtual bool | open (const std::string &name, size_t size) |
| Open a SMA.
|
|
virtual bool | close () |
| Close a SMA.
|
|
bool | created () const |
|
bool | is_opened () const |
| Return true if shared memory is opened.
|
|
size_t | size () const |
| Return size of shared memory area.
|
|
const std::string & | name () const |
| Return the name of the shared memory area.
|
|
void | wtmo (DWORD msec) |
| Set timeout value for write operations.
|
|
DWORD | wtmo () const |
| Return current write timeout value (in milliseconds)
|
|
void | rtmo (DWORD msec) |
| Set timeout value for read operations.
|
|
DWORD | rtmo () const |
| Return current timeout value for read operations (in milliseconds)
|
|
virtual bool | write (const void *data) |
| Obtain writer lock and update SMA.
|
|
virtual bool | read (void *data) |
| Obtain a reader lock and retrieve SMA content.
|
|
|
virtual bool | rdlock () |
| Obtain a reader lock on SMA.
|
|
virtual void | rdunlock () |
| Release a previously obtained reader lock.
|
|
virtual bool | wrlock () |
| Obtain a writer lock on SMA.
|
|
virtual void | wrunlock () |
| Release a previously obtained writer lock.
|
|
|
Use always together with lock control functions
|
void | get (void *data) const |
| Retrieve current content of SMA.
|
|
void | put (const void *data) |
| Write new data into the SMA.
|
|
const void * | dataptr () const |
| Return a pointer to content of SMA (const variant)
|
|
void * | dataptr () |
| Return a pointer to content of SMA (non-const variant)
|
|
Base class for shared memory objects.
◆ shmem_base() [1/2]
mlib::shmem_base::shmem_base |
( |
| ) |
|
Default constructor.
The shared memory area (SMA) must be opened before use.
◆ shmem_base() [2/2]
mlib::shmem_base::shmem_base |
( |
const std::string & | nam, |
|
|
size_t | sz_ ) |
Create and open a SMA.
- Parameters
-
nam | name of SMA |
sz_ | size of SMA (not including size of synchronization stuff) |
◆ ~shmem_base()
mlib::shmem_base::~shmem_base |
( |
| ) |
|
|
virtual |
Destructor.
If SMA was opened, close it now.
◆ created()
bool mlib::shmem_base::created |
( |
| ) |
const |
|
inline |
Return true
if this instance has created the shared memory area or false
if shared memory existed already.
◆ open()
bool mlib::shmem_base::open |
( |
const std::string & | nam, |
|
|
size_t | sz_ ) |
|
virtual |
Open a SMA.
- Parameters
-
nam | name of SMA |
sz_ | size of SMA (not including size of synchronization stuff) |
The SMA is called <nam>.MEM
. Additionally, the following objects are created:
- event flag
<nam>.EVT
- Mutex
<nam>.MUT
◆ rdlock()
bool mlib::shmem_base::rdlock |
( |
| ) |
|
|
protectedvirtual |
Obtain a reader lock on SMA.
- Returns
true
if successful, false
otherwise
If a write operation is in progress, the function waits for it to complete before acquiring read lock. If it cannot obtain the lock in read timeout set, the function returns false
.
◆ read()
bool mlib::shmem_base::read |
( |
void * | pData | ) |
|
|
virtual |
Obtain a reader lock and retrieve SMA content.
- Parameters
-
◆ write()
bool mlib::shmem_base::write |
( |
const void * | pData | ) |
|
|
virtual |
Obtain writer lock and update SMA.
- Parameters
-
pData | pointer to data to write in SMA |
◆ wrlock()
bool mlib::shmem_base::wrlock |
( |
| ) |
|
|
protectedvirtual |
Obtain a writer lock on SMA.
- Returns
- true if successful, false otherwise
If another operation is in progress, the function waits for it to complete before acquiring write lock. If it cannot obtain the lock in write timeout set, the function returns false.
The documentation for this class was generated from the following files: