Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/DOF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@
#include "Pinball.h"
#include "general/StringExtensions.h"

#ifdef __HIDAPI__
#include <hidapi/hidapi.h>
#endif

namespace DOF
{

DOF::DOF()
: m_pinball(new Pinball())
{
#ifdef __HIDAPI__
hid_init();
#endif
m_pinball = new Pinball();
}

DOF::~DOF() { delete m_pinball; }
DOF::~DOF()
{
delete m_pinball;
#ifdef __HIDAPI__
hid_exit();
#endif
}

void DOF::Init(const char* tableFilename, const char* romName)
{
Expand Down
6 changes: 0 additions & 6 deletions src/cab/Cabinet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sstream>

#ifdef __HIDAPI__
#include <hidapi/hidapi.h>
#include "out/ps/Pinscape.h"
#include "out/ps/PinscapeAutoConfigurator.h"
#include "out/pspico/PinscapePico.h"
Expand Down Expand Up @@ -48,8 +47,6 @@ Cabinet::Cabinet()
m_colors = new ColorList();

#ifdef __HIDAPI__
hid_init();

Pinscape::Initialize();
PinscapePico::Initialize();
#endif
Expand Down Expand Up @@ -83,9 +80,6 @@ Cabinet::~Cabinet()
delete m_outputControllers;
m_outputControllers = nullptr;
}
#ifdef __HIDAPI__
hid_exit();
#endif
}

void Cabinet::AutoConfig()
Expand Down
28 changes: 16 additions & 12 deletions src/cab/out/OutputControllerCompleteBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,29 @@ void OutputControllerCompleteBase::FinishUpdaterThread()
{
if (m_updaterThread && m_updaterThread->joinable())
{
try
{
m_keepUpdaterThreadAlive = false;
UpdaterThreadSignal();
m_keepUpdaterThreadAlive = false;
UpdaterThreadSignal();

auto future = std::async(std::launch::async, [this]() { m_updaterThread->join(); });
auto start = std::chrono::steady_clock::now();
bool joined = false;

if (future.wait_for(std::chrono::milliseconds(1000)) == std::future_status::timeout)
while (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count() < 1000)
{
if (!IsUpdaterThreadActive())
{
Log::Warning("Updater thread did not quit within timeout. Thread termination may be forceful.");
m_updaterThread->detach();
m_updaterThread->join();
joined = true;
break;
}

m_updaterThread.reset();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
catch (const std::exception& e)

if (!joined)
{
Log::Exception(StringExtensions::Build("Error occurred during termination of updater thread: {0}", e.what()));
Log::Warning("Updater thread did not quit within timeout. Thread termination may be forceful.");
m_updaterThread->detach();
}
m_updaterThread.reset();
}
}

Expand Down
Loading