Get rid of HAVE_THREADS macros

This commit is contained in:
libretroadmin 2022-07-06 15:01:53 +02:00
parent b6c9740ba3
commit 821bb86b37
4 changed files with 176 additions and 98 deletions

View File

@ -39,14 +39,6 @@
#include "../tasks/task_content.h"
#include "../tasks/tasks_internal.h"
#ifdef HAVE_THREADS
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
#endif
#define BASE_FONT_SIZE 32.0f
#define MSG_QUEUE_FONT_SIZE (BASE_FONT_SIZE * 0.69f)
@ -457,7 +449,9 @@ static void gfx_widgets_msg_queue_move(dispgfx_widget_t *p_dispwidget)
/* there should always be one and only one unfolded message */
disp_widget_msg_t *unfold = NULL;
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_lock(p_dispwidget->current_msgs_lock);
#endif
for (i = (int)(p_dispwidget->current_msgs_size - 1); i >= 0; i--)
{
@ -490,7 +484,9 @@ static void gfx_widgets_msg_queue_move(dispgfx_widget_t *p_dispwidget)
}
}
SLOCK_UNLOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_unlock(p_dispwidget->current_msgs_lock);
#endif
}
static void gfx_widgets_msg_queue_free(
@ -539,10 +535,11 @@ static void gfx_widgets_msg_queue_kill_end(void *userdata)
disp_widget_msg_t* msg;
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_lock(p_dispwidget->current_msgs_lock);
#endif
msg = p_dispwidget->current_msgs[p_dispwidget->msg_queue_kill];
if (msg)
if ((msg = p_dispwidget->current_msgs[p_dispwidget->msg_queue_kill]))
{
/* Remove it from the list */
for (i = p_dispwidget->msg_queue_kill; i < p_dispwidget->current_msgs_size - 1; i++)
@ -558,7 +555,9 @@ static void gfx_widgets_msg_queue_kill_end(void *userdata)
free(msg);
}
SLOCK_UNLOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_unlock(p_dispwidget->current_msgs_lock);
#endif
}
static void gfx_widgets_msg_queue_kill(
@ -988,7 +987,9 @@ void gfx_widgets_iterate(
{
disp_widget_msg_t *msg_widget = NULL;
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_lock(p_dispwidget->current_msgs_lock);
#endif
if (p_dispwidget->current_msgs_size < ARRAY_SIZE(p_dispwidget->current_msgs))
{
@ -1015,7 +1016,9 @@ void gfx_widgets_iterate(
}
}
SLOCK_UNLOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_unlock(p_dispwidget->current_msgs_lock);
#endif
if (msg_widget)
{
@ -1744,7 +1747,9 @@ void gfx_widgets_frame(void *data)
/* Draw all messages */
if (p_dispwidget->current_msgs_size)
{
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_lock(p_dispwidget->current_msgs_lock);
#endif
for (i = 0; i < p_dispwidget->current_msgs_size; i++)
{
@ -1769,7 +1774,9 @@ void gfx_widgets_frame(void *data)
video_width, video_height);
}
SLOCK_UNLOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_unlock(p_dispwidget->current_msgs_lock);
#endif
}
/* Ensure all text is flushed */
@ -1831,7 +1838,9 @@ static void gfx_widgets_free(dispgfx_widget_t *p_dispwidget)
fifo_deinitialize(&p_dispwidget->msg_queue);
/* Purge everything from the list */
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_lock(p_dispwidget->current_msgs_lock);
#endif
p_dispwidget->current_msgs_size = 0;
for (i = 0; i < ARRAY_SIZE(p_dispwidget->current_msgs); i++)
@ -1852,9 +1861,9 @@ static void gfx_widgets_free(dispgfx_widget_t *p_dispwidget)
gfx_widgets_msg_queue_free(p_dispwidget, msg);
}
SLOCK_UNLOCK(p_dispwidget->current_msgs_lock);
#ifdef HAVE_THREADS
slock_unlock(p_dispwidget->current_msgs_lock);
slock_free(p_dispwidget->current_msgs_lock);
p_dispwidget->current_msgs_lock = NULL;
#endif

View File

@ -20,14 +20,6 @@
#include "../cheevos/cheevos.h"
#ifdef HAVE_THREADS
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
#endif
#define CHEEVO_NOTIFICATION_DURATION 4000
#define CHEEVO_QUEUE_SIZE 8
@ -84,12 +76,14 @@ static void gfx_widget_achievement_popup_free_all(gfx_widget_achievement_popup_s
{
if (state->queue_read_index >= 0)
{
SLOCK_LOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_lock(state->queue_lock);
#endif
while (state->queue[state->queue_read_index].title)
gfx_widget_achievement_popup_free_current(state);
SLOCK_UNLOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_unlock(state->queue_lock);
#endif
}
}
@ -123,7 +117,9 @@ static void gfx_widget_achievement_popup_frame(void* data, void* userdata)
|| !state->queue[state->queue_read_index].title)
return;
SLOCK_LOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_lock(state->queue_lock);
#endif
{
static float pure_white[16] = {
@ -266,7 +262,9 @@ static void gfx_widget_achievement_popup_frame(void* data, void* userdata)
}
}
SLOCK_UNLOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_unlock(state->queue_lock);
#endif
}
static void gfx_widget_achievement_popup_free_current(
@ -297,7 +295,9 @@ static void gfx_widget_achievement_popup_next(void* userdata)
{
gfx_widget_achievement_popup_state_t *state = &p_w_achievement_popup_st;
SLOCK_LOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_lock(state->queue_lock);
#endif
if (state->queue_read_index >= 0)
{
@ -309,7 +309,9 @@ static void gfx_widget_achievement_popup_next(void* userdata)
gfx_widget_achievement_popup_start(state);
}
SLOCK_UNLOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_unlock(state->queue_lock);
#endif
}
static void gfx_widget_achievement_popup_dismiss(void *userdata)
@ -429,14 +431,18 @@ void gfx_widgets_push_achievement(const char *title, const char* subtitle, const
#endif
}
SLOCK_LOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_lock(state->queue_lock);
#endif
if (state->queue_write_index == state->queue_read_index)
{
if (state->queue[state->queue_write_index].title)
{
/* queue full */
SLOCK_UNLOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_unlock(state->queue_lock);
#endif
return;
}
@ -454,7 +460,9 @@ void gfx_widgets_push_achievement(const char *title, const char* subtitle, const
if (start_notification)
gfx_widget_achievement_popup_start(state);
SLOCK_UNLOCK(state->queue_lock);
#ifdef HAVE_THREADS
slock_unlock(state->queue_lock);
#endif
}
const gfx_widget_t gfx_widget_achievement_popup = {

View File

@ -20,14 +20,6 @@
#include "../cheevos/cheevos.h"
#ifdef HAVE_THREADS
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
#endif
#define CHEEVO_LBOARD_ARRAY_SIZE 4
#define CHEEVO_CHALLENGE_ARRAY_SIZE 8
@ -53,8 +45,8 @@ struct gfx_widget_leaderboard_display_state
#endif
const dispgfx_widget_t *dispwidget_ptr;
struct leaderboard_display_info tracker_info[CHEEVO_LBOARD_ARRAY_SIZE];
unsigned tracker_count;
struct challenge_display_info challenge_info[CHEEVO_CHALLENGE_ARRAY_SIZE];
unsigned tracker_count;
unsigned challenge_count;
};
@ -104,7 +96,10 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
if (state->tracker_count == 0 && state->challenge_count == 0)
return;
SLOCK_LOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_lock(state->array_lock);
#endif
{
static float pure_white[16] = {
1.00, 1.00, 1.00, 1.00,
@ -216,7 +211,9 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
}
}
SLOCK_UNLOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_unlock(state->array_lock);
#endif
}
void gfx_widgets_set_leaderboard_display(unsigned id, const char* value)
@ -224,7 +221,9 @@ void gfx_widgets_set_leaderboard_display(unsigned id, const char* value)
unsigned i;
gfx_widget_leaderboard_display_state_t *state = &p_w_leaderboard_display_st;
SLOCK_LOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_lock(state->array_lock);
#endif
for (i = 0; i < state->tracker_count; ++i)
{
@ -261,7 +260,9 @@ void gfx_widgets_set_leaderboard_display(unsigned id, const char* value)
}
}
SLOCK_UNLOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_unlock(state->array_lock);
#endif
}
void gfx_widgets_set_challenge_display(unsigned id, const char* badge)
@ -271,10 +272,12 @@ void gfx_widgets_set_challenge_display(unsigned id, const char* badge)
/* important - this must be done outside the lock because it has the potential to need to
* lock the video thread, which may be waiting for the popup queue lock to render popups */
uintptr_t badge_id = badge ? rcheevos_get_badge_texture(badge, 0) : 0;
uintptr_t badge_id = badge ? rcheevos_get_badge_texture(badge, 0) : 0;
uintptr_t old_badge_id = 0;
SLOCK_LOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_lock(state->array_lock);
#endif
for (i = 0; i < state->challenge_count; ++i)
{
@ -319,7 +322,9 @@ void gfx_widgets_set_challenge_display(unsigned id, const char* badge)
}
}
SLOCK_UNLOCK(state->array_lock);
#ifdef HAVE_THREADS
slock_unlock(state->array_lock);
#endif
if (old_badge_id)
video_driver_texture_unload(&old_badge_id);

