PCL
|
Automatic view lock/unlock. More...
#include <AutoViewLock.h>
Public Member Functions | |
AutoViewLock (const AutoViewLock &)=delete | |
AutoViewLock (View &view, bool lock=true) | |
~AutoViewLock () | |
void | Lock () |
void | LockForWrite () |
AutoViewLock & | operator= (const AutoViewLock &)=delete |
void | RelockForRead () |
void | Unlock () |
void | UnlockForRead () |
AutoViewLock simplifies locking and unlocking View objects accessed from process execution routines.
An AutoViewLock object locks a View upon construction and unlocks it upon destruction. This ensures that a view will never be left locked, even in critical situations involving multiple function return points and exceptions.
AutoViewLock works for View just as AutoLock does for Mutex. The main difference is that a view can be locked and unlocked for read and write operations separately, while a mutex cannot.
Typically AutoViewLock is used within a reimplementation of the ProcessImplementation::ExecuteOn() virtual member function for a process instance class. Consider the following example:
With AutoViewLock the above code can be simplified considerably:
Note that the try-catch blocks are now unnecessary. As soon as the lock
variable gets out of scope, the view
object will be unlocked automatically, including both normal function returns and uncaught exceptions within the ExecuteOn() function. Keep in mind that all exceptions will always be caught by internal PCL routines.
Definition at line 152 of file AutoViewLock.h.
|
inlineexplicit |
Constructs an AutoViewLock object to monitor the specified view.
view | A View object that will be monitored by this AutoViewLock instance. The object must remain valid for the whole lifetime of this AutoViewLock instance. |
lock | Whether the specified view should be locked for read and write operations by this constructor. The default value is true. |
If the lock argument is true, the specified view will be locked for read and write operations immediately by this constructor. It will be unlocked automatically when this AutoViewLock object gets out of scope, or if it is destroyed explicitly.
By specifying lock=false, you can create an AutoViewLock object to monitor a view and lock it for write operations exclusively:
See AutoViewWriteLock for a convenience class to implements this functionality in a cleaner way.
Definition at line 187 of file AutoViewLock.h.
|
inline |
Destroys this AutoViewLock object.
If the monitored view (that was specified in the constructor) is locked, it is unlocked by this destructor.
Definition at line 202 of file AutoViewLock.h.
References pcl::View::Null().
|
delete |
Copy constructor. This constructor is disabled because views and view locks are unique objects.
|
inline |
Locks the monitored view for read and write operations, if it has not been previously locked.
For more information, see the documentation for View::Lock().
Definition at line 226 of file AutoViewLock.h.
|
inline |
Locks the monitored view for write operations, if it has not already been write-locked.
For more information, see the documentation for View::LockForWrite().
Definition at line 266 of file AutoViewLock.h.
|
delete |
Copy assignment. This operator is disabled because views and view locks are unique objects.
|
inline |
Unlocks the monitored view for read operations only, if it has not already been unlocked.
For more information, see the documentation for View::RelockForRead().
Definition at line 292 of file AutoViewLock.h.
|
inline |
Unlocks the monitored view for read and write operations, if it has been previously locked.
For more information, see the documentation for View::Unlock().
Definition at line 246 of file AutoViewLock.h.
|
inline |
Unlocks the monitored view for read operations, if it has already been read-locked.
For more information, see the documentation for View::UnlockForRead().
Definition at line 279 of file AutoViewLock.h.