diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ll-internal.c | 12 | ||||
| -rw-r--r-- | src/ll-internal.h | 27 | ||||
| -rw-r--r-- | src/ll.c | 28 | ||||
| -rw-r--r-- | src/ll.h | 2 | ||||
| -rw-r--r-- | src/threadpool.c | 7 |
5 files changed, 47 insertions, 29 deletions
diff --git a/src/ll-internal.c b/src/ll-internal.c new file mode 100644 index 0000000..1a4fe3c --- /dev/null +++ b/src/ll-internal.c | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #include "ll-internal.h" | ||
| 2 | #include "shared.h" | ||
| 3 | |||
| 4 | dllnode * dllnode_init(void *data, dll_freecb fcb) { | ||
| 5 | dllnode *n = xcalloc(1, sizeof(*n)); | ||
| 6 | n->data = data; | ||
| 7 | n->freecb = fcb; | ||
| 8 | n->prev = NULL; | ||
| 9 | n->next = NULL; | ||
| 10 | |||
| 11 | return n; | ||
| 12 | } \ No newline at end of file | ||
diff --git a/src/ll-internal.h b/src/ll-internal.h new file mode 100644 index 0000000..f627807 --- /dev/null +++ b/src/ll-internal.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #ifndef __VXGG_REWRITE___LL_INTERNAL_H___21242172227746___ | ||
| 2 | #define __VXGG_REWRITE___LL_INTERNAL_H___21242172227746___ | ||
| 3 | |||
| 4 | #define __VXGG_REWRITE___LL_INTERNAL___ | ||
| 5 | #include "ll.h" | ||
| 6 | |||
| 7 | typedef struct dll { | ||
| 8 | void *data; | ||
| 9 | dll_freecb freecb; | ||
| 10 | |||
| 11 | struct dll *next; | ||
| 12 | struct dll *prev; | ||
| 13 | |||
| 14 | } dllnode; | ||
| 15 | typedef struct dlinked { | ||
| 16 | int size; | ||
| 17 | dllnode *start; | ||
| 18 | dllnode *end; | ||
| 19 | |||
| 20 | } dlinkedlist; | ||
| 21 | |||
| 22 | dllnode * dllnode_init(void *data, dll_freecb fcb); | ||
| 23 | |||
| 24 | // Note: This file exists because I want to reuse dlinkedlist's definitions from threadpool to create a concurrent queue without | ||
| 25 | // sacrificing the opaqueness of the definition | ||
| 26 | |||
| 27 | #endif \ No newline at end of file | ||
| @@ -1,38 +1,12 @@ | |||
| 1 | #include "ll.h" | 1 | #include "ll.h" |
| 2 | #include "ll-internal.h" | ||
| 2 | #include "shared.h" | 3 | #include "shared.h" |
| 3 | 4 | ||
| 4 | #include <asm-generic/errno-base.h> | ||
| 5 | #include <stddef.h> | 5 | #include <stddef.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 7 | #include <errno.h> | 7 | #include <errno.h> |
| 8 | #include <error.h> | 8 | #include <error.h> |
| 9 | 9 | ||
| 10 | typedef struct dll { | ||
| 11 | void *data; | ||
| 12 | dll_freecb freecb; | ||
| 13 | |||
| 14 | struct dll *next; | ||
| 15 | struct dll *prev; | ||
| 16 | |||
| 17 | } dllnode; | ||
| 18 | typedef struct dlinked { | ||
| 19 | int size; | ||
| 20 | dllnode *start; | ||
| 21 | dllnode *end; | ||
| 22 | |||
| 23 | } dlinkedlist; | ||
| 24 | |||
| 25 | |||
| 26 | dllnode * dllnode_init(void *data, dll_freecb fcb) { | ||
| 27 | dllnode *n = xcalloc(1, sizeof(*n)); | ||
| 28 | n->data = data; | ||
| 29 | n->freecb = fcb; | ||
| 30 | n->prev = NULL; | ||
| 31 | n->next = NULL; | ||
| 32 | |||
| 33 | return n; | ||
| 34 | } | ||
| 35 | |||
| 36 | dlinkedlist * dlinkedlist_init(void) { | 10 | dlinkedlist * dlinkedlist_init(void) { |
| 37 | dlinkedlist *ll = xcalloc(1, sizeof(*ll)); | 11 | dlinkedlist *ll = xcalloc(1, sizeof(*ll)); |
| 38 | ll->end = NULL; | 12 | ll->end = NULL; |
| @@ -24,6 +24,7 @@ | |||
| 24 | typedef void (*dll_freecb)(void*); | 24 | typedef void (*dll_freecb)(void*); |
| 25 | typedef struct dlinked dlinkedlist; | 25 | typedef struct dlinked dlinkedlist; |
| 26 | 26 | ||
| 27 | #ifndef __VXGG_REWRITE___LL_INTERNAL___ | ||
| 27 | dlinkedlist * dlinkedlist_init(void); | 28 | dlinkedlist * dlinkedlist_init(void); |
| 28 | void dlinkedlist_free(dlinkedlist *ll); | 29 | void dlinkedlist_free(dlinkedlist *ll); |
| 29 | int dlinkedlist_append(dlinkedlist * const ll, void *data, dll_freecb fcb); | 30 | int dlinkedlist_append(dlinkedlist * const ll, void *data, dll_freecb fcb); |
| @@ -36,5 +37,6 @@ int dlinkedlist_size(const dlinkedlist * const ll); | |||
| 36 | #define dlinkedlist_isempty(ll) (dlinkedlist_size((ll)) == 0) | 37 | #define dlinkedlist_isempty(ll) (dlinkedlist_size((ll)) == 0) |
| 37 | 38 | ||
| 38 | int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)); | 39 | int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)); |
| 40 | #endif | ||
| 39 | 41 | ||
| 40 | #endif \ No newline at end of file | 42 | #endif \ No newline at end of file |
diff --git a/src/threadpool.c b/src/threadpool.c index 8f1cf0b..d058d52 100644 --- a/src/threadpool.c +++ b/src/threadpool.c | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | #include "threadpool.h" | 1 | #include "threadpool.h" |
| 2 | #include "shared.h" | 2 | #include "shared.h" |
| 3 | 3 | ||
| 4 | #include "ll-internal.h" | ||
| 5 | #include "ll.h" | ||
| 6 | |||
| 4 | #include <threads.h> | 7 | #include <threads.h> |
| 5 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 6 | #include <errno.h> | 9 | #include <errno.h> |
| @@ -31,7 +34,7 @@ mtxpair * mtxpair_init(void * const data, int type) { | |||
| 31 | 34 | ||
| 32 | // Init the mutex | 35 | // Init the mutex |
| 33 | if(mtx_init(mtxp->mtx, type) == thrd_error) { | 36 | if(mtx_init(mtxp->mtx, type) == thrd_error) { |
| 34 | free(mtxp); free(mtxp->mtx); | 37 | free(mtxp->mtx); free(mtxp); |
| 35 | RETURNWERR(errno, NULL); | 38 | RETURNWERR(errno, NULL); |
| 36 | } | 39 | } |
| 37 | 40 | ||
| @@ -93,7 +96,7 @@ int thrd_createwmx(thrd_t * const thr, thrd_start_t func, mtxpair * const mtxd) | |||
| 93 | // Here's a good reference of this implemented in C++ using Boost: https://gist.github.com/mikeando/482342 | 96 | // Here's a good reference of this implemented in C++ using Boost: https://gist.github.com/mikeando/482342 |
| 94 | 97 | ||
| 95 | typedef struct cq { | 98 | typedef struct cq { |
| 96 | 99 | void*placehoilder; | |
| 97 | } cqueue; | 100 | } cqueue; |
| 98 | 101 | ||
| 99 | typedef struct task { | 102 | typedef struct task { |
