diff --git a/include/refcount.h b/include/refcount.h index c6c1ed8..bd6a046 100644 --- a/include/refcount.h +++ b/include/refcount.h @@ -83,6 +83,10 @@ void libab_ref_free(libab_ref* ref); * Copies this reference, thereby increasing the reference count. */ void libab_ref_copy(const libab_ref* ref, libab_ref* into); +/** + * Swaps the contents of two references. + */ +void libab_ref_swap(libab_ref* left, libab_ref* right); /** * Function that can be passed in to refcount to simply use free * when the refcount reaches 0. diff --git a/src/refcount.c b/src/refcount.c index 93a2963..92a638f 100644 --- a/src/refcount.c +++ b/src/refcount.c @@ -57,6 +57,13 @@ void libab_ref_copy(const libab_ref* ref, libab_ref* into) { memcpy(into, ref, sizeof(*ref)); } +void libab_ref_swap(libab_ref* left, libab_ref* right) { + libab_ref tmp; + tmp = *left; + *left = *right; + *right = tmp; +} + void libab_ref_data_free(void* data) { free(data); } void* libab_ref_get(const libab_ref* ref) {