summaryrefslogtreecommitdiffstats
path: root/libdimension/array.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-06-22 05:32:04 +0000
committerTavian Barnes <tavianator@gmail.com>2009-06-22 05:32:04 +0000
commitd23bff8a2eee13eec0724aabe5d9a86b126c4b2c (patch)
tree20541946b210329d516e606842745d1504deb8b8 /libdimension/array.c
parent3eb41435e3c266a6a8f3496ffa5d832f5951c50f (diff)
downloaddimension-d23bff8a2eee13eec0724aabe5d9a86b126c4b2c.tar.xz
Add interface for performing long tasks in background, while giving a
progress indication.
Diffstat (limited to 'libdimension/array.c')
-rw-r--r--libdimension/array.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/libdimension/array.c b/libdimension/array.c
index c106f2f..f0378cf 100644
--- a/libdimension/array.c
+++ b/libdimension/array.c
@@ -25,7 +25,6 @@
/* The raw implementations, which don't do any thread synchronicity */
static void dmnsn_array_get_impl(const dmnsn_array *array, size_t i, void *obj);
static void dmnsn_array_set_impl(dmnsn_array *array, size_t i, const void *obj);
-static void dmnsn_array_resize_impl(dmnsn_array *array, size_t length);
dmnsn_array *
dmnsn_new_array(size_t obj_size)
@@ -73,7 +72,7 @@ dmnsn_array_pop(dmnsn_array *array, void *obj)
{
dmnsn_array_wrlock(array);
dmnsn_array_get_impl(array, array->length - 1, obj);
- dmnsn_array_resize_impl(array, array->length - 1);
+ dmnsn_array_resize_unlocked(array, array->length - 1);
dmnsn_array_unlock(array);
}
@@ -97,30 +96,21 @@ void
dmnsn_array_resize(dmnsn_array *array, size_t length)
{
dmnsn_array_wrlock(array);
- dmnsn_array_resize_impl(array, length);
+ dmnsn_array_resize_unlocked(array, length);
dmnsn_array_unlock(array);
}
-static void
-dmnsn_array_get_impl(const dmnsn_array *array, size_t i, void *obj)
+void *
+dmnsn_array_at(dmnsn_array *array, size_t i)
{
if (i >= array->length) {
dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds.");
}
- memcpy(obj, array->ptr + array->obj_size*i, array->obj_size);
-}
-
-static void
-dmnsn_array_set_impl(dmnsn_array *array, size_t i, const void *obj)
-{
- if (i >= array->length) {
- dmnsn_array_resize_impl(array, i + 1);
- }
- memcpy(array->ptr + array->obj_size*i, obj, array->obj_size);
+ return array->ptr + array->obj_size*i;
}
-static void
-dmnsn_array_resize_impl(dmnsn_array *array, size_t length)
+void
+dmnsn_array_resize_unlocked(dmnsn_array *array, size_t length)
{
if (length > array->capacity) {
array->capacity = length*2; /* We are greedy */
@@ -133,15 +123,6 @@ dmnsn_array_resize_impl(dmnsn_array *array, size_t length)
array->length = length;
}
-void *
-dmnsn_array_at(dmnsn_array *array, size_t i)
-{
- if (i >= array->length) {
- dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds.");
- }
- return array->ptr + array->obj_size*i;
-}
-
void
dmnsn_array_rdlock(const dmnsn_array *array)
{
@@ -173,3 +154,21 @@ dmnsn_array_unlock(const dmnsn_array *array)
dmnsn_error(DMNSN_SEVERITY_MEDIUM, "Couldn't unlock array.");
}
}
+
+static void
+dmnsn_array_get_impl(const dmnsn_array *array, size_t i, void *obj)
+{
+ if (i >= array->length) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Array index out of bounds.");
+ }
+ memcpy(obj, array->ptr + array->obj_size*i, array->obj_size);
+}
+
+static void
+dmnsn_array_set_impl(dmnsn_array *array, size_t i, const void *obj)
+{
+ if (i >= array->length) {
+ dmnsn_array_resize_unlocked(array, i + 1);
+ }
+ memcpy(array->ptr + array->obj_size*i, obj, array->obj_size);
+}