diff --git a/Makefile.common b/Makefile.common
index 8f315b3380..547c932856 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -430,6 +430,7 @@ endif
ifeq ($(HAVE_RUNAHEAD), 1)
DEFINES += -DHAVE_RUNAHEAD
+ OBJ += runahead.o
endif
ifeq ($(HAVE_CC_RESAMPLER), 1)
diff --git a/griffin/griffin.c b/griffin/griffin.c
index c2de253044..253b09cd35 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -1236,6 +1236,9 @@ RETROARCH
============================================================ */
#include "../retroarch.c"
#include "../runloop.c"
+#ifdef HAVE_RUNAHEAD
+#include "../runahead.c"
+#endif
#include "../command.c"
#include "../midi_driver.c"
#include "../location_driver.c"
diff --git a/menu/menu_setting.c b/menu/menu_setting.c
index 3f97bd3408..a418f45879 100644
--- a/menu/menu_setting.c
+++ b/menu/menu_setting.c
@@ -8710,7 +8710,7 @@ static void runahead_change_handler(rarch_setting_t *setting)
{
/* Disable preemptive frames and inform user */
settings->bools.preemptive_frames_enable = false;
- runloop_preempt_deinit();
+ preempt_deinit(runloop_state_get_ptr());
runloop_msg_queue_push(
msg_hash_to_str(MSG_PREEMPT_DISABLED), 1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c
index 1229c1b2c2..63b50fd9ed 100644
--- a/network/netplay/netplay_frontend.c
+++ b/network/netplay/netplay_frontend.c
@@ -8438,7 +8438,7 @@ void deinit_netplay(void)
#if HAVE_RUNAHEAD
/* Reinitialize preemptive frames if enabled */
- runloop_preempt_init();
+ preempt_init(runloop_state_get_ptr());
#endif
}
diff --git a/retroarch.c b/retroarch.c
index 73f52d790c..dd15236af1 100644
--- a/retroarch.c
+++ b/retroarch.c
@@ -2272,7 +2272,7 @@ bool command_event(enum event_command cmd, void *data)
/* Disable preemptive frames */
settings->bools.preemptive_frames_enable = false;
- runloop_preempt_deinit();
+ preempt_deinit(runloop_st);
}
}
#endif
@@ -2318,8 +2318,8 @@ bool command_event(enum event_command cmd, void *data)
break;
case CMD_EVENT_PREEMPT_UPDATE:
#if HAVE_RUNAHEAD
- runloop_preempt_deinit();
- runloop_preempt_init();
+ preempt_deinit(runloop_st);
+ preempt_init(runloop_st);
#endif
break;
case CMD_EVENT_PREEMPT_RESET_BUFFER:
@@ -2411,9 +2411,9 @@ bool command_event(enum event_command cmd, void *data)
if (!runloop_st->secondary_lib_handle)
{
- if (!secondary_core_ensure_exists(settings))
+ if (!secondary_core_ensure_exists(runloop_st, settings))
{
- runloop_secondary_core_destroy();
+ runahead_secondary_core_destroy(runloop_st);
runloop_st->flags &=
~RUNLOOP_FLAG_RUNAHEAD_SECONDARY_CORE_AVAILABLE;
return false;
@@ -3042,10 +3042,10 @@ bool command_event(enum event_command cmd, void *data)
* remain disabled until the user restarts
* RetroArch */
if (!(runloop_st->flags & RUNLOOP_FLAG_RUNAHEAD_AVAILABLE))
- runloop_runahead_clear_variables(runloop_st);
+ runahead_clear_variables(runloop_st);
/* Deallocate preemptive frames */
- runloop_preempt_deinit();
+ preempt_deinit(runloop_st);
#endif
if (hwr)
@@ -3583,7 +3583,7 @@ bool command_event(enum event_command cmd, void *data)
}
#if HAVE_RUNAHEAD
/* Deinit preemptive frames; not compatible with netplay */
- runloop_preempt_deinit();
+ preempt_deinit(runloop_st);
#endif
}
break;
@@ -6248,7 +6248,7 @@ bool retroarch_main_init(int argc, char *argv[])
#ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
#endif
- runloop_preempt_init();
+ preempt_init(runloop_st);
#endif
return true;
diff --git a/runahead.c b/runahead.c
new file mode 100644
index 0000000000..ca5884f985
--- /dev/null
+++ b/runahead.c
@@ -0,0 +1,1705 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2023 - Daniel De Matteis
+ * Copyright (C) 2018-2023 - Dan Weiss
+ * Copyright (C) 2022-2023 - Neil4
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
+#include
+#include
+#include