(Autosave) Change/improve exit behavior of autosave thread -

if condition variable is signaled, the loop is ran another
last time so we can do a final check/save before stopping the thread.
Old commit courtesy of tobiasjakobi
This commit is contained in:
LibretroAdmin 2022-09-03 00:21:58 +02:00
parent 8f14143859
commit 654203be0a

View File

@ -141,7 +141,7 @@ struct autosave
sthread_t *thread;
size_t bufsize;
unsigned interval;
volatile bool quit;
bool quit;
bool compress_files;
};
#endif
@ -187,13 +187,13 @@ static void autosave_thread(void *data)
{
autosave_t *save = (autosave_t*)data;
while (!save->quit)
for (;;)
{
bool differ;
slock_lock(save->lock);
differ = string_is_not_equal_fast(save->buffer, save->retro_buffer,
save->bufsize);
differ = memcmp(save->buffer, save->retro_buffer,
save->bufsize) != 0;
if (differ)
memcpy(save->buffer, save->retro_buffer, save->bufsize);
slock_unlock(save->lock);
@ -221,17 +221,21 @@ static void autosave_thread(void *data)
slock_lock(save->cond_lock);
if (!save->quit)
if (save->quit)
{
#if defined(_MSC_VER) && _MSC_VER <= 1200
int64_t timeout_us = 1000000;
#else
int64_t timeout_us = 1000000LL;
#endif
scond_wait_timeout(save->cond, save->cond_lock,
save->interval * timeout_us);
slock_unlock(save->cond_lock);
break;
}
scond_wait_timeout(save->cond,
save->cond_lock,
#if defined(_MSC_VER) && _MSC_VER <= 1200
save->interval * 1000000
#else
save->interval * 1000000LL
#endif
);
slock_unlock(save->cond_lock);
}
}