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 <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <atomic>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -38,10 +39,10 @@ protected:
|
||||
void resetImpl();
|
||||
|
||||
private:
|
||||
bool _auto;
|
||||
volatile bool _state;
|
||||
pthread_mutex_t _mutex;
|
||||
pthread_cond_t _cond;
|
||||
bool _auto;
|
||||
std::atomic<bool> _state;
|
||||
pthread_mutex_t _mutex;
|
||||
pthread_cond_t _cond;
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +51,7 @@ private:
|
||||
//
|
||||
inline void EventImpl::setImpl()
|
||||
{
|
||||
if (pthread_mutex_lock(&_mutex))
|
||||
if (pthread_mutex_lock(&_mutex))
|
||||
throw SystemException("cannot signal event (lock)");
|
||||
_state = true;
|
||||
if (pthread_cond_broadcast(&_cond))
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@@ -37,7 +37,7 @@ protected:
|
||||
void resetImpl();
|
||||
|
||||
private:
|
||||
HANDLE _event;
|
||||
std::atomic<HANDLE> _event;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,10 @@ EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user