aboutsummaryrefslogtreecommitdiffstats
path: root/source/core/core_job.h
blob: 611b1655ea7769c5cfcebe9147d3b88554ed511a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef CORE_JOB_H
#define CORE_JOB_H

// NOTE: multi producer / multi consumer deque of u32 job ids. used by the download pool.
// push_back is the bulk lane (--sync, "download all"), push_front is the urgent lane (the track
// you just pressed play on). a ring of plain u32s so popping is one cache line touch.

typedef struct JobQueue JobQueue;
struct JobQueue {
	CacheAligned SpinLock lock;
	u32  head;  // index of the front item
	u32  count;
	u32  capacity;
	u32  mask;
	u32 *items;

	CacheAligned Signal signal; // bumped on every push and on quit
	u32 quit;
};

internal void job_queue_init(Arena *arena, JobQueue *queue, u32 capacity_pow2);
internal b32  job_queue_push_back(JobQueue *queue, u32 item);
internal b32  job_queue_push_front(JobQueue *queue, u32 item);
internal b32  job_queue_pop(JobQueue *queue, u32 *out); // blocks, false once quit
internal u32  job_queue_count(JobQueue *queue);
internal void job_queue_quit(JobQueue *queue);

#endif // CORE_JOB_H