mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-22 01:33:23 -10:00
Where the atomics have compare-and-swap and pointer operations, the threaded runner takes no lock and waits on no condition variable. Every task is on a live list from its push until it is retired: any thread links it at the head, only the checking thread unlinks it, and find(), retrieve() and the lookups behind wake, cancel and reset walk it from any thread inside a read epoch. A retired task is cleaned up and freed once no finder can still hold it, at once when none is inside, since finders read task->state. Workers take ready tasks from two bounded MPMC rings: the plain one, which only the one worker takes from, and the parallel one, which every worker does; what overflows waits behind them in order. A task with a 'when' to wait for goes to the timer keeper, whichever idle worker holds the token, which sleeps until the earliest is due and hands the token on before it runs anything. Main-thread tasks and finished ones reach the checking thread through lock-free stacks. Workers, task_queue_wait() and deinit's bounded wait for the workers park on eventcounts. Each gather with work in flight and each pass's end advance one counter that both read, so a handler still sees what the frame loop wrote before a check, as the frame count a load waits on, and has read it before the loop writes again. The volatile and PS2 backends keep the locked runner, as does GCD. task_queue.c now uses retro_eventcount.c, which the sample builds compiling it with threads now link. task_queue_parallel_test floods both rings past what they hold with every worker held; task_queue_switch_test holds a waker in retro_eventcount_notify() where the runner takes no lock.
50 lines
1.5 KiB
Makefile
50 lines
1.5 KiB
Makefile
include ../../sample_objdir.mk
|
|
|
|
TARGET := task_progress_push_test
|
|
|
|
# Drives the shipping libretro-common/queues/task_queue.c directly.
|
|
# The subject is task_queue_push_progress()'s contract with msg_push:
|
|
# the message is formatted under the property lock and pushed with it
|
|
# released, so the push must not reach for a property the lock guards.
|
|
# Build with EXTRA_CFLAGS=-DPROGRESS_PUSH_DEFECT to break that half.
|
|
|
|
REPO_ROOT := ../../..
|
|
LIBRETRO_COMM_DIR := $(REPO_ROOT)/libretro-common
|
|
|
|
SOURCES := task_progress_push_test.c \
|
|
$(LIBRETRO_COMM_DIR)/queues/task_queue.c \
|
|
$(LIBRETRO_COMM_DIR)/rthreads/rthreads.c \
|
|
$(LIBRETRO_COMM_DIR)/rthreads/retro_eventcount.c \
|
|
$(LIBRETRO_COMM_DIR)/features/features_cpu.c \
|
|
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c
|
|
|
|
OBJS := $(call sample_objs,$(SOURCES:.c=.o))
|
|
|
|
CFLAGS += -Wall -std=gnu99 -g1 -DHAVE_THREADS $(EXTRA_CFLAGS) \
|
|
-I$(LIBRETRO_COMM_DIR)/include
|
|
LDFLAGS += -lpthread -lm
|
|
|
|
# The samples workflow passes SANITIZER=address,undefined; honour it.
|
|
ifneq ($(SANITIZER),)
|
|
CFLAGS := -fsanitize=$(SANITIZER) -fno-omit-frame-pointer $(CFLAGS)
|
|
LDFLAGS := -fsanitize=$(SANITIZER) $(LDFLAGS)
|
|
endif
|
|
|
|
all: $(TARGET)
|
|
|
|
%.o: %.c
|
|
$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
$(SAMPLE_OBJDIR)/%.o: $$(call sample_src,$$*).c
|
|
@mkdir -p $(@D)
|
|
$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
$(TARGET): $(OBJS)
|
|
$(CC) -o $@ $^ $(LDFLAGS)
|
|
|
|
clean:
|
|
rm -rf $(SAMPLE_OBJDIR)
|
|
rm -f $(TARGET) $(OBJS)
|
|
|
|
.PHONY: clean all
|