mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Remove unneeded async_job - plug memory leak in cheevos.c
This commit is contained in:
parent
bf04b798fe
commit
e7aedb6fb9
@ -513,7 +513,6 @@ ifeq ($(HAVE_THREADS), 1)
|
|||||||
OBJ += autosave.o \
|
OBJ += autosave.o \
|
||||||
libretro-common/rthreads/rthreads.o \
|
libretro-common/rthreads/rthreads.o \
|
||||||
libretro-common/rthreads/rsemaphore.o \
|
libretro-common/rthreads/rsemaphore.o \
|
||||||
libretro-common/rthreads/async_job.o \
|
|
||||||
gfx/video_thread_wrapper.o \
|
gfx/video_thread_wrapper.o \
|
||||||
audio/audio_thread_wrapper.o
|
audio/audio_thread_wrapper.o
|
||||||
DEFINES += -DHAVE_THREADS
|
DEFINES += -DHAVE_THREADS
|
||||||
|
@ -1978,7 +1978,11 @@ static unsigned cheevos_find_game_id_nes(
|
|||||||
uint8_t * data = (uint8_t *) malloc(rom_size << 14);
|
uint8_t * data = (uint8_t *) malloc(rom_size << 14);
|
||||||
|
|
||||||
if (!file || !data)
|
if (!file || !data)
|
||||||
|
{
|
||||||
|
if (file)
|
||||||
|
filestream_close(file);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* from fceu core - need it for a correctly md5 sum */
|
/* from fceu core - need it for a correctly md5 sum */
|
||||||
memset(data, 0xFF, rom_size << 14);
|
memset(data, 0xFF, rom_size << 14);
|
||||||
|
@ -788,7 +788,6 @@ THREAD
|
|||||||
#elif defined(HAVE_THREADS)
|
#elif defined(HAVE_THREADS)
|
||||||
#include "../libretro-common/rthreads/rthreads.c"
|
#include "../libretro-common/rthreads/rthreads.c"
|
||||||
#include "../libretro-common/rthreads/rsemaphore.c"
|
#include "../libretro-common/rthreads/rsemaphore.c"
|
||||||
#include "../libretro-common/rthreads/async_job.c"
|
|
||||||
#include "../gfx/video_thread_wrapper.c"
|
#include "../gfx/video_thread_wrapper.c"
|
||||||
#include "../audio/audio_thread_wrapper.c"
|
#include "../audio/audio_thread_wrapper.c"
|
||||||
#include "../autosave.c"
|
#include "../autosave.c"
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
/* Copyright (C) 2010-2015 The RetroArch team
|
|
||||||
*
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
* The following license statement only applies to this file (async_job.h).
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge,
|
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
||||||
* to deal in the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
||||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_ASYNC_JOB_H
|
|
||||||
#define __LIBRETRO_SDK_ASYNC_JOB_H
|
|
||||||
|
|
||||||
typedef struct async_job async_job_t;
|
|
||||||
typedef void (*async_task_t)(void *payload);
|
|
||||||
|
|
||||||
async_job_t *async_job_new(void);
|
|
||||||
|
|
||||||
void async_job_free(async_job_t *ajob);
|
|
||||||
|
|
||||||
int async_job_add(async_job_t *ajob, async_task_t task, void *payload);
|
|
||||||
|
|
||||||
#endif /* __LIBRETRO_SDK_ASYNC_JOB_H */
|
|
@ -1,150 +0,0 @@
|
|||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
|
||||||
*
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
* The following license statement only applies to this file (async_job.c).
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge,
|
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
||||||
* to deal in the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
||||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <rthreads/rthreads.h>
|
|
||||||
#include <rthreads/rsemaphore.h>
|
|
||||||
#include <rthreads/async_job.h>
|
|
||||||
|
|
||||||
typedef struct async_job_node async_job_node_t;
|
|
||||||
|
|
||||||
struct async_job_node
|
|
||||||
{
|
|
||||||
async_task_t task;
|
|
||||||
void *payload;
|
|
||||||
async_job_node_t *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct async_job
|
|
||||||
{
|
|
||||||
async_job_node_t *first;
|
|
||||||
async_job_node_t *last;
|
|
||||||
volatile int finish;
|
|
||||||
slock_t *lock;
|
|
||||||
ssem_t *sem;
|
|
||||||
sthread_t* thread;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void async_job_processor(void *userdata)
|
|
||||||
{
|
|
||||||
async_job_node_t *node = NULL;
|
|
||||||
async_job_t *ajob = (async_job_t*)userdata;
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
ssem_wait(ajob->sem);
|
|
||||||
|
|
||||||
if (ajob->finish)
|
|
||||||
return;
|
|
||||||
|
|
||||||
slock_lock(ajob->lock);
|
|
||||||
|
|
||||||
node = ajob->first;
|
|
||||||
ajob->first = node->next;
|
|
||||||
|
|
||||||
slock_unlock(ajob->lock);
|
|
||||||
|
|
||||||
node->task(node->payload);
|
|
||||||
free((void*)node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_job_t *async_job_new(void)
|
|
||||||
{
|
|
||||||
async_job_t *ajob = (async_job_t*)calloc(1, sizeof(*ajob));
|
|
||||||
|
|
||||||
if (!ajob)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ajob->lock = slock_new();
|
|
||||||
|
|
||||||
if (!ajob->lock)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
ajob->sem = ssem_new(0);
|
|
||||||
|
|
||||||
if (!ajob->sem)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
ajob->thread = sthread_create(async_job_processor, (void*)ajob);
|
|
||||||
|
|
||||||
if (!ajob->thread)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return ajob;
|
|
||||||
|
|
||||||
error:
|
|
||||||
if (ajob->lock)
|
|
||||||
slock_free(ajob->lock);
|
|
||||||
ajob->lock = NULL;
|
|
||||||
if (ajob->sem)
|
|
||||||
ssem_free(ajob->sem);
|
|
||||||
if (ajob)
|
|
||||||
free((void*)ajob);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void async_job_free(async_job_t *ajob)
|
|
||||||
{
|
|
||||||
if (!ajob)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ajob->finish = 1;
|
|
||||||
ssem_signal(ajob->sem);
|
|
||||||
sthread_join(ajob->thread);
|
|
||||||
slock_free(ajob->lock);
|
|
||||||
ssem_free(ajob->sem);
|
|
||||||
|
|
||||||
free((void*)ajob);
|
|
||||||
}
|
|
||||||
|
|
||||||
int async_job_add(async_job_t *ajob, async_task_t task, void *payload)
|
|
||||||
{
|
|
||||||
async_job_node_t *node;
|
|
||||||
|
|
||||||
if (!ajob)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
node = (async_job_node_t*)calloc(1, sizeof(*node));
|
|
||||||
|
|
||||||
if (!node)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
node->task = task;
|
|
||||||
node->payload = payload;
|
|
||||||
|
|
||||||
slock_lock(ajob->lock);
|
|
||||||
|
|
||||||
if (ajob->first)
|
|
||||||
{
|
|
||||||
ajob->last->next = node;
|
|
||||||
ajob->last = node;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ajob->first = ajob->last = node;
|
|
||||||
|
|
||||||
slock_unlock(ajob->lock);
|
|
||||||
ssem_signal(ajob->sem);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user