View File

@ -30,11 +30,6 @@
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
#endif
typedef struct
@ -619,8 +614,7 @@ void task_queue_deinit(void)
void task_queue_init(bool threaded, retro_task_queue_msg_t msg_push)
{
impl_current = &impl_regular;
impl_current = &impl_regular;
#ifdef HAVE_THREADS
main_thread_id = sthread_get_current_thread_id();
if (threaded)
@ -653,9 +647,7 @@ bool task_queue_is_threaded(void)
bool task_queue_find(task_finder_data_t *find_data)
{
if (!impl_current->find(find_data->func, find_data->userdata))
return false;
return true;
return impl_current->find(find_data->func, find_data->userdata);
}
void task_queue_retrieve(task_retriever_data_t *data)
@ -687,7 +679,9 @@ bool task_queue_push(retro_task_t *task)
retro_task_t *running = NULL;
bool found = false;
SLOCK_LOCK(queue_lock);
#ifdef HAVE_THREADS
slock_lock(queue_lock);
#endif
running = tasks_running.front;
for (; running; running = running->next)
@ -699,7 +693,9 @@ bool task_queue_push(retro_task_t *task)
}
}
SLOCK_UNLOCK(queue_lock);
#ifdef HAVE_THREADS
slock_unlock(queue_lock);
#endif
/* skip this task, user must try again later */
if (found)
@ -770,69 +766,105 @@ bool task_is_on_main_thread(void)
void task_set_finished(retro_task_t *task, bool finished)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
task->finished = finished;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void task_set_mute(retro_task_t *task, bool mute)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
task->mute = mute;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void task_set_error(retro_task_t *task, char *error)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
task->error = error;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void task_set_progress(retro_task_t *task, int8_t progress)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
task->progress = progress;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void task_set_title(retro_task_t *task, char *title)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
task->title = title;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void task_set_data(retro_task_t *task, void *data)
{
SLOCK_LOCK(running_lock);
#ifdef HAVE_THREADS
slock_lock(running_lock);
#endif
task->task_data = data;
SLOCK_UNLOCK(running_lock);
#ifdef HAVE_THREADS
slock_unlock(running_lock);
#endif
}
void task_set_cancelled(retro_task_t *task, bool cancelled)
{
SLOCK_LOCK(running_lock);
#ifdef HAVE_THREADS
slock_lock(running_lock);
#endif
task->cancelled = cancelled;
SLOCK_UNLOCK(running_lock);
#ifdef HAVE_THREADS
slock_unlock(running_lock);
#endif
}
void task_free_title(retro_task_t *task)
{
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
if (task->title)
free(task->title);
task->title = NULL;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
}
void* task_get_data(retro_task_t *task)
{
void *data = NULL;
SLOCK_LOCK(running_lock);
#ifdef HAVE_THREADS
slock_lock(running_lock);
#endif
data = task->task_data;
SLOCK_UNLOCK(running_lock);
#ifdef HAVE_THREADS
slock_unlock(running_lock);
#endif
return data;
}
@ -841,9 +873,13 @@ bool task_get_cancelled(retro_task_t *task)
{
bool cancelled = false;
SLOCK_LOCK(running_lock);
#ifdef HAVE_THREADS
slock_lock(running_lock);
#endif
cancelled = task->cancelled;
SLOCK_UNLOCK(running_lock);
#ifdef HAVE_THREADS
slock_unlock(running_lock);
#endif
return cancelled;
}
@ -852,9 +888,13 @@ bool task_get_finished(retro_task_t *task)
{
bool finished = false;
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
finished = task->finished;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
return finished;
}
@ -863,9 +903,13 @@ bool task_get_mute(retro_task_t *task)
{
bool mute = false;
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
mute = task->mute;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
return mute;
}
@ -874,9 +918,13 @@ char* task_get_error(retro_task_t *task)
{
char *error = NULL;
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
error = task->error;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
return error;
}
@ -885,9 +933,13 @@ int8_t task_get_progress(retro_task_t *task)
{
int8_t progress = 0;
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
progress = task->progress;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
return progress;
}
@ -896,9 +948,13 @@ char* task_get_title(retro_task_t *task)
{
char *title = NULL;
SLOCK_LOCK(property_lock);
#ifdef HAVE_THREADS
slock_lock(property_lock);
#endif
title = task->title;
SLOCK_UNLOCK(property_lock);
#ifdef HAVE_THREADS
slock_unlock(property_lock);
#endif
return title;
}