(autosave.c) Cleanups
This commit is contained in:
parent
0bd38a5e1d
commit
fe8a502488
34
autosave.c
34
autosave.c
|
@ -55,28 +55,6 @@ struct autosave
|
||||||
|
|
||||||
static struct autosave_st autosave_state;
|
static struct autosave_st autosave_state;
|
||||||
|
|
||||||
/**
|
|
||||||
* autosave_lock:
|
|
||||||
* @handle : pointer to autosave object
|
|
||||||
*
|
|
||||||
* Locks autosave.
|
|
||||||
**/
|
|
||||||
static void autosave_lock(autosave_t *handle)
|
|
||||||
{
|
|
||||||
slock_lock(handle->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* autosave_unlock:
|
|
||||||
* @handle : pointer to autosave object
|
|
||||||
*
|
|
||||||
* Unlocks autosave.
|
|
||||||
**/
|
|
||||||
static void autosave_unlock(autosave_t *handle)
|
|
||||||
{
|
|
||||||
slock_unlock(handle->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* autosave_thread:
|
* autosave_thread:
|
||||||
* @data : pointer to autosave object
|
* @data : pointer to autosave object
|
||||||
|
@ -85,19 +63,19 @@ static void autosave_unlock(autosave_t *handle)
|
||||||
**/
|
**/
|
||||||
static void autosave_thread(void *data)
|
static void autosave_thread(void *data)
|
||||||
{
|
{
|
||||||
bool first_log = true;
|
bool first_log = true;
|
||||||
autosave_t *save = (autosave_t*)data;
|
autosave_t *save = (autosave_t*)data;
|
||||||
|
|
||||||
while (!save->quit)
|
while (!save->quit)
|
||||||
{
|
{
|
||||||
bool differ;
|
bool differ;
|
||||||
|
|
||||||
autosave_lock(save);
|
slock_lock(save->lock);
|
||||||
differ = memcmp(save->buffer, save->retro_buffer,
|
differ = memcmp(save->buffer, save->retro_buffer,
|
||||||
save->bufsize) != 0;
|
save->bufsize) != 0;
|
||||||
if (differ)
|
if (differ)
|
||||||
memcpy(save->buffer, save->retro_buffer, save->bufsize);
|
memcpy(save->buffer, save->retro_buffer, save->bufsize);
|
||||||
autosave_unlock(save);
|
slock_unlock(save->lock);
|
||||||
|
|
||||||
if (differ)
|
if (differ)
|
||||||
{
|
{
|
||||||
|
@ -153,7 +131,7 @@ static autosave_t *autosave_new(const char *path,
|
||||||
const void *data, size_t size,
|
const void *data, size_t size,
|
||||||
unsigned interval)
|
unsigned interval)
|
||||||
{
|
{
|
||||||
autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
|
autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
|
||||||
if (!handle)
|
if (!handle)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -219,7 +197,7 @@ void lock_autosave(void)
|
||||||
for (i = 0; i < autosave_state.num; i++)
|
for (i = 0; i < autosave_state.num; i++)
|
||||||
{
|
{
|
||||||
if (autosave_state.list[i])
|
if (autosave_state.list[i])
|
||||||
autosave_lock(autosave_state.list[i]);
|
slock_lock(autosave_state.list[i]->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +213,7 @@ void unlock_autosave(void)
|
||||||
for (i = 0; i < autosave_state.num; i++)
|
for (i = 0; i < autosave_state.num; i++)
|
||||||
{
|
{
|
||||||
if (autosave_state.list[i])
|
if (autosave_state.list[i])
|
||||||
autosave_unlock(autosave_state.list[i]);
|
slock_unlock(autosave_state.list[i]->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue