diff --git a/include/haggis.h b/include/haggis.h index 454b85c..9a49de0 100644 --- a/include/haggis.h +++ b/include/haggis.h @@ -38,23 +38,20 @@ typedef uint8_t u8; -union _u16 { +typedef union { uint16_t val; u8 bytes[2]; -}; -typedef union _u16 u16; +} u16; -union _u32 { +typedef union { uint32_t val; u8 bytes[4]; -}; -typedef union _u32 u32; +} u32; -union _u64 { +typedef union { uint64_t val; u8 bytes[8]; -}; -typedef union _u64 u64; +} u64; typedef struct { u32 major; diff --git a/include/jobq.h b/include/jobq.h index 056b33f..c00c92b 100644 --- a/include/jobq.h +++ b/include/jobq.h @@ -37,13 +37,20 @@ #include #include -struct _job { - struct _job *prev; - char *fname; - struct _job *next; +#include "haggis.h" + +typedef union { + haggis_node *node; + char *f_name; +} haggis_job; + +struct _job_node { + struct _job_node *prev; + haggis_job *job; + struct _job_node *next; }; -typedef struct _job haggis_jobq_node; +typedef struct _job_node haggis_jobq_node; typedef struct { sem_t *sem; @@ -52,7 +59,7 @@ typedef struct { haggis_jobq_node *tail; } haggis_jobq; -int haggis_jobq_push(haggis_jobq *queue, char *fname); -char* haggis_jobq_pop(haggis_jobq *queue); +int haggis_jobq_push(haggis_jobq *queue, haggis_job *job); +haggis_job* haggis_jobq_pop(haggis_jobq *queue); #endif // !JOBQ_H diff --git a/src/jobq.c b/src/jobq.c index 23817b1..4c470f5 100644 --- a/src/jobq.c +++ b/src/jobq.c @@ -32,11 +32,11 @@ #include "jobq.h" -int haggis_jobq_push(haggis_jobq *queue, char *fname) { +int haggis_jobq_push(haggis_jobq *queue, haggis_job *job) { haggis_jobq_node *new = malloc(sizeof(haggis_jobq_node)); if (new == NULL) return 1; - new->fname = fname; + new->job = job; new->next = new->prev = NULL; pthread_mutex_lock(queue->mutex); @@ -51,14 +51,14 @@ int haggis_jobq_push(haggis_jobq *queue, char *fname) { return sem_post(queue->sem); } -char* haggis_jobq_pop(haggis_jobq *queue) { +haggis_job* haggis_jobq_pop(haggis_jobq *queue) { haggis_jobq_node *j; - char *fname; + haggis_job *job; sem_wait(queue->sem); pthread_mutex_lock(queue->mutex); j = queue->head; - fname = j->fname; + job = j->job; if (queue->tail == queue->head) { queue->tail = queue->head = NULL; } else { @@ -68,5 +68,5 @@ char* haggis_jobq_pop(haggis_jobq *queue) { pthread_mutex_unlock(queue->mutex); if (sem_post(queue->sem) != 0) return NULL; - return fname; + return job; }