Lines Matching +full:active +full:-
2 * Copyright 2013-2015 Samy Al Bahra
3 * Copyright 2013-2014 AppNexus, Inc.
37 struct _ck_array *active; in ck_array_create() local
39 active = allocator->malloc(sizeof(struct _ck_array) + sizeof(void *) * length); in ck_array_create()
40 if (active == NULL) in ck_array_create()
43 active->n_committed = 0; in ck_array_create()
44 active->length = length; in ck_array_create()
46 return active; in ck_array_create()
52 struct _ck_array *active; in ck_array_init() local
56 if (allocator->realloc == NULL || in ck_array_init()
57 allocator->malloc == NULL || in ck_array_init()
58 allocator->free == NULL || in ck_array_init()
62 active = ck_array_create(allocator, length); in ck_array_init()
63 if (active == NULL) in ck_array_init()
66 array->n_entries = 0; in ck_array_init()
67 array->allocator = allocator; in ck_array_init()
68 array->active = active; in ck_array_init()
69 array->transaction = NULL; in ck_array_init()
80 * If no transaction copy has been necessary, attempt to do in-place in ck_array_put()
83 if (array->transaction == NULL) { in ck_array_put()
84 target = array->active; in ck_array_put()
86 if (array->n_entries == target->length) { in ck_array_put()
87 size = target->length << 1; in ck_array_put()
89 target = array->allocator->realloc(target, in ck_array_put()
90 sizeof(struct _ck_array) + sizeof(void *) * array->n_entries, in ck_array_put()
97 ck_pr_store_uint(&target->length, size); in ck_array_put()
101 ck_pr_store_ptr(&array->active, target); in ck_array_put()
104 target->values[array->n_entries++] = value; in ck_array_put()
108 target = array->transaction; in ck_array_put()
109 if (array->n_entries == target->length) { in ck_array_put()
110 size = target->length << 1; in ck_array_put()
112 target = array->allocator->realloc(target, in ck_array_put()
113 sizeof(struct _ck_array) + sizeof(void *) * array->n_entries, in ck_array_put()
120 target->length = size; in ck_array_put()
121 array->transaction = target; in ck_array_put()
124 target->values[array->n_entries++] = value; in ck_array_put()
134 limit = array->n_entries; in ck_array_put_unique()
135 if (array->transaction != NULL) { in ck_array_put_unique()
136 v = array->transaction->values; in ck_array_put_unique()
138 v = array->active->values; in ck_array_put_unique()
146 return -!ck_array_put(array, value); in ck_array_put_unique()
155 if (array->transaction != NULL) { in ck_array_remove()
156 target = array->transaction; in ck_array_remove()
158 for (i = 0; i < array->n_entries; i++) { in ck_array_remove()
159 if (target->values[i] == value) { in ck_array_remove()
160 target->values[i] = target->values[--array->n_entries]; in ck_array_remove()
168 target = array->active; in ck_array_remove()
170 for (i = 0; i < array->n_entries; i++) { in ck_array_remove()
171 if (target->values[i] == value) in ck_array_remove()
175 if (i == array->n_entries) in ck_array_remove()
179 if (target->n_committed != array->n_entries) { in ck_array_remove()
180 ck_pr_store_ptr(&target->values[i], target->values[--array->n_entries]); in ck_array_remove()
189 target = ck_array_create(array->allocator, array->n_entries); in ck_array_remove()
193 memcpy(target->values, array->active->values, sizeof(void *) * array->n_entries); in ck_array_remove()
194 target->length = array->n_entries; in ck_array_remove()
195 target->n_committed = array->n_entries; in ck_array_remove()
196 target->values[i] = target->values[--array->n_entries]; in ck_array_remove()
198 array->transaction = target; in ck_array_remove()
205 struct _ck_array *m = array->transaction; in ck_array_commit()
210 m->n_committed = array->n_entries; in ck_array_commit()
212 p = array->active; in ck_array_commit()
213 ck_pr_store_ptr(&array->active, m); in ck_array_commit()
214 array->allocator->free(p, sizeof(struct _ck_array) + in ck_array_commit()
215 p->length * sizeof(void *), true); in ck_array_commit()
216 array->transaction = NULL; in ck_array_commit()
222 ck_pr_store_uint(&array->active->n_committed, array->n_entries); in ck_array_commit()
230 array->allocator->free(array->active, in ck_array_deinit()
231 sizeof(struct _ck_array) + sizeof(void *) * array->active->length, defer); in ck_array_deinit()
233 if (array->transaction != NULL) { in ck_array_deinit()
234 array->allocator->free(array->transaction, in ck_array_deinit()
235 sizeof(struct _ck_array) + sizeof(void *) * array->transaction->length, defer); in ck_array_deinit()
238 array->transaction = array->active = NULL; in ck_array_deinit()