mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-23 14:33:13 -04:00
multithread: stop all threads from running when window is closed
Add a "running" boolean to the master device struct, and set it to false when the main window is closed. All the tight inner while (1) loops now become while (running). Closes #24
This commit is contained in:
parent
0d087a054e
commit
406b080fd1
3
cen64.c
3
cen64.c
|
@ -281,6 +281,8 @@ int validate_sha(struct rom_file *rom, const uint8_t *good_sum) {
|
|||
int run_device(struct cen64_device *device, bool no_video) {
|
||||
cen64_thread thread;
|
||||
|
||||
device->running = true;
|
||||
|
||||
if (cen64_thread_create(&thread, run_device_thread, device)) {
|
||||
printf("Failed to create the main emulation thread.\n");
|
||||
device_destroy(device);
|
||||
|
@ -290,6 +292,7 @@ int run_device(struct cen64_device *device, bool no_video) {
|
|||
if (!no_video)
|
||||
cen64_gl_window_thread(device);
|
||||
|
||||
device->running = false;
|
||||
cen64_thread_join(&thread);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ CEN64_THREAD_RETURN_TYPE run_rcp_thread(void *opaque) {
|
|||
if (setjmp(device->bus.unwind_data))
|
||||
return CEN64_THREAD_RETURN_VAL;
|
||||
|
||||
while (1) {
|
||||
while (likely(device->running)) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 6250; i++) {
|
||||
|
@ -193,7 +193,7 @@ CEN64_THREAD_RETURN_TYPE run_rcp_thread(void *opaque) {
|
|||
CEN64_THREAD_RETURN_TYPE run_vr4300_thread(void *opaque) {
|
||||
struct cen64_device *device = (struct cen64_device *) opaque;
|
||||
|
||||
while (1) {
|
||||
while (likely(device->running)) {
|
||||
unsigned i, j;
|
||||
|
||||
for (i = 0; i < 6250 / 2; i++) {
|
||||
|
@ -261,7 +261,7 @@ int device_spin(struct cen64_device *device) {
|
|||
if (setjmp(device->bus.unwind_data))
|
||||
return 1;
|
||||
|
||||
while (1) {
|
||||
while (likely(device->running)) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
|
@ -290,7 +290,7 @@ int device_debug_spin(struct cen64_device *device) {
|
|||
if (setjmp(device->bus.unwind_data))
|
||||
return 1;
|
||||
|
||||
while (1) {
|
||||
while (likely(device->running)) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
|
|
|
@ -50,6 +50,8 @@ struct cen64_device {
|
|||
bool other_thread_is_waiting;
|
||||
cen64_mutex sync_mutex;
|
||||
cen64_cv sync_cv;
|
||||
|
||||
bool running;
|
||||
};
|
||||
|
||||
cen64_cold void device_destroy(struct cen64_device *device);
|
||||
|
|
Loading…
Reference in a new issue