Skip to content
Snippets Groups Projects
Commit 1ae460bc authored by Ramin Yaghoubzadeh's avatar Ramin Yaghoubzadeh
Browse files

Added Locker class (stack-based auto-releasing mutex holder).

parent 7dbda5be
No related branches found
No related tags found
No related merge requests found
...@@ -150,6 +150,20 @@ class Lock ...@@ -150,6 +150,20 @@ class Lock
} }
}; };
/// Stack-based lock holder. Create in a new stack frame
/// (i.e. {}-block) and it will obtain the lock and
/// auto-release in on exiting the stack frame.
class Locker
{
protected:
Lock* _lock;
private:
inline Locker(): _lock(NULL) { } // not available
public:
inline Locker(Lock& lock): _lock(&lock) { _lock->lock(); }
inline ~Locker() { _lock->unlock(); }
};
typedef std::set<std::string> LinkSet; typedef std::set<std::string> LinkSet;
typedef std::map<std::string, LinkSet> LinkMap; typedef std::map<std::string, LinkSet> LinkMap;
class SmartLinkMap { class SmartLinkMap {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment