]> git.sur5r.net Git - ngadmin/blob - lib/src/list.h
39a17513c444488826abc8154eac235370d0e27d
[ngadmin] / lib / src / list.h
1
2 #ifndef DEF_LIST
3 #define DEF_LIST
4
5
6 #include <stdlib.h>
7 #include <stdbool.h>
8 #include <string.h>
9 #include <pthread.h>
10
11
12
13
14 typedef struct ListNode ListNode;
15
16 struct ListNode {
17  void* data;
18  ListNode *prev, *next;
19 };
20
21
22 typedef struct {
23  ListNode *first, *last;
24  unsigned int count;
25  pthread_cond_t cond;
26  pthread_mutex_t mutex;
27 } List;
28
29
30
31
32 // Creates an empty list
33 List* createEmptyList (void);
34
35 // Destroys a list, and eventually frees the elements
36 // NOT MT SAFE
37 void destroyList (List *l, void (*freefunc)(void*));
38
39 // Adds an element at front of the list
40 void pushFrontList (List *l, void* data);
41
42 // Adds an element at back of the list
43 void pushBackList (List *l, void* data);
44
45 // Pops an element from the front of the list and returns its value
46 void* popFrontList (List *l);
47
48 // Pops an element from the back of the list and returns its value
49 void* popBackList (List *l);
50
51 // Clears all the items of the list, and eventually frees them
52 void clearList (List *l, void (*freefunc)(void*));
53
54 // Find and destroy a particular element of the list, and eventually frees it
55 bool findAndDestroy (List *l, void* data, void (*freefunc)(void*));
56
57 // Browse all the items of the list through the callback function
58 void browseList (List *l, void (*browsefunc)(void*));
59
60 // 
61 void* convertToArray (List *l, size_t sz);
62
63
64
65
66 #endif
67