Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include <ctype.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <sys/time.h>
- #include <string.h>
- #include <stdint.h>
- #include "job_queue.h"
- pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
- pthread_cond_t fill = PTHREAD_COND_INITIALIZER;
- pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
- int job_queue_init(struct job_queue *job_queue, int capacity) { // alokerer plads
- job_queue->maxCapacity = capacity;
- job_queue->rear = 0;
- job_queue->front = 0;
- job_queue->buffer = malloc(sizeof(void*) * capacity);
- job_queue->available = capacity;
- return 0;
- }
- int job_queue_destroy(struct job_queue *job_queue) {
- assert(0);
- }
- int job_queue_push(struct job_queue *job_queue, void *data) {
- //if (job_queue->buffer[job_queue->rear]) //hvis der er noget på rear er bufferen ful
- while (job_queue->available == 0 ) // sørg for at sikre at den ikke kan blive negativ
- {
- pthread_cond_wait(&empty, &m);
- }
- job_queue->buffer[job_queue->rear] = data;
- job_queue->available--;
- job_queue->rear ++; // noget modulus hvis den overskrider max capacity
- pthread_cond_signal(&fill);
- //while ( )
- return 0;
- }
- int job_queue_pop(struct job_queue *job_queue, void **data) {
- assert(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement