diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-06-11 23:24:02 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-06-11 23:24:02 +0200 |
commit | b9771b85d4f543af78465985e6350c0ca57f4c70 (patch) | |
tree | 012838e8e3a66d17b7220efdefd3ae2a17fed217 /04_exercise/arena/arena_list.h | |
parent | 7ecbcce58aa7a33915a150ad3f48924c1158779d (diff) | |
download | betriebssysteme-b9771b85d4f543af78465985e6350c0ca57f4c70.tar.gz betriebssysteme-b9771b85d4f543af78465985e6350c0ca57f4c70.zip |
Broken Mess
Diffstat (limited to '04_exercise/arena/arena_list.h')
-rw-r--r-- | 04_exercise/arena/arena_list.h | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/04_exercise/arena/arena_list.h b/04_exercise/arena/arena_list.h index 387f881..304209c 100644 --- a/04_exercise/arena/arena_list.h +++ b/04_exercise/arena/arena_list.h @@ -6,6 +6,9 @@ #define BETRIEBSYSTEME_ARENA_LIST_H #include <stdlib.h> +#include <stdbool.h> +#include <stdatomic.h> + typedef struct Node { void * value; struct Node * next; @@ -16,24 +19,39 @@ typedef struct List { Node * first; Node * last; } List; -// This structure manages an arena / memory slab to be used + + // Should we have a free list or just a bit set relative to the size of the slab? +/** This structure manages an arena / memory slab to be used + * This structure is thread-safe as it locks internally + * It will spin until a request is safe to access the items + * This also means this structure shouldn't be read externally + * unless the thread doing so managed to aquire the atomic_flag + */ typedef struct ArenaList { List freeList; List activeList; Node * arena; size_t size; -} ArenaList; + atomic_char lock; +} AtomicArenaList; +typedef bool (*SearchFunction)(void const *); //Initializes the node array -ArenaList alInit(Node * arena, size_t size); +AtomicArenaList alInit(Node * arena, size_t size); // Return -1 if the List is full -int alPush(ArenaList* al, void * value); +int alPush(AtomicArenaList * al, void * value); // Return -1 if the Node was already deleted -int alRemove(ArenaList* al, Node * node); +int alRemoveElem(AtomicArenaList * al, void * value); -// Return -1 if the Node was already deleted -int alRemoveElem(ArenaList* al, void * value); +/** + * Searches the activeList for an element + * for which the search function returns true + * The function will be passed the value pointer + * of a given Node + * @return the Element pointed or NULL if nothing matched + */ +void *alFindLastElem(AtomicArenaList *al, SearchFunction f); #endif // BETRIEBSYSTEME_ARENA_LIST_H |