Skip to content

Commit eb36c35

Browse files
author
Cthulhu-throwaway
authored
(Netplay) Fix content reload deadlocks on static core platforms #2 (libretro#14202)
1 parent 8108931 commit eb36c35

File tree

4 files changed

+112
-14
lines changed

4 files changed

+112
-14
lines changed

network/netplay/netplay.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "../../config.h"
2929
#endif
3030

31+
#include <retro_miscellaneous.h>
32+
3133
#include <net/net_compat.h>
3234

3335
#include "../../msg_hash.h"
@@ -56,6 +58,11 @@ enum rarch_netplay_ctl_state
5658
RARCH_NETPLAY_CTL_ENABLE_SERVER,
5759
RARCH_NETPLAY_CTL_ENABLE_CLIENT,
5860
RARCH_NETPLAY_CTL_DISABLE,
61+
#ifndef HAVE_DYNAMIC
62+
RARCH_NETPLAY_CTL_GET_FORK_ARGS,
63+
RARCH_NETPLAY_CTL_SET_FORK_ARGS,
64+
RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS,
65+
#endif
5966
RARCH_NETPLAY_CTL_REFRESH_CLIENT_INFO,
6067
RARCH_NETPLAY_CTL_IS_ENABLED,
6168
RARCH_NETPLAY_CTL_IS_REPLAYING,
@@ -247,6 +254,9 @@ typedef struct
247254
unsigned server_port_deferred;
248255
char server_address_deferred[256];
249256
char server_session_deferred[32];
257+
#ifndef HAVE_DYNAMIC
258+
char netplay_fork_args[PATH_MAX_LENGTH];
259+
#endif
250260
bool netplay_client_deferred;
251261
/* Only used before init_netplay */
252262
bool netplay_enabled;

network/netplay/netplay_frontend.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8987,6 +8987,28 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
89878987
#endif
89888988
break;
89898989

8990+
#ifndef HAVE_DYNAMIC
8991+
case RARCH_NETPLAY_CTL_GET_FORK_ARGS:
8992+
if (data && !string_is_empty(net_st->netplay_fork_args))
8993+
strlcpy((char*)data, net_st->netplay_fork_args,
8994+
sizeof(net_st->netplay_fork_args));
8995+
else
8996+
ret = false;
8997+
break;
8998+
8999+
case RARCH_NETPLAY_CTL_SET_FORK_ARGS:
9000+
if (data)
9001+
strlcpy(net_st->netplay_fork_args, (const char*)data,
9002+
sizeof(net_st->netplay_fork_args));
9003+
else
9004+
ret = false;
9005+
break;
9006+
9007+
case RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS:
9008+
*net_st->netplay_fork_args = '\0';
9009+
break;
9010+
#endif
9011+
89909012
case RARCH_NETPLAY_CTL_REFRESH_CLIENT_INFO:
89919013
if (!netplay || !netplay->is_server)
89929014
{

network/netplay/netplay_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "netplay_protocol.h"
2424

2525
#include <libretro.h>
26-
#include <retro_miscellaneous.h>
2726

2827
#include <streams/trans_stream.h>
2928

tasks/task_netplay_find_content.c

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "../content.h"
3939
#include "../runloop.h"
4040

41+
#ifndef HAVE_DYNAMIC
42+
#include "../retroarch.h"
43+
#include "../frontend/frontend_driver.h"
44+
#endif
45+
4146
#include "task_content.h"
4247
#include "tasks_internal.h"
4348

@@ -445,6 +450,59 @@ static void task_netplay_crc_scan_handler(retro_task_t *task)
445450
task_set_finished(task, true);
446451
}
447452

