Skip to content

Commit

Permalink
Make reload thread joinable
Browse files Browse the repository at this point in the history
This allows us to cleanly shut down if the reload thread is running
  • Loading branch information
Foereaper committed Jul 17, 2024
1 parent 6b3adff commit 8c6c47c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ElunaLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ ElunaLoader* ElunaLoader::instance()

ElunaLoader::~ElunaLoader()
{
// join any previously created reload thread so it can exit cleanly
if (_reloadThread.joinable())
_reloadThread.join();

#ifdef TRINITY
if (lua_scriptWatcher >= 0)
{
Expand All @@ -88,11 +92,15 @@ void ElunaLoader::ReloadScriptCache()
return;
}

// try to join any previous thread before starting a new one, just in case
if (_reloadThread.joinable())
_reloadThread.join();

// set the internal cache state to reinit
_cacheState = SCRIPT_CACHE_REINIT;

// create new thread to load scripts asynchronously
std::thread(&ElunaLoader::LoadScripts, this).detach();
_reloadThread = std::thread(&ElunaLoader::LoadScripts, this);
ELUNA_LOG_DEBUG("[Eluna]: Script cache reload thread started");
}

Expand Down
1 change: 1 addition & 0 deletions ElunaLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ElunaLoader
#endif
protected:
std::atomic<uint8> _cacheState;
std::thread _reloadThread;
};

#ifdef TRINITY
Expand Down

0 comments on commit 8c6c47c

Please sign in to comment.