00001 00004 #ifndef RAZORBACK_LIST_H 00005 #define RAZORBACK_LIST_H 00006 #include <stdint.h> 00007 #include <stdlib.h> 00008 #ifdef _MSC_VER 00009 #else //_MSC_VER 00010 #include <stdbool.h> 00011 #endif //_MSC_VER 00012 #include <razorback/visibility.h> 00013 #include <razorback/lock.h> 00014 00015 #ifdef __cplusplus 00016 extern "C" { 00017 #endif 00018 00022 #define LIST_MODE_GENERIC 0 ///< Generic list 00023 #define LIST_MODE_STACK 1 ///< Stack list 00024 #define LIST_MODE_QUEUE 2 ///< Queue list 00025 00026 00030 #define LIST_EACH_OK 0 ///< Node successfully processed 00031 #define LIST_EACH_ERROR 1 ///< Error processing node 00032 #define LIST_EACH_REMOVE 2 ///< Node successfully processed, remove from list. 00033 00034 00037 struct ListNode 00038 { 00039 struct ListNode *next; 00040 struct ListNode *prev; 00041 void *item; 00042 }; 00043 00046 struct List 00047 { 00048 struct ListNode *head; 00049 struct ListNode *tail; 00050 size_t length; 00051 int mode; 00052 int (*cmp)(void *, void *); 00053 int (*keyCmp)(void *, void *); 00054 void (*destroy)(void *); 00055 void *(*clone)(void *); 00056 void (*nodeLock)(void *); 00057 void (*nodeUnlock)(void *); 00058 struct Mutex *lock; 00059 struct Semaphore *sem; 00060 }; 00061 00072 SO_PUBLIC extern struct List * List_Create(int mode, 00073 int (*cmp)(void *, void *), 00074 int (*keyCmp)(void *, void *), 00075 void (*destroy)(void *), 00076 void *(*clone)(void *), 00077 void (*nodeLock)(void *), 00078 void (*nodeUnlock)(void *)); 00079 00085 SO_PUBLIC extern bool List_Push(struct List *list, void *item); 00086 00092 SO_PUBLIC extern void * List_Pop(struct List *list); 00093 00098 SO_PUBLIC extern void List_Remove(struct List *list, void *item); 00099 00105 SO_PUBLIC extern void * List_Find(struct List *list, void *id); 00106 00113 SO_PUBLIC extern bool List_ForEach(struct List *list, int (*op)(void *i, void *ud), void *userData); 00114 00119 SO_PUBLIC extern size_t List_Length(struct List *list); 00120 00124 SO_PUBLIC extern void List_Clear(struct List *list); 00129 SO_PUBLIC extern void List_Lock(struct List *list); 00130 00135 SO_PUBLIC extern void List_Unlock(struct List *list); 00136 00140 SO_PUBLIC extern void List_Destroy(struct List *list); 00141 00147 SO_PUBLIC extern struct List* List_Clone (struct List *source); 00148 00149 #ifdef __cplusplus 00150 } 00151 #endif 00152 #endif //RAZORBACK_LIST_H