From d47f45a5e3e40b48131409071b119b442c78bffc Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Thu, 17 Apr 2025 21:56:23 -0500 Subject: Create ll-internal files to maintain opaqueness of linked list while opening it up for reuse --- src/ll-internal.c | 12 ++++++++++++ src/ll-internal.h | 27 +++++++++++++++++++++++++++ src/ll.c | 28 +--------------------------- src/ll.h | 2 ++ src/threadpool.c | 7 +++++-- 5 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 src/ll-internal.c create mode 100644 src/ll-internal.h 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 @@ +#include "ll-internal.h" +#include "shared.h" + +dllnode * dllnode_init(void *data, dll_freecb fcb) { + dllnode *n = xcalloc(1, sizeof(*n)); + n->data = data; + n->freecb = fcb; + n->prev = NULL; + n->next = NULL; + + return n; +} \ 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 @@ +#ifndef __VXGG_REWRITE___LL_INTERNAL_H___21242172227746___ +#define __VXGG_REWRITE___LL_INTERNAL_H___21242172227746___ + +#define __VXGG_REWRITE___LL_INTERNAL___ +#include "ll.h" + +typedef struct dll { + void *data; + dll_freecb freecb; + + struct dll *next; + struct dll *prev; + +} dllnode; +typedef struct dlinked { + int size; + dllnode *start; + dllnode *end; + +} dlinkedlist; + +dllnode * dllnode_init(void *data, dll_freecb fcb); + +// Note: This file exists because I want to reuse dlinkedlist's definitions from threadpool to create a concurrent queue without +// sacrificing the opaqueness of the definition + +#endif \ No newline at end of file diff --git a/src/ll.c b/src/ll.c index d25818a..9bb1441 100644 --- a/src/ll.c +++ b/src/ll.c @@ -1,38 +1,12 @@ #include "ll.h" +#include "ll-internal.h" #include "shared.h" -#include #include #include #include #include -typedef struct dll { - void *data; - dll_freecb freecb; - - struct dll *next; - struct dll *prev; - -} dllnode; -typedef struct dlinked { - int size; - dllnode *start; - dllnode *end; - -} dlinkedlist; - - -dllnode * dllnode_init(void *data, dll_freecb fcb) { - dllnode *n = xcalloc(1, sizeof(*n)); - n->data = data; - n->freecb = fcb; - n->prev = NULL; - n->next = NULL; - - return n; -} - dlinkedlist * dlinkedlist_init(void) { dlinkedlist *ll = xcalloc(1, sizeof(*ll)); ll->end = NULL; diff --git a/src/ll.h b/src/ll.h index 1824b49..3636e77 100644 --- a/src/ll.h +++ b/src/ll.h @@ -24,6 +24,7 @@ typedef void (*dll_freecb)(void*); typedef struct dlinked dlinkedlist; +#ifndef __VXGG_REWRITE___LL_INTERNAL___ dlinkedlist * dlinkedlist_init(void); void dlinkedlist_free(dlinkedlist *ll); int dlinkedlist_append(dlinkedlist * const ll, void *data, dll_freecb fcb); @@ -36,5 +37,6 @@ int dlinkedlist_size(const dlinkedlist * const ll); #define dlinkedlist_isempty(ll) (dlinkedlist_size((ll)) == 0) int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)); +#endif #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 @@ #include "threadpool.h" #include "shared.h" +#include "ll-internal.h" +#include "ll.h" + #include #include #include @@ -31,7 +34,7 @@ mtxpair * mtxpair_init(void * const data, int type) { // Init the mutex if(mtx_init(mtxp->mtx, type) == thrd_error) { - free(mtxp); free(mtxp->mtx); + free(mtxp->mtx); free(mtxp); RETURNWERR(errno, NULL); } @@ -93,7 +96,7 @@ int thrd_createwmx(thrd_t * const thr, thrd_start_t func, mtxpair * const mtxd) // Here's a good reference of this implemented in C++ using Boost: https://gist.github.com/mikeando/482342 typedef struct cq { - + void*placehoilder; } cqueue; typedef struct task { -- cgit v1.2.3