+static bool lightrec_cancel_block_rec(struct recompiler *rec,
+ struct block_rec *block_rec)
+{
+ if (block_rec->compiling) {
+ /* Block is being recompiled - wait for
+ * completion */
+ pthread_cond_wait(&rec->cond2, &rec->mutex);
+
+ /* We can't guarantee the signal was for us.
+ * Since block_rec may have been removed while
+ * we were waiting on the condition, we cannot
+ * check block_rec->compiling again. The best
+ * thing is just to restart the function. */
+ return false;
+ }
+
+ /* Block is not yet being processed - remove it from the list */
+ slist_remove(&rec->slist, &block_rec->slist);
+ lightrec_free(rec->state, MEM_FOR_LIGHTREC,
+ sizeof(*block_rec), block_rec);
+
+ return true;
+}
+
+static void lightrec_cancel_list(struct recompiler *rec)
+{
+ struct block_rec *block_rec;
+ struct slist_elm *next;
+
+ while (!!(next = lightrec_get_first_elm(&rec->slist))) {
+ block_rec = container_of(next, struct block_rec, slist);
+
+ lightrec_cancel_block_rec(rec, block_rec);
+ }
+
+ pthread_cond_broadcast(&rec->cond2);
+}
+
+static void lightrec_flush_code_buffer(struct lightrec_state *state, void *d)
+{
+ struct recompiler *rec = d;
+
+ pthread_mutex_lock(&rec->mutex);
+
+ if (rec->must_flush) {
+ lightrec_remove_outdated_blocks(state->block_cache, NULL);
+ rec->must_flush = false;
+ }
+
+ pthread_mutex_unlock(&rec->mutex);
+}
+