diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-06-22 05:31:53 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-06-22 05:31:53 +0000 |
commit | 3eb41435e3c266a6a8f3496ffa5d832f5951c50f (patch) | |
tree | f98b57a0f947c86552c564a13b007dc7bf45fe0e /libdimension/dimension | |
parent | c4b1e00954c6934b081cbf3b26c55222b351cc46 (diff) | |
download | dimension-3eb41435e3c266a6a8f3496ffa5d832f5951c50f.tar.xz |
Make dmnsn_array*'s thread safe.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/array.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h index 0a64952..30a119d 100644 --- a/libdimension/dimension/array.h +++ b/libdimension/dimension/array.h @@ -22,28 +22,38 @@ #define DIMENSION_ARRAY_H /* - * Simple generalized arrays, for returning variable-length arrays from - * functions, and other fun stuff. + * Simple thread-safe generalized arrays, for returning variable-length arrays + * from functions, and other fun stuff. */ -#include <stdlib.h> /* For size_t */ +#include <pthread.h> /* For pthread_rwlock_t */ +#include <stdlib.h> /* For size_t */ typedef struct { void *ptr; size_t obj_size, length, capacity; + + /* Synchronicity control (pointer so it's not const) */ + pthread_rwlock_t *rwlock; } dmnsn_array; dmnsn_array *dmnsn_new_array(size_t obj_size); +void dmnsn_delete_array(dmnsn_array *array); void dmnsn_array_push(dmnsn_array *array, const void *obj); void dmnsn_array_pop(dmnsn_array *array, void *obj); -void *dmnsn_array_at(dmnsn_array *array, size_t i); -void dmnsn_array_get(const dmnsn_array *array, size_t i, void *obj); -void dmnsn_array_set(dmnsn_array *array, size_t i, const void *obj); +void dmnsn_array_get(const dmnsn_array *array, size_t i, void *obj); +void dmnsn_array_set(dmnsn_array *array, size_t i, const void *obj); void dmnsn_array_resize(dmnsn_array *array, size_t length); -void dmnsn_delete_array(dmnsn_array *array); +/* Thread-unsafe! Don't give multiple threads the same raw pointer... */ +void *dmnsn_array_at(dmnsn_array *array, size_t i); + +/* Manual locking */ +void dmnsn_array_rdlock(const dmnsn_array *array); +void dmnsn_array_wrlock(dmnsn_array *array); +void dmnsn_array_unlock(const dmnsn_array *array); #endif /* DIMENSION_ARRAY_H */ |