summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-04-17 21:56:23 -0500
committer@syxhe <https://t.me/syxhe>2025-04-17 21:56:23 -0500
commitd47f45a5e3e40b48131409071b119b442c78bffc (patch)
tree95e95ac5cbf2be1fec5402452d586a3400d90a02
parent9bd10281119a28323ddd05bd13827bceb553cc56 (diff)
Create ll-internal files to maintain opaqueness of linked list while opening it up for reuse
-rw-r--r--src/ll-internal.c12
-rw-r--r--src/ll-internal.h27
-rw-r--r--src/ll.c28
-rw-r--r--src/ll.h2
-rw-r--r--src/threadpool.c7
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
4dllnode * 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
7typedef struct dll {
8 void *data;
9 dll_freecb freecb;
10
11 struct dll *next;
12 struct dll *prev;
13
14} dllnode;
15typedef struct dlinked {
16 int size;
17 dllnode *start;
18 dllnode *end;
19
20} dlinkedlist;
21
22dllnode * 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
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 @@
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
10typedef struct dll {
11 void *data;
12 dll_freecb freecb;
13
14 struct dll *next;
15 struct dll *prev;
16
17} dllnode;
18typedef struct dlinked {
19 int size;
20 dllnode *start;
21 dllnode *end;
22
23} dlinkedlist;
24
25
26dllnode * 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
36dlinkedlist * dlinkedlist_init(void) { 10dlinkedlist * 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;
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 @@
24typedef void (*dll_freecb)(void*); 24typedef void (*dll_freecb)(void*);
25typedef struct dlinked dlinkedlist; 25typedef struct dlinked dlinkedlist;
26 26
27#ifndef __VXGG_REWRITE___LL_INTERNAL___
27dlinkedlist * dlinkedlist_init(void); 28dlinkedlist * dlinkedlist_init(void);
28void dlinkedlist_free(dlinkedlist *ll); 29void dlinkedlist_free(dlinkedlist *ll);
29int dlinkedlist_append(dlinkedlist * const ll, void *data, dll_freecb fcb); 30int 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
38int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)); 39int 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
95typedef struct cq { 98typedef struct cq {
96 99 void*placehoilder;
97} cqueue; 100} cqueue;
98 101
99typedef struct task { 102typedef struct task {