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 29 30
|
.
..
...
internal void win32_create_queue(Os_Job_Queue *queue, int number_of_thread)
{
zero_struct(*queue);
queue->semaphore = CreateSemaphoreA(0, 0, number_of_thread, NULL); // CreateSemaphoreExA that I should use, seems this doesn't exist.
for(int i = 0; i < number_of_thread; i++)
{
HANDLE thread = CreateThread(0, 0, win32_thread_proc, queue, 0, 0);
CloseHandle(thread);
}
}
os_add_job_to_queue(struct Os_Job_Queue *queue, Os_Job_Callback *callback, void *data)
{
u32 volatile new_next_entry_to_write = (queue->next_entry_to_write + 1) % array_count(queue->entries);
assert(new_next_entry_to_write != queue->next_entry_to_read); // Fails with a small queue
Os_Job *entry = queue->entries + queue->next_entry_to_write;
entry->callback = callback;
entry->data = data;
//_WriteBarrier(); // <- not working
queue->next_entry_to_write = new_next_entry_to_write;
ReleaseSemaphore(queue->semaphore, 1, 0);
}
...
..
.
|