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

Added a Locker class for already existing raw pthread_mutexes

parent 86d54e1b
No related branches found
No related tags found
No related merge requests found
...@@ -129,6 +129,18 @@ class RemotePushIUStore: public std::map<std::string, boost::shared_ptr<RemotePu ...@@ -129,6 +129,18 @@ class RemotePushIUStore: public std::map<std::string, boost::shared_ptr<RemotePu
{ {
}; };
class Exception: public std::exception//{{{
{
protected:
std::string _description;
public:
inline Exception(const std::string& description=""): _description(description) { }
inline ~Exception() throw() { }
const char* what() const throw() {
return _description.c_str();
}
};//}}}
/// a reentrant lock/mutex /// a reentrant lock/mutex
class Lock class Lock
{ {
...@@ -163,8 +175,29 @@ class Locker ...@@ -163,8 +175,29 @@ class Locker
private: private:
inline Locker(): _lock(NULL) { } // not available inline Locker(): _lock(NULL) { } // not available
public: public:
inline Locker(Lock& lock): _lock(&lock) { _lock->lock(); } inline Locker(Lock& lock): _lock(&lock) {
inline ~Locker() { _lock->unlock(); } //std::cout << "-- Locker: lock" << std::endl;
_lock->lock();
}
inline ~Locker() {
//std::cout << "-- Locker: unlock" << std::endl;
_lock->unlock();
}
};
class PthreadMutexLocker
{
protected:
pthread_mutex_t* _lock;
private:
inline PthreadMutexLocker(): _lock(NULL) { } // not available
public:
inline PthreadMutexLocker(pthread_mutex_t* lock): _lock(lock) {
if (!lock) throw Exception("PthreadMutexLocker got a NULL mutex!");
pthread_mutex_lock(_lock);
}
inline ~PthreadMutexLocker() {
pthread_mutex_unlock(_lock);
}
}; };
typedef std::set<std::string> LinkSet; typedef std::set<std::string> LinkSet;
...@@ -663,17 +696,6 @@ class RemoteMessage: public IUInterface {//{{{ ...@@ -663,17 +696,6 @@ class RemoteMessage: public IUInterface {//{{{
typedef boost::shared_ptr<RemoteMessage> ptr; typedef boost::shared_ptr<RemoteMessage> ptr;
};//}}} };//}}}
class Exception: public std::exception//{{{
{
protected:
std::string _description;
inline Exception(const std::string& description=""): _description(description) { }
public:
inline ~Exception() throw() { }
const char* what() const throw() {
return _description.c_str();
}
};//}}}
class IUNotFoundError: public Exception//{{{ class IUNotFoundError: public Exception//{{{
{ {
public: public:
......
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