mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-19 16:51:53 +00:00
Check at runtime if we can make threads
This commit is contained in:
parent
5595855878
commit
538f1b6985
22 changed files with 185 additions and 200 deletions
|
@ -192,9 +192,6 @@ endif()
|
|||
|
||||
target_compile_definitions(SRB2SDL2 PRIVATE -D_LARGEFILE64_SOURCE)
|
||||
|
||||
set(SRB2_HAVE_THREADS ON)
|
||||
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS)
|
||||
|
||||
if("${SRB2_CONFIG_HWRENDER}")
|
||||
target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
|
||||
add_subdirectory(hardware)
|
||||
|
|
|
@ -13,10 +13,7 @@ ifdef MINGW
|
|||
libs+=-mconsole
|
||||
endif
|
||||
|
||||
ifndef NOTHREADS
|
||||
opts+=-DHAVE_THREADS
|
||||
sources+=dedicated/i_threads.c
|
||||
endif
|
||||
|
||||
NOOPENMPT=1
|
||||
NOGME=1
|
||||
|
|
|
@ -43,10 +43,7 @@ sources+=sdl/mixer_sound.c
|
|||
endif
|
||||
endif
|
||||
|
||||
ifndef NOTHREADS
|
||||
opts+=-DHAVE_THREADS
|
||||
sources+=sdl/i_threads.c
|
||||
endif
|
||||
|
||||
ifdef SDL_PKGCONFIG
|
||||
$(eval $(call Use_pkg_config,SDL))
|
||||
|
|
|
@ -45,15 +45,10 @@
|
|||
|
||||
#define MAXHUDLINES 20
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_mutex con_mutex;
|
||||
|
||||
# define Lock_state() I_lock_mutex(&con_mutex)
|
||||
# define Unlock_state() I_unlock_mutex(con_mutex)
|
||||
#else/*HAVE_THREADS*/
|
||||
# define Lock_state()
|
||||
# define Unlock_state()
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
static boolean con_started = false; // console has been initialised
|
||||
boolean con_startup = false; // true at game startup
|
||||
|
|
|
@ -21,9 +21,7 @@ void CON_StopRefresh(void);
|
|||
|
||||
boolean CON_Responder(event_t *ev);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
extern I_mutex con_mutex;
|
||||
#endif
|
||||
|
||||
// set true when screen size has changed, to adapt console
|
||||
extern boolean con_recalc;
|
||||
|
|
12
src/d_main.c
12
src/d_main.c
|
@ -244,15 +244,11 @@ void D_ProcessEvents(void)
|
|||
}
|
||||
|
||||
// Menu input
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
{
|
||||
eaten = M_Responder(ev);
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
|
||||
if (eaten)
|
||||
continue; // menu ate the event
|
||||
|
@ -264,15 +260,11 @@ void D_ProcessEvents(void)
|
|||
}
|
||||
|
||||
// console input
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&con_mutex);
|
||||
#endif
|
||||
{
|
||||
eaten = CON_Responder(ev);
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(con_mutex);
|
||||
#endif
|
||||
|
||||
if (eaten)
|
||||
continue; // ate the event
|
||||
|
@ -596,13 +588,9 @@ static void D_Display(void)
|
|||
// vid size change is now finished if it was on...
|
||||
vid.recalc = 0;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_Drawer(); // menu is drawn even on top of everything
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
// focus lost moved to M_Drawer
|
||||
|
||||
CON_Drawer();
|
||||
|
|
|
@ -1181,10 +1181,8 @@ static void I_RegisterSignals (void)
|
|||
|
||||
INT32 I_StartupSystem(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_start_threads();
|
||||
I_AddExitFunc(I_stop_threads);
|
||||
#endif
|
||||
I_StartupConsole();
|
||||
I_RegisterSignals();
|
||||
#ifndef NOMUMBLE
|
||||
|
|
|
@ -42,10 +42,11 @@ static void *HandleThread(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
|
||||
int I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
|
||||
{
|
||||
thread_t *thread;
|
||||
(void)name;
|
||||
|
||||
pthread_mutex_lock(&thread_lock);
|
||||
thread = thread_list;
|
||||
while (thread != NULL)
|
||||
|
@ -69,6 +70,13 @@ void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
|
|||
thread->userdata = userdata;
|
||||
pthread_create(&thread->thread, NULL, HandleThread, thread);
|
||||
pthread_mutex_unlock(&thread_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int I_can_thread(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int I_thread_is_stopped(void)
|
||||
|
|
|
@ -245,6 +245,8 @@ enum {false = 0, true = 1};
|
|||
|
||||
#define FUNCNOINLINE __attribute__((noinline))
|
||||
|
||||
#define FUNCWARNRV __attribute__((warn_unused_result))
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4
|
||||
#ifdef __i386__ // i386 only
|
||||
#define FUNCTARGET(X) __attribute__ ((__target__ (X)))
|
||||
|
@ -296,6 +298,9 @@ enum {false = 0, true = 1};
|
|||
#ifndef FUNCTARGET
|
||||
#define FUNCTARGET(x)
|
||||
#endif
|
||||
#ifndef FUNCWARNRV
|
||||
#define FUNCWARNRV
|
||||
#endif
|
||||
#ifndef ATTRPACK
|
||||
#define ATTRPACK
|
||||
#endif
|
||||
|
|
|
@ -919,13 +919,9 @@ void F_IntroTicker(void)
|
|||
|
||||
I_OsPolling();
|
||||
I_UpdateNoBlit();
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_Drawer(); // menu is drawn even on top of wipes
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
I_FinishUpdate(); // Update the screen with the image Tails 06-19-2001
|
||||
|
||||
if (moviemode) // make sure we save frames for the white hold too
|
||||
|
|
|
@ -601,13 +601,9 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu)
|
|||
|
||||
if (drawMenu)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_Drawer(); // menu is drawn even on top of wipes
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
I_FinishUpdate(); // page flip or blit buffer
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
/// \file i_threads.h
|
||||
/// \brief Multithreading abstraction
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
|
||||
#ifndef I_THREADS_H
|
||||
#define I_THREADS_H
|
||||
|
||||
|
@ -19,10 +17,11 @@ typedef void (*I_thread_fn)(void *userdata);
|
|||
typedef void * I_mutex;
|
||||
typedef void * I_cond;
|
||||
|
||||
int I_can_thread (void) FUNCWARNRV;
|
||||
void I_start_threads (void);
|
||||
void I_stop_threads (void);
|
||||
|
||||
void I_spawn_thread (const char *name, I_thread_fn, void *userdata);
|
||||
int I_spawn_thread (const char *name, I_thread_fn, void *userdata) FUNCWARNRV;
|
||||
|
||||
/* check in your thread whether to return early */
|
||||
int I_thread_is_stopped (void);
|
||||
|
@ -36,4 +35,3 @@ void I_wake_one_cond (I_cond *);
|
|||
void I_wake_all_cond (I_cond *);
|
||||
|
||||
#endif/*I_THREADS_H*/
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
|
95
src/m_menu.c
95
src/m_menu.c
|
@ -123,9 +123,7 @@ typedef enum
|
|||
NUM_QUITMESSAGES
|
||||
} text_enum;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_mutex m_menu_mutex;
|
||||
#endif
|
||||
|
||||
M_waiting_mode_t m_waiting_mode = M_NOT_WAITING;
|
||||
|
||||
|
@ -3802,29 +3800,32 @@ void M_SetupNextMenu(menu_t *menudef)
|
|||
{
|
||||
INT16 i;
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
if (currentMenu == &MP_RoomDef || currentMenu == &MP_ConnectDef)
|
||||
#if defined (MASTERSERVER)
|
||||
if (I_can_thread())
|
||||
{
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
if (currentMenu == &MP_RoomDef || currentMenu == &MP_ConnectDef)
|
||||
{
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
}
|
||||
|
||||
if (currentMenu == &MP_ConnectDef)
|
||||
{
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
if (ms_ServerList)
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
free(ms_ServerList);
|
||||
ms_ServerList = NULL;
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
}
|
||||
|
||||
if (currentMenu == &MP_ConnectDef)
|
||||
{
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
if (ms_ServerList)
|
||||
{
|
||||
free(ms_ServerList);
|
||||
ms_ServerList = NULL;
|
||||
}
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
#endif/*MASTERSERVER*/
|
||||
|
||||
if (currentMenu->quitroutine)
|
||||
{
|
||||
|
@ -3891,7 +3892,7 @@ void M_Ticker(void)
|
|||
if (currentMenu == &OP_ScreenshotOptionsDef)
|
||||
M_SetupScreenshotMenu();
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#if defined (MASTERSERVER)
|
||||
if (!netgame)
|
||||
return;
|
||||
|
||||
|
@ -11378,7 +11379,7 @@ static boolean M_CheckMODVersion(int id)
|
|||
}
|
||||
#endif/*UPDATE_ALERT*/
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#if defined (MASTERSERVER)
|
||||
static void
|
||||
Check_new_version_thread (int *id)
|
||||
{
|
||||
|
@ -11435,7 +11436,7 @@ Check_new_version_thread (int *id)
|
|||
|
||||
free(id);
|
||||
}
|
||||
#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/
|
||||
#endif/*defined (MASTERSERVER)*/
|
||||
|
||||
static void M_ConnectMenu(INT32 choice)
|
||||
{
|
||||
|
@ -11477,7 +11478,7 @@ UINT32 roomIds[NUM_LIST_ROOMS];
|
|||
static void M_RoomMenu(INT32 choice)
|
||||
{
|
||||
INT32 i;
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#if defined (MASTERSERVER)
|
||||
int *id;
|
||||
#endif
|
||||
|
||||
|
@ -11500,44 +11501,50 @@ static void M_RoomMenu(INT32 choice)
|
|||
M_SetupNextMenu(&MP_RoomDef);
|
||||
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
if (I_can_thread())
|
||||
{
|
||||
#ifdef UPDATE_ALERT
|
||||
m_waiting_mode = M_WAITING_VERSION;
|
||||
m_waiting_mode = M_WAITING_VERSION;
|
||||
#else/*UPDATE_ALERT*/
|
||||
m_waiting_mode = M_WAITING_ROOMS;
|
||||
m_waiting_mode = M_WAITING_ROOMS;
|
||||
#endif/*UPDATE_ALERT*/
|
||||
|
||||
MP_RoomMenu[0].text = "";
|
||||
MP_RoomMenu[0].text = "";
|
||||
|
||||
id = malloc(sizeof *id);
|
||||
id = malloc(sizeof *id);
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
*id = ms_QueryId;
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
*id = ms_QueryId;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
(void)I_spawn_thread("check-new-version",
|
||||
(I_thread_fn)Check_new_version_thread, id);
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
I_spawn_thread("check-new-version",
|
||||
(I_thread_fn)Check_new_version_thread, id);
|
||||
#else/*HAVE_THREADS*/
|
||||
else
|
||||
{
|
||||
#ifdef UPDATE_ALERT
|
||||
if (M_CheckMODVersion(0))
|
||||
if (M_CheckMODVersion(0))
|
||||
#endif/*UPDATE_ALERT*/
|
||||
{
|
||||
GetRoomsList(currentMenu->prevMenu == &MP_ServerDef, 0);
|
||||
{
|
||||
GetRoomsList(currentMenu->prevMenu == &MP_ServerDef, 0);
|
||||
}
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
static void M_ChooseRoom(INT32 choice)
|
||||
{
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
#if defined (MASTERSERVER)
|
||||
if (I_can_thread())
|
||||
{
|
||||
ms_QueryId++;
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
#endif
|
||||
|
||||
if (choice == 0)
|
||||
|
|
|
@ -352,9 +352,7 @@ void M_ClearMenus(boolean callexitmenufunc);
|
|||
// Maybe this goes here????? Who knows.
|
||||
boolean M_MouseNeeded(void);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
extern I_mutex m_menu_mutex;
|
||||
#endif
|
||||
|
||||
extern menu_t *currentMenu;
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node)
|
|||
M_SortServerList();
|
||||
}
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#if defined (MASTERSERVER)
|
||||
struct Fetch_servers_ctx
|
||||
{
|
||||
int room;
|
||||
|
@ -437,7 +437,7 @@ Fetch_servers_thread (struct Fetch_servers_ctx *ctx)
|
|||
|
||||
free(ctx);
|
||||
}
|
||||
#endif // defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#endif // defined (MASTERSERVER)
|
||||
|
||||
void CL_QueryServerList (msg_server_t *server_list)
|
||||
{
|
||||
|
@ -493,34 +493,38 @@ void CL_UpdateServerList(boolean internetsearch, INT32 room)
|
|||
#ifdef MASTERSERVER
|
||||
if (internetsearch)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
struct Fetch_servers_ctx *ctx;
|
||||
|
||||
ctx = malloc(sizeof *ctx);
|
||||
|
||||
// This called from M_Refresh so I don't use a mutex
|
||||
m_waiting_mode = M_WAITING_SERVERS;
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
if (I_can_thread())
|
||||
{
|
||||
ctx->id = ms_QueryId;
|
||||
struct Fetch_servers_ctx *ctx;
|
||||
|
||||
ctx = malloc(sizeof *ctx);
|
||||
|
||||
// This called from M_Refresh so I don't use a mutex
|
||||
m_waiting_mode = M_WAITING_SERVERS;
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ctx->id = ms_QueryId;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
ctx->room = room;
|
||||
|
||||
(void)I_spawn_thread("fetch-servers", (I_thread_fn)Fetch_servers_thread, ctx);
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
ctx->room = room;
|
||||
|
||||
I_spawn_thread("fetch-servers", (I_thread_fn)Fetch_servers_thread, ctx);
|
||||
#else
|
||||
msg_server_t *server_list;
|
||||
|
||||
server_list = GetShortServersList(room, 0);
|
||||
|
||||
if (server_list)
|
||||
else
|
||||
{
|
||||
CL_QueryServerList(server_list);
|
||||
free(server_list);
|
||||
msg_server_t *server_list;
|
||||
|
||||
server_list = GetShortServersList(room, 0);
|
||||
|
||||
if (server_list)
|
||||
{
|
||||
CL_QueryServerList(server_list);
|
||||
free(server_list);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif // MASTERSERVER
|
||||
}
|
||||
|
@ -1187,13 +1191,9 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
|
|||
F_TitleScreenDrawer();
|
||||
}
|
||||
CL_DrawConnectionStatus();
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_Drawer(); //Needed for drawing messageboxes on the connection screen
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
I_UpdateNoVsync(); // page flip or blit buffer
|
||||
if (moviemode)
|
||||
M_SaveFrame();
|
||||
|
|
|
@ -1645,13 +1645,9 @@ void NetUpdate(void)
|
|||
if (nowtime != resptime)
|
||||
{
|
||||
resptime = nowtime;
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_Ticker();
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
CON_Ticker();
|
||||
}
|
||||
|
||||
|
|
|
@ -1605,6 +1605,9 @@ boolean CURLPrepareFile(const char* url, int dfilenum)
|
|||
{
|
||||
HTTP_login *login;
|
||||
|
||||
if (!I_can_thread())
|
||||
return false;
|
||||
|
||||
#ifdef PARANOIA
|
||||
if (M_CheckParm("-nodownload"))
|
||||
I_Error("Attempted to download files in -nodownload mode");
|
||||
|
@ -1675,7 +1678,7 @@ boolean CURLPrepareFile(const char* url, int dfilenum)
|
|||
filedownload.current = dfilenum;
|
||||
filedownload.http_running = true;
|
||||
|
||||
I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL);
|
||||
(void)I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -70,9 +70,7 @@ static boolean hms_allow_ipv6;
|
|||
static boolean hms_allow_ipv4;
|
||||
|
||||
static char *hms_api;
|
||||
#ifdef HAVE_THREADS
|
||||
static I_mutex hms_api_mutex;
|
||||
#endif
|
||||
|
||||
static char *hms_server_token;
|
||||
#ifndef NO_IPV6
|
||||
|
@ -201,9 +199,7 @@ HMS_connect (int proto, const char *format, ...)
|
|||
token_length = 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&hms_api_mutex);
|
||||
#endif
|
||||
|
||||
init_user_agent_once();
|
||||
|
||||
|
@ -215,9 +211,7 @@ HMS_connect (int proto, const char *format, ...)
|
|||
|
||||
sprintf(url, "%s/", hms_api);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(hms_api_mutex);
|
||||
#endif
|
||||
|
||||
va_start (ap, format);
|
||||
seek += vsprintf(&url[seek], format, ap);
|
||||
|
@ -379,7 +373,6 @@ HMS_fetch_rooms (int joining, int query_id)
|
|||
*/
|
||||
if (joining || id_no != 0)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (query_id != ms_QueryId)
|
||||
|
@ -389,7 +382,6 @@ HMS_fetch_rooms (int joining, int query_id)
|
|||
|
||||
if (! doing_shit)
|
||||
break;
|
||||
#endif
|
||||
|
||||
room_list[i].header.buffer[0] = 1;
|
||||
|
||||
|
@ -413,9 +405,7 @@ HMS_fetch_rooms (int joining, int query_id)
|
|||
|
||||
if (doing_shit)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
{
|
||||
for (i = 0; room_list[i].header.buffer[0]; i++)
|
||||
{
|
||||
|
@ -427,9 +417,7 @@ HMS_fetch_rooms (int joining, int query_id)
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -710,7 +698,6 @@ HMS_fetch_servers (msg_server_t *list, int room_number, int query_id)
|
|||
|
||||
if (address && port && title && version)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (query_id != ms_QueryId)
|
||||
|
@ -720,7 +707,6 @@ HMS_fetch_servers (msg_server_t *list, int room_number, int query_id)
|
|||
|
||||
if (! doing_shit)
|
||||
break;
|
||||
#endif
|
||||
|
||||
if (strcmp(version, local_version) == 0)
|
||||
{
|
||||
|
@ -809,16 +795,12 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size)
|
|||
void
|
||||
HMS_set_api (char *api)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&hms_api_mutex);
|
||||
#endif
|
||||
{
|
||||
free(hms_api);
|
||||
hms_api = api;
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(hms_api_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif/*MASTERSERVER*/
|
||||
|
|
|
@ -274,9 +274,14 @@ static void init_upnpc_once(struct upnpdata *upnpdata);
|
|||
|
||||
static void I_InitUPnP(void)
|
||||
{
|
||||
if (!I_can_thread())
|
||||
{
|
||||
UPNP_support = false;
|
||||
return;
|
||||
}
|
||||
upnpuser = malloc(sizeof *upnpuser);
|
||||
upnpuser->upnpc_started = 0;
|
||||
I_spawn_thread("init_upnpc_once", (I_thread_fn)init_upnpc_once, upnpuser);
|
||||
(void)I_spawn_thread("init_upnpc_once", (I_thread_fn)init_upnpc_once, upnpuser);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -35,16 +35,11 @@ static boolean MSUpdateAgain;
|
|||
|
||||
static time_t MSLastPing;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static I_mutex MSMutex;
|
||||
static I_cond MSCond;
|
||||
|
||||
# define Lock_state() I_lock_mutex (&MSMutex)
|
||||
# define Unlock_state() I_unlock_mutex (MSMutex)
|
||||
#else/*HAVE_THREADS*/
|
||||
# define Lock_state()
|
||||
# define Unlock_state()
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
static void Command_Listserv_f(void);
|
||||
|
||||
|
@ -72,13 +67,11 @@ consvar_t cv_masterserver_room_id = CVAR_INIT ("masterserver_room_id", "-1", CV_
|
|||
|
||||
static INT16 ms_RoomId = -1;
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
int ms_QueryId;
|
||||
I_mutex ms_QueryId_mutex;
|
||||
|
||||
msg_server_t *ms_ServerList;
|
||||
I_mutex ms_ServerList_mutex;
|
||||
#endif
|
||||
|
||||
UINT16 current_port = 0;
|
||||
|
||||
|
@ -110,13 +103,9 @@ void AddMServCommands(void)
|
|||
|
||||
static void WarnGUI (void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_StartMessage(M_GetText("There was a problem connecting to\nthe Master Server\n\nCheck the console for details.\n"), NULL, MM_NOTHING);
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define NUM_LIST_SERVER MAXSERVERLIST
|
||||
|
@ -160,14 +149,12 @@ char *GetMODVersion(int id)
|
|||
|
||||
c = HMS_compare_mod_version(buffer, 16);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (id != ms_QueryId)
|
||||
c = -1;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
#endif
|
||||
|
||||
if (c > 0)
|
||||
return buffer;
|
||||
|
@ -294,9 +281,7 @@ Finish_unlist (void)
|
|||
}
|
||||
Unlock_state();
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_wake_all_cond(&MSCond);
|
||||
#endif
|
||||
}
|
||||
|
||||
Lock_state();
|
||||
|
@ -307,7 +292,6 @@ Finish_unlist (void)
|
|||
Unlock_state();
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static int *
|
||||
Server_id (void)
|
||||
{
|
||||
|
@ -402,48 +386,56 @@ Change_masterserver_thread (char *api)
|
|||
|
||||
HMS_set_api(api);
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
void RegisterServer(void)
|
||||
{
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
I_spawn_thread(
|
||||
"register-server",
|
||||
(I_thread_fn)Register_server_thread,
|
||||
New_server_id()
|
||||
);
|
||||
#else
|
||||
Finish_registration();
|
||||
#endif
|
||||
if (I_can_thread())
|
||||
{
|
||||
(void)I_spawn_thread(
|
||||
"register-server",
|
||||
(I_thread_fn)Register_server_thread,
|
||||
New_server_id()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Finish_registration();
|
||||
}
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
static void UpdateServer(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_spawn_thread(
|
||||
"update-server",
|
||||
(I_thread_fn)Update_server_thread,
|
||||
Server_id()
|
||||
);
|
||||
#else
|
||||
Finish_update();
|
||||
#endif
|
||||
if (I_can_thread())
|
||||
{
|
||||
(void)I_spawn_thread(
|
||||
"update-server",
|
||||
(I_thread_fn)Update_server_thread,
|
||||
Server_id()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Finish_update();
|
||||
}
|
||||
}
|
||||
|
||||
void UnregisterServer(void)
|
||||
{
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
I_spawn_thread(
|
||||
"unlist-server",
|
||||
(I_thread_fn)Unlist_server_thread,
|
||||
Server_id()
|
||||
);
|
||||
#else
|
||||
Finish_unlist();
|
||||
#endif
|
||||
if (I_can_thread())
|
||||
{
|
||||
(void)I_spawn_thread(
|
||||
"unlist-server",
|
||||
(I_thread_fn)Unlist_server_thread,
|
||||
Server_id()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Finish_unlist();
|
||||
}
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
|
@ -490,15 +482,18 @@ void MasterClient_Ticker(void)
|
|||
static void
|
||||
Set_api (const char *api)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_spawn_thread(
|
||||
"change-masterserver",
|
||||
(I_thread_fn)Change_masterserver_thread,
|
||||
strdup(api)
|
||||
);
|
||||
#else
|
||||
HMS_set_api(strdup(api));
|
||||
#endif
|
||||
if (I_can_thread())
|
||||
{
|
||||
(void)I_spawn_thread(
|
||||
"change-masterserver",
|
||||
(I_thread_fn)Change_masterserver_thread,
|
||||
strdup(api)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
HMS_set_api(strdup(api));
|
||||
}
|
||||
}
|
||||
|
||||
#endif/*MASTERSERVER*/
|
||||
|
|
|
@ -71,13 +71,11 @@ extern consvar_t cv_masterserver_timeout;
|
|||
extern consvar_t cv_masterserver_debug;
|
||||
extern consvar_t cv_masterserver_token;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
extern int ms_QueryId;
|
||||
extern I_mutex ms_QueryId_mutex;
|
||||
|
||||
extern msg_server_t *ms_ServerList;
|
||||
extern I_mutex ms_ServerList_mutex;
|
||||
#endif
|
||||
|
||||
void RegisterServer(void);
|
||||
void UnregisterServer(void);
|
||||
|
|
|
@ -155,7 +155,7 @@ Worker (
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
I_spawn_thread (
|
||||
const char * name,
|
||||
I_thread_fn entry,
|
||||
|
@ -164,10 +164,15 @@ I_spawn_thread (
|
|||
Link link;
|
||||
Thread th;
|
||||
|
||||
if (! I_can_thread())
|
||||
return false;
|
||||
|
||||
th = malloc(sizeof *th);
|
||||
|
||||
if (! th)
|
||||
abort();/* this is pretty GNU of me */
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
th->entry = entry;
|
||||
th->userdata = userdata;
|
||||
|
@ -192,6 +197,14 @@ I_spawn_thread (
|
|||
}
|
||||
}
|
||||
I_unlock_mutex(i_thread_pool_mutex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
I_can_thread (void)
|
||||
{
|
||||
return SDL_ThreadID() != 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -207,6 +220,9 @@ I_start_threads (void)
|
|||
i_mutex_pool_mutex = SDL_CreateMutex();
|
||||
i_cond_pool_mutex = SDL_CreateMutex();
|
||||
|
||||
if (! I_can_thread())
|
||||
return;
|
||||
|
||||
if (!(
|
||||
i_thread_pool_mutex &&
|
||||
i_mutex_pool_mutex &&
|
||||
|
@ -287,6 +303,9 @@ I_lock_mutex (
|
|||
){
|
||||
SDL_mutex * mutex;
|
||||
|
||||
if (! I_can_thread())
|
||||
return;
|
||||
|
||||
mutex = Identity(
|
||||
&i_mutex_pool,
|
||||
i_mutex_pool_mutex,
|
||||
|
@ -302,6 +321,9 @@ void
|
|||
I_unlock_mutex (
|
||||
I_mutex id
|
||||
){
|
||||
if (! I_can_thread())
|
||||
return;
|
||||
|
||||
if (SDL_UnlockMutex(id) == -1)
|
||||
abort();
|
||||
}
|
||||
|
@ -330,6 +352,9 @@ I_wake_one_cond (
|
|||
){
|
||||
SDL_cond * cond;
|
||||
|
||||
if (! I_can_thread())
|
||||
return;
|
||||
|
||||
cond = Identity(
|
||||
&i_cond_pool,
|
||||
i_cond_pool_mutex,
|
||||
|
@ -347,6 +372,9 @@ I_wake_all_cond (
|
|||
){
|
||||
SDL_cond * cond;
|
||||
|
||||
if (! I_can_thread())
|
||||
return;
|
||||
|
||||
cond = Identity(
|
||||
&i_cond_pool,
|
||||
i_cond_pool_mutex,
|
||||
|
|
Loading…
Reference in a new issue