Fixed bug with event notifier being notified with a bad eventfd
This commit is contained in:
@@ -32,7 +32,6 @@ void DebugServer::startup() {
|
|||||||
this->eventManager.registerListener(this->eventListener);
|
this->eventManager.registerListener(this->eventListener);
|
||||||
|
|
||||||
this->interruptEventNotifier = std::make_shared<EventNotifier>();
|
this->interruptEventNotifier = std::make_shared<EventNotifier>();
|
||||||
this->interruptEventNotifier->init();
|
|
||||||
this->eventListener->setInterruptEventNotifier(this->interruptEventNotifier);
|
this->eventListener->setInterruptEventNotifier(this->interruptEventNotifier);
|
||||||
|
|
||||||
// Register event handlers
|
// Register event handlers
|
||||||
@@ -52,8 +51,8 @@ void DebugServer::shutdown() {
|
|||||||
this->setThreadState(ThreadState::SHUTDOWN_INITIATED);
|
this->setThreadState(ThreadState::SHUTDOWN_INITIATED);
|
||||||
Logger::info("Shutting down DebugServer");
|
Logger::info("Shutting down DebugServer");
|
||||||
this->close();
|
this->close();
|
||||||
this->interruptEventNotifier->close();
|
|
||||||
this->setThreadStateAndEmitEvent(ThreadState::STOPPED);
|
this->setThreadStateAndEmitEvent(ThreadState::STOPPED);
|
||||||
|
this->eventManager.deregisterListener(this->eventListener->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugServer::onShutdownDebugServerEvent(EventPointer<Events::ShutdownDebugServer> event) {
|
void DebugServer::onShutdownDebugServerEvent(EventPointer<Events::ShutdownDebugServer> event) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ void EventListener::registerEvent(GenericEventPointer event) {
|
|||||||
eventQueueByType[eventName].push(event);
|
eventQueueByType[eventName].push(event);
|
||||||
this->eventQueueByEventTypeCV.notify_all();
|
this->eventQueueByEventTypeCV.notify_all();
|
||||||
|
|
||||||
if (this->interruptEventNotifier != nullptr) {
|
if (this->interruptEventNotifier != nullptr && this->interruptEventNotifier->isInitialised()) {
|
||||||
this->interruptEventNotifier->notify();
|
this->interruptEventNotifier->notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
@@ -26,9 +27,7 @@ namespace Bloom
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int fileDescriptor = -1;
|
int fileDescriptor = -1;
|
||||||
|
std::atomic<bool> initialised = false;
|
||||||
public:
|
|
||||||
EventNotifier() = default;
|
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
||||||
@@ -37,12 +36,34 @@ namespace Bloom
|
|||||||
throw Exceptions::Exception("Failed to create new eventfd object - error number: "
|
throw Exceptions::Exception("Failed to create new eventfd object - error number: "
|
||||||
+ std::to_string(errno));
|
+ std::to_string(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->initialised = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
::close(this->fileDescriptor);
|
||||||
|
this->initialised = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
EventNotifier() {
|
||||||
|
this->init();
|
||||||
|
};
|
||||||
|
|
||||||
|
~EventNotifier() {
|
||||||
|
if (this->initialised) {
|
||||||
|
this->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getFileDescriptor() {
|
int getFileDescriptor() {
|
||||||
return this->fileDescriptor;
|
return this->fileDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isInitialised() {
|
||||||
|
return this->initialised;
|
||||||
|
}
|
||||||
|
|
||||||
void notify() {
|
void notify() {
|
||||||
if (::eventfd_write(this->fileDescriptor, 1) < 0) {
|
if (::eventfd_write(this->fileDescriptor, 1) < 0) {
|
||||||
throw Exceptions::Exception("Failed to increment eventfd counter - error number: "
|
throw Exceptions::Exception("Failed to increment eventfd counter - error number: "
|
||||||
@@ -57,9 +78,5 @@ namespace Bloom
|
|||||||
"error number: " + std::to_string(errno));
|
"error number: " + std::to_string(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void close() {
|
|
||||||
::close(this->fileDescriptor);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user