From 29a84b47b31695983a14399d38ebcc6523cb1196 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Wed, 17 Jul 2013 23:52:19 -0400 Subject: [PATCH] ck_hs: Add ck_hs_move operation. This operation moves ownership from one hash set object to another and re-assigns callback functions to developer-specified values. This allows for dynamic configuration of allocation callbacks and is necessary for use-cases involving executable code which may be unmapped underneath the hash set. The developer is responsible for enforcing barriers and enforcing the visibility of the new hash set. --- include/ck_hs.h | 2 ++ src/ck_hs.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/ck_hs.h b/include/ck_hs.h index 4d0bc03..157c00c 100644 --- a/include/ck_hs.h +++ b/include/ck_hs.h @@ -88,6 +88,8 @@ typedef struct ck_hs_iterator ck_hs_iterator_t; void ck_hs_iterator_init(ck_hs_iterator_t *); bool ck_hs_next(ck_hs_t *, ck_hs_iterator_t *, void **); +bool ck_hs_move(ck_hs_t *, ck_hs_t *, ck_hs_hash_cb_t *, + ck_hs_compare_cb_t *, struct ck_malloc *); bool ck_hs_init(ck_hs_t *, unsigned int, ck_hs_hash_cb_t *, ck_hs_compare_cb_t *, struct ck_malloc *, unsigned long, unsigned long); void ck_hs_destroy(ck_hs_t *); diff --git a/src/ck_hs.c b/src/ck_hs.c index cac2505..597838c 100644 --- a/src/ck_hs.c +++ b/src/ck_hs.c @@ -582,6 +582,26 @@ ck_hs_remove(struct ck_hs *hs, return object; } +bool +ck_hs_move(struct ck_hs *hs, + struct ck_hs *source, + ck_hs_hash_cb_t *hf, + ck_hs_compare_cb_t *compare, + struct ck_malloc *m) +{ + + if (m == NULL || m->malloc == NULL || m->free == NULL || hf == NULL) + return false; + + hs->mode = source->mode; + hs->seed = source->seed; + hs->map = source->map; + hs->m = m; + hs->hf = hf; + hs->compare = compare; + return true; +} + bool ck_hs_init(struct ck_hs *hs, unsigned int mode,