453+
#ifndef HAVE_DYNAMIC
454+
static void static_load(const char *core, const char *subsystem,
455+
const void *content, const char *hostname)
456+
{
457+
char buf[512];
458+
char args[PATH_MAX_LENGTH];
459+
460+
path_set(RARCH_PATH_CORE, core);
461+
462+
netplay_driver_ctl(RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS, NULL);
463+
464+
if (string_is_empty(hostname))
465+
{
466+
strlcpy(args, "-H", sizeof(args));
467+
}
468+
else
469+
{
470+
strlcpy(args, "-C ", sizeof(args));
471+
strlcat(args, hostname, sizeof(args));
472+
}
473+
474+
if (!string_is_empty(subsystem))
475+
{
476+
snprintf(buf, sizeof(buf), "\"%s\"", subsystem);
477+
strlcat(args, " --subsystem ", sizeof(args));
478+
strlcat(args, buf, sizeof(args));
479+
480+
if (content)
481+
{
482+
size_t i;
483+
const struct string_list *subsystem_content =
484+
(const struct string_list*)content;
485+
486+
for (i = 0; i < subsystem_content->size; i++)
487+
{
488+
snprintf(buf, sizeof(buf), " \"%s\"",
489+
subsystem_content->elems[i].data);
490+
strlcat(args, buf, sizeof(args));
491+
}
492+
}
493+
}
494+
else if (content)
495+
{
496+
snprintf(buf, sizeof(buf), " \"%s\"", (const char*)content);
497+
strlcat(args, buf, sizeof(args));
498+
}
499+
500+
netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_FORK_ARGS, args);
501+
frontend_driver_set_fork(FRONTEND_FORK_CORE_WITH_ARGS);
502+
retroarch_ctl(RARCH_CTL_SET_SHUTDOWN, NULL);
503+
}
504+
#endif
505+
448506
static void task_netplay_crc_scan_callback(retro_task_t *task,
449507
void *task_data, void *user_data, const char *error)
450508
{
@@ -457,14 +515,13 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
457515
{
458516
case STATE_LOAD:
459517
{
460-
content_ctx_info_t content_info = {0};
461518
const char *content_path = (state->state & STATE_RELOAD) ?
462519
data->current.content_path : data->content_paths.elems[0].data;
463-
464520
#ifdef HAVE_DYNAMIC
521+
content_ctx_info_t content_info = {0};
522+
465523
if (data->current.core_loaded)
466524
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
467-
#endif
468525

469526
RARCH_LOG("[Lobby] Loading core '%s' with content file '%s'.\n",
470527
data->core, content_path);
@@ -486,6 +543,10 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
486543
NULL, NULL, CORE_TYPE_PLAIN, NULL, NULL);
487544
task_push_load_content_with_core(content_path,
488545
&content_info, CORE_TYPE_PLAIN, NULL, NULL);
546+
#else
547+
548+
static_load(data->core, NULL, content_path, data->hostname);
549+
#endif
489550
}
490551
break;
491552

@@ -494,11 +555,6 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
494555
const char *subsystem;
495556
struct string_list *subsystem_content;
496557

497-
#ifdef HAVE_DYNAMIC
498-
if (data->current.core_loaded)
499-
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
500-
#endif
501-
502558
if (state->state & STATE_RELOAD)
503559
{
504560
subsystem = data->current.subsystem;
@@ -510,6 +566,10 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
510566
subsystem_content = &data->content_paths;
511567
}
512568

569+
#ifdef HAVE_DYNAMIC
570+
if (data->current.core_loaded)
571+
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
572+
513573
RARCH_LOG("[Lobby] Loading core '%s' with subsystem '%s'.\n",
514574
data->core, subsystem);
515575

@@ -547,21 +607,22 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
547607
/* Disable netplay if we don't have the subsystem. */
548608
netplay_driver_ctl(RARCH_NETPLAY_CTL_DISABLE, NULL);
549609

550-
#ifdef HAVE_DYNAMIC
551610
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
552-
#endif
553611
}
612+
#else
613+
static_load(data->core, subsystem, subsystem_content,
614+
data->hostname);
615+
#endif
554616
}
555617
break;
556618

557619
case STATE_LOAD_CONTENTLESS:
558620
{
621+
#ifdef HAVE_DYNAMIC
559622
content_ctx_info_t content_info = {0};
560623

561-
#ifdef HAVE_DYNAMIC
562624
if (data->current.core_loaded)
563625
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
564-
#endif
565626

566627
RARCH_LOG("[Lobby] Loading contentless core '%s'.\n", data->core);
567628

@@ -581,6 +642,9 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
581642
task_push_load_new_core(data->core,
582643
NULL, NULL, CORE_TYPE_PLAIN, NULL, NULL);
583644
task_push_start_current_core(&content_info);
645+
#else
646+
static_load(data->core, NULL, NULL, data->hostname);
647+
#endif
584648
}
585649
break;
586650

@@ -590,7 +654,6 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
590654
{
591655
#ifdef HAVE_DYNAMIC
592656
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
593-
#endif
594657

595658
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
596659

@@ -613,6 +676,10 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
613676
content_clear_subsystem();
614677
content_set_subsystem_by_name(data->current.subsystem);
615678
}
679+
#else
680+
static_load(data->core, data->current.subsystem, NULL,
681+
data->hostname);
682+
#endif
616683

617684
runloop_msg_queue_push(
618685
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_START_WHEN_LOADED),

0 commit comments

Comments
 (0)