MLIB
Loading...
Searching...
No Matches
mlib::shmem_base Class Reference

Base class for shared memory objects. More...

#include <shmem.h>

Inheritance diagram for mlib::shmem_base:
mlib::shmem< S, shmem_base > mlib::shmem< S, B >

Public Member Functions

 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.
 

Protected Member Functions

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.
 
Naked data access functions

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)
 

Detailed Description

Base class for shared memory objects.

Constructor & Destructor Documentation

◆ 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
namname 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.

Member Function Documentation

◆ 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
namname 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
pDatapointer to data

◆ write()

bool mlib::shmem_base::write ( const void * pData)
virtual

Obtain writer lock and update SMA.

Parameters
pDatapointer 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: