virtmem
virtual memory library for Arduino
|
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... | |
Creates a lock to some virtual data.
TV | Type 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.
|
inline |
Constructs a virtual data lock class and creates a lock to the given data.
v | A virtual pointer to the data to be locked. |
s | Amount of bytes to lock. Note: the actual locked size may be smaller. |
ro | Whether 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 . |
|
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.
|
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.
|
inline |
Recreates a virtual data lock after unlock was called.