diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-27 23:12:56 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-27 23:12:56 +0100 |
commit | 6c2649ab27f96dcc40a1f01a36a07d1603f39c51 (patch) | |
tree | 32e5ddf8ea76619da45cc27578673a15d7399910 /src/queue.h | |
parent | 5e70122b5481c878aa0773281304c4d68062cf7d (diff) | |
download | fastd-6c2649ab27f96dcc40a1f01a36a07d1603f39c51.tar fastd-6c2649ab27f96dcc40a1f01a36a07d1603f39c51.zip |
Add timeout to task queue
Diffstat (limited to 'src/queue.h')
-rw-r--r-- | src/queue.h | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/src/queue.h b/src/queue.h index a196153..e26946b 100644 --- a/src/queue.h +++ b/src/queue.h @@ -29,6 +29,7 @@ #define _FASTD_QUEUE_H_ #include <stdlib.h> +#include <time.h> typedef struct _fastd_queue_entry fastd_queue_entry; @@ -36,39 +37,16 @@ typedef struct _fastd_queue_entry fastd_queue_entry; struct _fastd_queue_entry { fastd_queue_entry *next; void *data; + struct timespec timeout; }; typedef struct _fastd_queue { fastd_queue_entry *head; - fastd_queue_entry *tail; } fastd_queue; -static inline void fastd_queue_put(fastd_queue *queue, void *data) { - fastd_queue_entry *entry = malloc(sizeof(fastd_queue_entry)); - entry->next = NULL; - entry->data = data; - - if (queue->tail) - queue->tail->next = entry; - else - queue->head = entry; - - queue->tail = entry; -} - -static inline void* fastd_queue_get(fastd_queue *queue) { - if (!queue->head) - return NULL; - - fastd_queue_entry *entry = queue->head; - queue->head = entry->next; - if (!queue->head) - queue->tail = NULL; - - void *data = entry->data; - free(entry); - return data; -} +void fastd_queue_put(fastd_queue *queue, void *data, int timeout); +void* fastd_queue_get(fastd_queue *queue); +int fastd_queue_timeout(fastd_queue *queue); #endif /* _FASTD_QUEUE_H_ */ |