mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
fix(Event): Event data race #3629
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -38,10 +39,10 @@ protected:
|
|||||||
void resetImpl();
|
void resetImpl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _auto;
|
bool _auto;
|
||||||
volatile bool _state;
|
std::atomic<bool> _state;
|
||||||
pthread_mutex_t _mutex;
|
pthread_mutex_t _mutex;
|
||||||
pthread_cond_t _cond;
|
pthread_cond_t _cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ private:
|
|||||||
//
|
//
|
||||||
inline void EventImpl::setImpl()
|
inline void EventImpl::setImpl()
|
||||||
{
|
{
|
||||||
if (pthread_mutex_lock(&_mutex))
|
if (pthread_mutex_lock(&_mutex))
|
||||||
throw SystemException("cannot signal event (lock)");
|
throw SystemException("cannot signal event (lock)");
|
||||||
_state = true;
|
_state = true;
|
||||||
if (pthread_cond_broadcast(&_cond))
|
if (pthread_cond_broadcast(&_cond))
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ protected:
|
|||||||
void resetImpl();
|
void resetImpl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HANDLE _event;
|
std::atomic<HANDLE> _event;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,10 @@ EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
|
|||||||
|
|
||||||
EventImpl::~EventImpl()
|
EventImpl::~EventImpl()
|
||||||
{
|
{
|
||||||
pthread_cond_destroy(&_cond);
|
if (0 == pthread_mutex_lock(&_mutex))
|
||||||
|
pthread_cond_destroy(&_cond);
|
||||||
|
else poco_unexpected();
|
||||||
|
pthread_mutex_unlock(&_mutex);
|
||||||
pthread_mutex_destroy(&_mutex);
|
pthread_mutex_destroy(&_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user