Skip to content

Commit

Permalink
threading: some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasdr committed Sep 20, 2023
1 parent 06a67c3 commit f92fd48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
17 changes: 12 additions & 5 deletions src/tdme/os/threading/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class tdme::os::threading::Thread {
/**
* @brief Public constructor
* @param name name
* @param autoDelete delete thread after thread execution has been completed
*/
inline Thread(const string& name): name(name), stopRequested(false) {}
inline Thread(const string& name, bool autoDelete = false): name(name), stopRequested(false), autoDelete(autoDelete) {}

/**
* @brief Public destructor
Expand All @@ -52,14 +53,14 @@ class tdme::os::threading::Thread {
* @brief Blocks caller thread until this thread has been terminated
*/
inline void join() {
stlThread->join();
stlThread.join();
}

/**
* @brief Starts this objects thread
*/
inline virtual void start() {
stlThread = make_unique<thread>(thread(threadRun, (void*)this));
stlThread = thread(threadRun, (void*)this);
}

/**
Expand All @@ -85,10 +86,16 @@ class tdme::os::threading::Thread {

private:
inline static void threadRun(void *thread) {
static_cast<Thread*>(thread)->run();
auto threadPtr = static_cast<Thread*>(thread);
threadPtr->run();
if (threadPtr->autoDelete == true) {
threadPtr->stlThread.detach();
delete threadPtr;
}
}

string name;
unique_ptr<thread> stlThread;
thread stlThread;
volatile bool stopRequested;
bool autoDelete;
};
15 changes: 3 additions & 12 deletions src/tdme/tools/installer/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,13 @@ void Installer::performScreenAction() {
dynamic_cast<GUIElementNode*>(engine->getGUI()->getScreen("installer_installing")->getNodeById("progressbar"))->getController()->setValue(MutableString(0.0f, 2));
class CheckForUpdateThread: public Thread {
public:
CheckForUpdateThread(Installer* installer): Thread("checkforupdate-thread"), installer(installer) {
CheckForUpdateThread(Installer* installer): Thread("checkforupdate-thread", true), installer(installer) {
}

private:
Installer* installer;

void run() {
//
auto thisPtr = unique_ptr<CheckForUpdateThread>(this);

//
Console::println("CheckForUpdateThread::run(): init");

Expand Down Expand Up @@ -490,12 +487,9 @@ void Installer::performScreenAction() {
engine->getGUI()->addRenderScreen(popUps->getInfoDialogScreenController()->getScreenNode()->getId());
class InstallThread: public Thread {
public:
InstallThread(Installer* installer): Thread("install-thread"), installer(installer) {
InstallThread(Installer* installer): Thread("install-thread", true), installer(installer) {
}
void run() {
//
auto thisPtr = unique_ptr<InstallThread>(this);

//
Console::println("InstallThread::run(): init");

Expand Down Expand Up @@ -897,12 +891,9 @@ void Installer::performScreenAction() {
engine->getGUI()->addRenderScreen(popUps->getInfoDialogScreenController()->getScreenNode()->getId());
class UninstallThread: public Thread {
public:
UninstallThread(Installer* installer): Thread("install-thread"), installer(installer) {
UninstallThread(Installer* installer): Thread("install-thread", true), installer(installer) {
}
void run() {
//
auto thisPtr = unique_ptr<UninstallThread>(this);

//
Console::println("UninstallThread::run(): init");

Expand Down

0 comments on commit f92fd48

Please sign in to comment.