diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-01 23:48:56 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-01 23:48:56 +0200 |
commit | 43d0bb8e3997022e5270f7f75f615a47819c929e (patch) | |
tree | 937992d286966edecf81b405e414230c85d19bad /src/kernel/lib/earray.h | |
parent | e9683297bf480f9590b0e5796f4520fb430e2e03 (diff) | |
download | TCE-43d0bb8e3997022e5270f7f75f615a47819c929e.tar.gz TCE-43d0bb8e3997022e5270f7f75f615a47819c929e.zip |
Basic object system - THIS IS STILL A LONG WAY TO GO!!
Diffstat (limited to 'src/kernel/lib/earray.h')
-rw-r--r-- | src/kernel/lib/earray.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/kernel/lib/earray.h b/src/kernel/lib/earray.h new file mode 100644 index 0000000..69849c9 --- /dev/null +++ b/src/kernel/lib/earray.h @@ -0,0 +1,40 @@ +#ifndef DEF_EARRAY_H +#define DEF_EARRAY_H + +#include <sched.h> + +/* + * This class implements a simple extensible array structure. + * An entry with a 0 value is considered free and can be allocated. + * The array will free as much space when elements are removed. + * The array will ALWAYS have array->data = 0 when uninitialized, !=0 when initialized and in use + * To initialize an earray: + * - allocate the struct earray + * - set its ref_vect_init_len and vect_len to desired values + * - set its data to 0 + * - all the rest doesn't matter + * - call earray_init + * Freeing an array does not free the struct earray, only the data it references. + */ + +struct earray { + int ref_vect_init_len; + int vect_len; // NEVER CHANGE THIS AFTER INITIALISATION!!!! + + int ref_vect_len; + int elements; + void ***data; + + mutex_t mutex; +}; + +void earray_init(struct earray *array); +void earray_free(struct earray *earray); // frees everything + +int earray_add(struct earray *array, void* ptr); // return element number or -1 if fail +void *earray_at(struct earray *array, int num); // returns 0 when nothing +void earray_set(struct earray *earray, int num, void* ptr); + + +#endif + |