PIPeer important fix!
git-svn-id: svn://db.shs.com.ru/pip@110 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -47,6 +47,7 @@ PIMutex::PIMutex() {
|
||||
pthread_mutex_init(&mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +57,7 @@ PIMutex::~PIMutex() {
|
||||
#else
|
||||
pthread_mutex_destroy(&mutex);
|
||||
#endif
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +67,7 @@ void PIMutex::lock() {
|
||||
#else
|
||||
pthread_mutex_lock(&mutex);
|
||||
#endif
|
||||
locked = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +77,22 @@ void PIMutex::unlock() {
|
||||
#else
|
||||
pthread_mutex_unlock(&mutex);
|
||||
#endif
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
||||
bool PIMutex::tryLock() {
|
||||
bool ret =
|
||||
#ifdef WINDOWS
|
||||
return (WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
|
||||
(WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
|
||||
#else
|
||||
return (pthread_mutex_trylock(&mutex) == 0);
|
||||
(pthread_mutex_trylock(&mutex) == 0);
|
||||
#endif
|
||||
locked = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PIMutex::isLocked() const {
|
||||
return locked;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
//! If mutex is already locked function returns immediate an returns "false"
|
||||
bool tryLock();
|
||||
|
||||
//! Returns if mutex is locked
|
||||
bool isLocked() const;
|
||||
|
||||
private:
|
||||
#ifdef WINDOWS
|
||||
void *
|
||||
@@ -56,6 +59,7 @@ private:
|
||||
pthread_mutex_t
|
||||
#endif
|
||||
mutex;
|
||||
bool locked;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user