Skip to content

v3.workers

fn new #

fn new(size int) &Pool

new creates up to size persistent workers. Failed launches simply reduce the available parallelism; run executes synchronously if none launch.

struct Pool #

@[heap]
struct Pool {
mut:
	jobs                   chan Task
	done                   chan Completion
	threads                []C.pthread_t
	is_closed              bool
	task_count             u64
	async_task_count       u64
	forced_sync_task_count u64
	fallback_task_count    u64
	launch_attempt_count   u64
	launch_failure_count   u64
	queue_wait_ns          u64
	worker_run_ns          u64
	started_at_ns          u64
}

Pool owns a bounded set of persistent compiler workers. Phase payloads stay owned by the submitting thread until run returns.

fn (Pool) size #

fn (p &Pool) size() int

size reports the number of successfully launched persistent workers.

fn (Pool) run #

fn (mut p Pool) run(tasks []Task) bool

run executes one compiler phase batch and waits for every callback. Tasks marked force_sync run on the caller while submitted tasks use the pool.

fn (Pool) tasks_run #

fn (p &Pool) tasks_run() u64

tasks_run reports the number of phase callbacks completed through this pool.

fn (Pool) stats #

fn (p &Pool) stats() Stats

stats returns cumulative scheduling and utilization counters.

fn (Pool) close #

fn (mut p Pool) close()

close stops and joins every persistent worker. Join failures are surfaced.

struct Stats #

struct Stats {
pub:
	tasks_run         u64
	async_tasks       u64
	forced_sync_tasks u64
	fallback_tasks    u64
	launch_attempts   u64
	launch_failures   u64
	queue_wait_ns     u64
	worker_run_ns     u64
	utilization_ppm   u64
}

Stats is a cumulative snapshot of persistent worker-pool activity.

struct Task #

struct Task {
pub:
	run        fn (voidptr) voidptr = unsafe { nil }
	arg        voidptr
	force_sync bool
	stop       bool
mut:
	queued_at_ns u64
}

Task is one type-erased compiler phase callback submitted to Pool.