Skip to content

Commit

Permalink
substitute jthread for thread
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Dec 17, 2023
1 parent adc988e commit 4468e7a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Cafe/HW/Latte/Core/LatteShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,9 @@ void LatteShaderCache_handleDeprecatedCacheFiles(fs::path pathGeneric, fs::path
}

constexpr sint32 samplesPerBlock = 4800;
static std::atomic<bool> audiothread_keeprunning = true;

void LatteShaderCache_StreamBootSound(const std::stop_token& token)
void LatteShaderCache_StreamBootSound()
{
AudioAPIPtr bootSndAudioDev;
std::unique_ptr<BootSoundReader> bootSndFileReader;
Expand Down Expand Up @@ -850,7 +851,7 @@ void LatteShaderCache_StreamBootSound(const std::stop_token& token)

if(bootSndAudioDev && bootSndFileHandle && bootSndFileReader)
{
while(!token.stop_requested())
while(audiothread_keeprunning)
{
if (bootSndAudioDev->NeedAdditionalBlocks())
bootSndAudioDev->FeedBlock(bootSndFileReader->getSamples());
Expand All @@ -863,14 +864,18 @@ void LatteShaderCache_StreamBootSound(const std::stop_token& token)
fsc_close(bootSndFileHandle);
}

static std::jthread g_bootSndPlayThread;
static std::thread g_bootSndPlayThread;
void LatteShaderCache_InitBootSound()
{
audiothread_keeprunning = true;
if(!g_bootSndPlayThread.joinable())
g_bootSndPlayThread = std::jthread{LatteShaderCache_StreamBootSound};
g_bootSndPlayThread = std::thread{LatteShaderCache_StreamBootSound};
}

void LatteShaderCache_ShutdownBootSound()
{
audiothread_keeprunning = false;
if(g_bootSndPlayThread.joinable())
g_bootSndPlayThread.join();
g_bootSndPlayThread = {};
}

0 comments on commit 4468e7a

Please sign in to comment.