ck_array: Add ck_array_initialized functionality.

The function returns true if the target is initialized, otherwise,
it returns false.
ck_pring
Samy Al Bahra 11 years ago
parent 59e38af2cd
commit a7cb0f9bbb

@ -32,6 +32,7 @@
#include <ck_malloc.h>
#include <ck_pr.h>
#include <stdbool.h>
#include <stddef.h>
struct _ck_array {
unsigned int n_committed;
@ -81,6 +82,13 @@ ck_array_buffer(struct ck_array *array, unsigned int *length)
return a->values;
}
CK_CC_INLINE static bool
ck_array_initialized(struct ck_array *array)
{
return ck_pr_load_ptr(&array->active) != NULL;
}
#define CK_ARRAY_FOREACH(a, i, b) \
(i)->snapshot = ck_pr_load_ptr(&(a)->active); \
ck_pr_fence_load(); \

@ -138,8 +138,14 @@ main(void)
if (i != ITERATION - 1 || ck_array_length(&array) != ITERATION - 1)
ck_error("Incorrect item count in iteration after unique put\n");
if (ck_array_initialized(&array) == false)
ck_error("Error, expected array to be initialized.\n");
ck_array_deinit(&array, false);
if (ck_array_initialized(&array) == true)
ck_error("Error, expected array to be uninitialized.\n");
return 0;
}

@ -238,6 +238,7 @@ ck_array_deinit(struct ck_array *array, bool defer)
sizeof(struct _ck_array) + sizeof(void *) * array->transaction->length, defer);
}
array->transaction = array->active = NULL;
return;
}

Loading…
Cancel
Save