Adjust job queue to take a union as payload
This commit is contained in:
parent
c72c82484a
commit
2db9b2df53
3 changed files with 26 additions and 22 deletions
|
@ -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;
|
||||
|
|
|
@ -37,13 +37,20 @@
|
|||
#include <semaphore.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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
|
||||
|
|
12
src/jobq.c
12
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue