Skip to content

v.workers #

C.pthread_t is the platform pthread handle type.

fn limit_pool_size #

fn limit_pool_size(size int)

limit_pool_size caps pools created after this call to at most size 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.

fn note_fork #

fn note_fork()

note_fork tells the pools that this process is a child created by fork(): the threads they list belong to the parent and do not exist here.

struct Pool #

@[heap]
struct Pool {
mut:
	jobs    chan Task
	threads []WorkerThread
	// stats_lock guards the cumulative task and timing counters below; each
	// batch merges its own totals once, since batches may run concurrently.
	stats_lock             &sync.Mutex = sync.new_mutex()
	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
	launched_thread_count  u64
	caller_steals          bool
	queue_wait_ns          u64
	worker_run_ns          u64
	caller_run_ns          u64
	started_at_ns          u64
	generation             int // the fork generation the threads belong to
}

Pool owns a bounded set of persistent compiler workers. Phase payloads stay owned by the submitting thread until run returns. Thread creation and joining are the only platform-specific parts (thread_nix.c.v and thread_windows.c.v); the queueing and accounting are shared.

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
	// caller_run_ns is queued work that a waiting Pool.run caller ran itself. It
	// is excluded from utilization_ppm, which measures the persistent workers.
	caller_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
	// done receives the completion of a queued task. Each Pool.run batch has its
	// own channel, so a batch never counts another batch's completions, even
	// when it runs one of their queued tasks itself.
	done chan Completion
	// pushes_in_flight is the batch's count of queued tasks that have not yet
	// returned from their push into `done` (see wait_for_completion_pushes).
	pushes_in_flight &u32 = unsafe { nil }
}

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