From eb068a13cf83faf15a2db6ca4046975d303fa6c6 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 6 Jan 2021 18:54:42 -0800 Subject: [PATCH] Cleanup and get ck_array changes to compile --- ck-polyfill.c | 50 ++------------------------------------------------ ck-polyfill.h | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 65 deletions(-) diff --git a/ck-polyfill.c b/ck-polyfill.c index 7e9b83ba..c9ceebe6 100644 --- a/ck-polyfill.c +++ b/ck-polyfill.c @@ -57,6 +57,7 @@ ck_array_put_unique(ck_array_t *array, void *pointer) pthread_mutex_lock(&(array->lock)); hashset_add(array->hs, pointer); pthread_mutex_unlock(&(array->lock)); + return true; } // DESCRIPTION @@ -75,6 +76,7 @@ ck_array_remove(ck_array_t *array, void *pointer){ pthread_mutex_lock(&(array->lock)); hashset_remove(array->hs, pointer); pthread_mutex_unlock(&(array->lock)); + return true; } // DESCRIPTION @@ -124,51 +126,3 @@ bool ck_pr_cas_8(uint8_t *target, uint8_t old_value, uint8_t new_value) return false; } -bool ck_array_init(ck_array_t *array, unsigned int mode, - struct ck_malloc *allocator, unsigned int initial_length) -{ - // TODO: init mutex, data structure -} - -// DESCRIPTION -// The ck_array_put_unique(3) function will attempt to insert the value of -// pointer into the array pointed to by array. This function may incur -// additional memory allocations if not enough memory has been allocated in -// the array for a new entry. The operation is also free to apply the opera- -// tion immediately if there is an opportunity for elimination with a pend- -// ing (uncommitted) remove operation. The function will not make any modi- -// fications if the pointer already exists in the array. -// -// RETURN VALUES -// This function returns 1 if the pointer already exists in the array. It -// returns 0 if the put operation succeeded. It returns -1 on error due to -// internal memory allocation failures. -int -ck_array_put_unique(ck_array_t *array, void *pointer); - -// DESCRIPTION -// The ck_array_remove(3) function will attempt to remove the value of -// pointer into the array pointed to by array. The operation is also free to -// apply the operation immediately if there is an opportunity for elimina- -// tion with a pending (uncommitted) put operation. If no elimination was -// possible, the function may require to allocate more memory. -// -// RETURN VALUES -// This function returns true if the remove operation succeeded. It will -// return false otherwise due to internal allocation failures or because the -// value did not exist. -bool -ck_array_remove(ck_array_t *array, void *pointer); - - -// DESCRIPTION -// The ck_array_commit(3) function will commit any pending put or remove -// operations associated with the array. The function may end up requesting -// the safe reclamation of memory actively being iterated upon by other -// threads. -// -// RETURN VALUES -// This function returns true if the commit operation succeeded. It will -// return false otherwise, and pending operations will not be applied. -bool -ck_array_commit(ck_array_t *array); diff --git a/ck-polyfill.h b/ck-polyfill.h index c4f92b30..a70511ed 100644 --- a/ck-polyfill.h +++ b/ck-polyfill.h @@ -12,7 +12,7 @@ void ck_polyfill_init(); struct ck_array { pthread_mutex_t lock; hashset_t hs; -} +}; typedef struct ck_array ck_array_t; struct ck_array_iterator { @@ -93,22 +93,20 @@ ck_array_commit(ck_array_t *array); // TODO: // Can we safely lock the array, make a copy, and interate over that???? -#define CK_ARRAY_FOREACH(a, i, b) \ - pthread_mutex_lock(&(a->lock)); - size_t *tmp = calloc(a->hs->nitems, sizeof(struct hashset_st)); - int tmpc = a->hs->nitems; - // TODO: just do this in the loop below, this is unnecessary - for (unsigned int tmpi = 0, tmpii = 0; tmpi < tmpc; tmpi++) { - if (a->hs->items != 0 && a->hs->items != 1) { - tmp[tmpii] = a->hs->items[tmpi]; - tmpii++; - } - } - pthread_mutex_unlock(&(a->lock)); - for (unsigned int _ck_i = 0; - _ck_i < (a)->active->n_committed && - ((*b) = (a)->active->values[_ck_i], 1); - _ck_i++) +#define CK_ARRAY_FOREACH(a, i, b) \ + pthread_mutex_lock(&((a)->lock)); \ + int tmpc = (a)->hs->nitems; \ + size_t *tmp = calloc(tmpc, sizeof(struct hashset_st)); \ + for (unsigned int tmpi = 0, tmpii = 0; tmpi < tmpc; tmpi++) { \ + if ((a)->hs->items != 0 && (a)->hs->items != 1) { \ + tmp[tmpii] = (a)->hs->items[tmpi]; \ + tmpii++; \ + } \ + } \ + pthread_mutex_unlock(&((a)->lock)); \ + for (unsigned int _ck_i = 0, (*b) = (a)->hs->items[_ck_i]; \ + _ck_i < tmpc; \ + _ck_i++, (*b) = (a)->hs->items[_ck_i]) // CAS section bool