X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=deps%2Flightrec%2Frecompiler.c;h=1ccef7a067b25b7a10ff265ab3e9b208b9c570c1;hb=878e6cda26bbf4af5090a01709db026d42c233b4;hp=a6d2f322a71c03f89204399047abdecca9b8c0c4;hpb=a5a6f7b82ed88f1ac3178c32c9bda22eb612814b;p=pcsx_rearmed.git diff --git a/deps/lightrec/recompiler.c b/deps/lightrec/recompiler.c index a6d2f322..1ccef7a0 100644 --- a/deps/lightrec/recompiler.c +++ b/deps/lightrec/recompiler.c @@ -38,7 +38,7 @@ struct recompiler { pthread_cond_t cond; pthread_cond_t cond2; pthread_mutex_t mutex; - bool stop, must_flush; + bool stop, pause, must_flush; struct slist_elm slist; pthread_mutex_t alloc_mutex; @@ -49,7 +49,7 @@ struct recompiler { static unsigned int get_processors_count(void) { - unsigned int nb = 1; + int nb = 1; #if defined(PTW32_VERSION) nb = pthread_num_processors_np(); @@ -59,7 +59,7 @@ static unsigned int get_processors_count(void) nb = sysctlbyname("hw.ncpu", &count, &size, NULL, 0) ? 1 : count; #elif defined(_SC_NPROCESSORS_ONLN) - nb = sysconf(_SC_NPROCESSORS_ONLN); + nb = (int)sysconf(_SC_NPROCESSORS_ONLN); #endif return nb < 1 ? 1 : nb; @@ -131,7 +131,8 @@ static void lightrec_compile_list(struct recompiler *rec, struct block *block; int ret; - while (!!(block_rec = lightrec_get_best_elm(&rec->slist))) { + while (!rec->pause && + !!(block_rec = lightrec_get_best_elm(&rec->slist))) { block_rec->compiling = true; block = block_rec->block; @@ -187,7 +188,7 @@ static void * lightrec_recompiler_thd(void *d) if (rec->stop) goto out_unlock; - } while (slist_empty(&rec->slist)); + } while (rec->pause || slist_empty(&rec->slist)); lightrec_compile_list(rec, thd); } @@ -228,6 +229,7 @@ struct recompiler *lightrec_recompiler_init(struct lightrec_state *state) rec->state = state; rec->stop = false; + rec->pause = false; rec->must_flush = false; rec->nb_recs = nb_recs; slist_init(&rec->slist); @@ -486,3 +488,18 @@ void lightrec_code_alloc_unlock(struct lightrec_state *state) { pthread_mutex_unlock(&state->rec->alloc_mutex); } + +void lightrec_recompiler_pause(struct recompiler *rec) +{ + rec->pause = true; + + pthread_mutex_lock(&rec->mutex); + pthread_cond_broadcast(&rec->cond); + lightrec_cancel_list(rec); + pthread_mutex_unlock(&rec->mutex); +} + +void lightrec_recompiler_unpause(struct recompiler *rec) +{ + rec->pause = false; +}