This commit is contained in:
Nikolaj
2021-10-26 14:15:16 +02:00
parent b57db9596c
commit a988405fd3
10 changed files with 616 additions and 0 deletions

30
A2/job_queue.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef JOB_QUEUE_H
#define JOB_QUEUE_H
#include <pthread.h>
struct job_queue {
int dummy;
};
// Initialise a job queue with the given capacity. The queue starts out
// empty. Returns non-zero on error.
int job_queue_init(struct job_queue *job_queue, int capacity);
// Destroy the job queue. Blocks until the queue is empty before it
// is destroyed.
int job_queue_destroy(struct job_queue *job_queue);
// Push an element onto the end of the job queue. Blocks if the
// job_queue is full (its size is equal to its capacity). Returns
// non-zero on error. It is an error to push a job onto a queue that
// has been destroyed.
int job_queue_push(struct job_queue *job_queue, void *data);
// Pop an element from the front of the job queue. Blocks if the
// job_queue contains zero elements. Returns non-zero on error. If
// job_queue_destroy() has been called (possibly after the call to
// job_queue_pop() blocked), this function will return -1.
int job_queue_pop(struct job_queue *job_queue, void **data);
#endif