The class to use to acquire the lock on resources. More...
|ResourcesLocker (ConcurrentResourcesUser *resourcesUser, bool acquireLock=true)|
|Acquires the lock. More...|
|Releases the lock. More...|
The class to use to acquire the lock on resources.
The ConcurrentResourcesUser class has no public methods to acquire the lock on the resources it uses. To acquire the lock use a local instance of ResourcesLocker so that you are also sure that the lock is released when the object is destroyed. Here is an example (suppose the current instance of A inherits from ConcurrentResourcesUser):
This class also has methods to manually lock and unlock resources, although their use is discouraged. Multiple calls to lock() will always result in the lock being acquired once (even if the underlying semaphores are recursive), so a single call to unlock() is enough to unlock the resource no matter how many times you called lock(). Similarly, only the first one of subsequent calls to unlock() actually unlocks. If however you create multiple ResourcesLocker objects on the same ConcurrentResourcesUser object in the same thread, you must unlock all ResourcesLocker to actually unlock resources (see the warning below)
- You can set two or more ResourcesLocker on the same ConcurrentResourcesUser object in the same thread, locking will be recursive (i.e. you will have to unlock the same number of times you have locked to actually unlock)
Constructor & Destructor Documentation
resourcesUser the resource user with the resources to lock acquireLock if true the lock is acquired automatically (and this function will block), if false it is not. It is advised to let the constructor acquire the lock and to let the destructor release them.
Member Function Documentation
The documentation for this class was generated from the following files: