virtmem
virtual memory library for Arduino
virtmem::VPtrLock< TV > Class Template Reference

Creates a lock to some virtual data. More...

#include <vptr_utils.h>

Public Member Functions

 VPtrLock (const TV &v, VirtPageSize s, bool ro=false)
 Constructs a virtual data lock class and creates a lock to the given data. More...
 
 VPtrLock (void)
 Default constructor. No locks are created. More...
 
 ~VPtrLock (void)
 Unlocks data if locked.
 
 VPtrLock (const VPtrLock &other)
 Copy constructor, adds extra lock to data.
 
void lock (void)
 Recreates a virtual data lock after unlock was called. More...
 
void lock (const TV &v, VirtPageSize s, bool ro=false)
 Locks data. Parameters are described here.
 
void unlock (void)
 Unlocks data (if locked). Automatically called during destruction.
 
Ptr operator* (void)
 Provides access to the data.
 
VirtPageSize getLockSize (void) const
 Returns the actual size locked. More...
 

Detailed Description

template<typename TV>
class virtmem::VPtrLock< TV >

Creates a lock to some virtual data.

Template Parameters
TVType of virtual pointer that points to data

This class is used to create and release locks to virtual data. The use of locks allows more efficient data handling and compatibility with code only accepting regular pointers. For more information see Locking virtual data.

The class uses a RAII (resource acquisition is initialization) approach: after a lock has been acquired (usually during construction), it will be automatically released as soon as the class variable goes out of scope.

Wrapped regular pointers are supported: if a given virtual pointer wraps a regular pointer, this class will not attempt to make or release a lock and operator *(void) will simply return the wrapped pointer.

Examples:
locking.ino.

Constructor & Destructor Documentation

template<typename TV>
virtmem::VPtrLock< TV >::VPtrLock ( const TV &  v,
VirtPageSize  s,
bool  ro = false 
)
inline

Constructs a virtual data lock class and creates a lock to the given data.

Parameters
vA virtual pointer to the data to be locked.
sAmount of bytes to lock. Note: the actual locked size may be smaller.
roWhether locking should read-only (true) or not (false). If ro is false (default), the locked data will always be synchronized after unlocking (even if unchanged). Therefore, if no changes in data are expected, it is more efficient to set ro to true.
See also
getLockSize
template<typename TV>
virtmem::VPtrLock< TV >::VPtrLock ( void  )
inline

Default constructor. No locks are created.

The lock(const TV &v, VirtPageSize s, bool ro) function should be used to create a lock if this constructor is used.

Member Function Documentation

template<typename TV>
VirtPageSize virtmem::VPtrLock< TV >::getLockSize ( void  ) const
inline

Returns the actual size locked.

The actual size that was locked may be smaller then what was requested. If the requested size was too large, for instance larger then the largest memory page size, the locked size will be adjusted accordingly. For this reason, it is very important to use this function after a lock has been created.

template<typename TV>
void virtmem::VPtrLock< TV >::lock ( void  )
inline

Recreates a virtual data lock after unlock was called.

Note
This function will re-use the parameters for locking set by VPtrLock(const TV &v, VirtPageSize s, bool ro) or lock(const TV &v, VirtPageSize s, bool ro).

The documentation for this class was generated from the following file: