Skip to content

Commit

Permalink
Remove signal trapping by ViZDoom thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Sep 8, 2024
1 parent 937e306 commit 625b24b
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 92 deletions.
2 changes: 0 additions & 2 deletions docs/api/cpp/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ The declarations of all the enums can be found in the `include/ViZDoomExceptions

* `MessageQueueException/SharedMemoryException` - means that communication with ViZDoom's instance failed. Usually, means a problem with permissions or system configuration.

* `SignalException` - means that a signal was cached by ViZDoom's instance.

* `ViZDoomErrorException` - means that an error in the ViZDoom engine occurred.

* `ViZDoomIsNotRunningException` - means that called method cannot be used when ViZDoom instance is not running.
Expand Down
6 changes: 0 additions & 6 deletions docs/api/python/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ Means that communication with ViZDoom's instance failed. Usually, means a proble

Means that allocation/reading of shared memory failed. Usually, means a problem with permissions or system configuration.

```{eval-rst}
.. autoexception:: vizdoom.SignalException
```

Means that a signal was cached by ViZDoom's instance.

```{eval-rst}
.. autoexception:: vizdoom.ViZDoomErrorException
```
Expand Down
9 changes: 0 additions & 9 deletions include/ViZDoomExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ namespace vizdoom{
std::string error;
};

class SignalException : public std::exception {
public:
SignalException(std::string signal): signal(signal){}
~SignalException() throw(){}
const char* what() const throw();
private:
std::string signal;
};

class ViZDoomErrorException : public std::exception {
public:
ViZDoomErrorException(){}
Expand Down
55 changes: 0 additions & 55 deletions src/lib/ViZDoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ namespace vizdoom {
this->MQDoom = new MessageQueue(MQ_DOOM_NAME_BASE + this->instanceId);
this->MQController = new MessageQueue(MQ_CTR_NAME_BASE + this->instanceId);

// Signal handle thread
this->signalThread = new b::thread(b::bind(&DoomController::handleSignals, this));

// Doom thread
this->doomThread = new b::thread(b::bind(&DoomController::launchDoom, this));
this->doomRunning = true;
Expand Down Expand Up @@ -221,18 +218,6 @@ namespace vizdoom {
this->MQDoom->send(MSG_CODE_CLOSE);
}

if (this->signalThread && this->signalThread->joinable()) {
this->ioService->stop();

this->signalThread->interrupt();
this->signalThread->join();
delete this->signalThread;
this->signalThread = nullptr;

delete this->ioService;
this->ioService = nullptr;
}

#ifdef OS_POSIX
// If the Doom thread is still running, kill the engine process
if (this->doomThread && !this->doomThread->joinable()) {
Expand Down Expand Up @@ -1142,34 +1127,6 @@ namespace vizdoom {
}
}


/* Signals */
/*----------------------------------------------------------------------------------------------------------------*/

void DoomController::handleSignals() {
this->ioService = new ba::io_service();
ba::signal_set signals(*this->ioService, SIGINT, SIGABRT, SIGTERM);

#if BOOST_VERSION >= 106000
signals.async_wait(b::bind(signalHandler, b::ref(signals), this, bpl::_1, bpl::_2));
#else
signals.async_wait(b::bind(signalHandler, b::ref(signals), this, _1, _2));
#endif

this->ioService->run();
}

void DoomController::signalHandler(ba::signal_set &signal, DoomController *controller, const bs::error_code &error,
int sigNumber) {
controller->intSignal(sigNumber);
}

void DoomController::intSignal(int sigNumber) {
this->MQDoom->send(MSG_CODE_CLOSE);
this->MQController->send(static_cast<uint8_t >(MSG_CODE_SIG + sigNumber));
}


/* Flow */
/*----------------------------------------------------------------------------------------------------------------*/

Expand All @@ -1191,18 +1148,6 @@ namespace vizdoom {
this->close();
throw ViZDoomErrorException(std::string(msg.command));

case MSG_CODE_SIGINT :
this->close();
throw SignalException("SIGINT");

case MSG_CODE_SIGABRT :
this->close();
throw SignalException("SIGABRT");

case MSG_CODE_SIGTERM :
this->close();
throw SignalException("SIGTERM");

default:
this->close();
throw MessageQueueException("Unknown message code. Possible ViZDoom version mismatch.");
Expand Down
19 changes: 0 additions & 19 deletions src/lib/ViZDoomController.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,15 @@ namespace vizdoom {
#define MSG_CODE_COMMAND 24
#define MSG_CODE_CLOSE 25

#define MSG_CODE_SIG 30
#define MSG_CODE_SIGINT 30 + SIGINT
#define MSG_CODE_SIGABRT 30 + SIGABRT
#define MSG_CODE_SIGTERM 30 + SIGTERM

/* OSes */
#ifdef __linux__
#define OS_LINUX
#define OS_POSIX
#include <sys/types.h>
#include <signal.h>
#elif _WIN32
#define OS_WIN
#elif __APPLE__
#define OS_OSX
#define OS_POSIX
#include <sys/types.h>
#include <signal.h>
#endif

class DoomController {
Expand Down Expand Up @@ -322,16 +313,6 @@ namespace vizdoom {
/* Threads */
/*------------------------------------------------------------------------------------------------------------*/

ba::io_service *ioService;
b::thread *signalThread;

void handleSignals();

static void signalHandler(ba::signal_set &signal, DoomController *controller,
const bs::error_code &error, int sigNumber);

void intSignal(int sigNumber);

b::thread *doomThread;

#ifdef OS_POSIX
Expand Down
1 change: 0 additions & 1 deletion src/lib_python/ViZDoomPythonModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ PYBIND11_MODULE(vizdoom, vz){
EXCEPTION_TO_PYT(FileDoesNotExistException)
EXCEPTION_TO_PYT(MessageQueueException)
EXCEPTION_TO_PYT(SharedMemoryException)
EXCEPTION_TO_PYT(SignalException)
EXCEPTION_TO_PYT(ViZDoomIsNotRunningException)
EXCEPTION_TO_PYT(ViZDoomErrorException)
EXCEPTION_TO_PYT(ViZDoomUnexpectedExitException)
Expand Down

0 comments on commit 625b24b

Please sign in to comment.