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.
ck_pring
Samy Al Bahra 12 years ago
parent 721cc0605c
commit 29a84b47b3

@ -88,6 +88,8 @@ typedef struct ck_hs_iterator ck_hs_iterator_t;
void ck_hs_iterator_init(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_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 *, 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); ck_hs_compare_cb_t *, struct ck_malloc *, unsigned long, unsigned long);
void ck_hs_destroy(ck_hs_t *); void ck_hs_destroy(ck_hs_t *);

@ -582,6 +582,26 @@ ck_hs_remove(struct ck_hs *hs,
return object; 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 bool
ck_hs_init(struct ck_hs *hs, ck_hs_init(struct ck_hs *hs,
unsigned int mode, unsigned int mode,

Loading…
Cancel
Save