Commit 5e2f3132 by Marcus Winter

base_c: functions without error code return only assert the validity of their…

base_c: functions without error code return only assert the validity of their arguments, documentation changed accordingly
parent 8ca94138
...@@ -81,6 +81,8 @@ unsigned int embb_core_count_available(); ...@@ -81,6 +81,8 @@ unsigned int embb_core_count_available();
* The second parameter specifies whether the set is initially empty or contains * The second parameter specifies whether the set is initially empty or contains
* all cores. * all cores.
* *
* \pre \c core_set is not NULL.
*
* \notthreadsafe * \notthreadsafe
*/ */
void embb_core_set_init( void embb_core_set_init(
...@@ -96,6 +98,9 @@ void embb_core_set_init( ...@@ -96,6 +98,9 @@ void embb_core_set_init(
* *
* If the core is already contained in the set, the operation has no effect. * If the core is already contained in the set, the operation has no effect.
* *
* \pre \c core_set is not NULL and \c core_number is smaller than
* embb_core_count_available().
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_remove() * \see embb_core_set_remove()
*/ */
...@@ -107,13 +112,16 @@ void embb_core_set_add( ...@@ -107,13 +112,16 @@ void embb_core_set_add(
); );
/** /**
* Removes a core from the specified set. * Removes a core from the specified set.
* *
* If the core is not in the set, the operation has no effect. * If the core is not in the set, the operation has no effect.
* *
* \notthreadsafe * \pre \c core_set is not NULL and \c core_number is smaller than
* \see embb_core_set_add() * embb_core_count_available().
*/ *
* \notthreadsafe
* \see embb_core_set_add()
*/
void embb_core_set_remove( void embb_core_set_remove(
embb_core_set_t* core_set, embb_core_set_t* core_set,
/**< [IN/OUT] Core set to be manipulated */ /**< [IN/OUT] Core set to be manipulated */
...@@ -124,8 +132,11 @@ void embb_core_set_remove( ...@@ -124,8 +132,11 @@ void embb_core_set_remove(
/** /**
* Determines whether a core is contained in the specified set. * Determines whether a core is contained in the specified set.
* *
* \return 0 if the core is not contained in the set, otherwise a number greater * \pre \c core_set is not NULL and \c core_number is smaller than
* than zero. * embb_core_count_available().
*
* \return 0 if the core is not contained in the set, otherwise a number
* greater than zero.
* \notthreadsafe * \notthreadsafe
*/ */
int embb_core_set_contains( int embb_core_set_contains(
...@@ -140,6 +151,8 @@ int embb_core_set_contains( ...@@ -140,6 +151,8 @@ int embb_core_set_contains(
* *
* The result is stored in \c set1. * The result is stored in \c set1.
* *
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_union() * \see embb_core_set_union()
*/ */
...@@ -155,6 +168,8 @@ void embb_core_set_intersection( ...@@ -155,6 +168,8 @@ void embb_core_set_intersection(
* *
* The result is stored in \c set1. * The result is stored in \c set1.
* *
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_intersection() * \see embb_core_set_intersection()
*/ */
...@@ -168,6 +183,8 @@ void embb_core_set_union( ...@@ -168,6 +183,8 @@ void embb_core_set_union(
/** /**
* Returns the number of cores contained in the specified set. * Returns the number of cores contained in the specified set.
* *
* \pre \c core_set is not NULL.
*
* \notthreadsafe * \notthreadsafe
* \return Number of cores in \c core_set * \return Number of cores in \c core_set
*/ */
......
...@@ -67,6 +67,8 @@ int embb_counter_init( ...@@ -67,6 +67,8 @@ int embb_counter_init(
/** /**
* Returns the current value of \c counter. * Returns the current value of \c counter.
* *
* \pre \c counter is not NULL.
*
* \return Current value * \return Current value
* *
* \waitfree * \waitfree
...@@ -79,6 +81,8 @@ unsigned int embb_counter_get( ...@@ -79,6 +81,8 @@ unsigned int embb_counter_get(
/** /**
* Increments \c counter and returns the old value. * Increments \c counter and returns the old value.
* *
* \pre \c counter is not NULL.
*
* \return Old, non-incremented value * \return Old, non-incremented value
* \waitfree * \waitfree
*/ */
...@@ -90,6 +94,8 @@ unsigned int embb_counter_increment( ...@@ -90,6 +94,8 @@ unsigned int embb_counter_increment(
/** /**
* Decrements \c counter and returns the old value. * Decrements \c counter and returns the old value.
* *
* \pre \c counter is not NULL.
*
* \return Old, non-decremented value * \return Old, non-decremented value
* \waitfree * \waitfree
*/ */
...@@ -101,8 +107,8 @@ unsigned int embb_counter_decrement( ...@@ -101,8 +107,8 @@ unsigned int embb_counter_decrement(
/** /**
* Destroys an initialized counter. * Destroys an initialized counter.
* *
* \pre Counter is initialized * \pre \c counter is initialized and not NULL.
* \post Counter is invalid and cannot be used anymore * \post \c counter is invalid and cannot be used anymore
* \waitfree * \waitfree
*/ */
void embb_counter_destroy( void embb_counter_destroy(
......
...@@ -73,6 +73,8 @@ extern "C" { ...@@ -73,6 +73,8 @@ extern "C" {
* *
* Keeps track of freed memory in debug mode. * Keeps track of freed memory in debug mode.
* *
* \pre \c ptr is not NULL.
*
* \threadsafe * \threadsafe
* *
* \see embb_get_bytes_allocated() * \see embb_get_bytes_allocated()
...@@ -161,6 +163,8 @@ extern "C" { ...@@ -161,6 +163,8 @@ extern "C" {
* *
* Keeps track of freed memory in debug mode. * Keeps track of freed memory in debug mode.
* *
* \pre \c ptr is not NULL and was allocated by an aligned method.
*
* \threadsafe * \threadsafe
* *
* \see embb_alloc_aligned(), embb_alloc_cache_aligned(), * \see embb_alloc_aligned(), embb_alloc_cache_aligned(),
......
...@@ -150,7 +150,7 @@ int embb_mutex_unlock( ...@@ -150,7 +150,7 @@ int embb_mutex_unlock(
/** /**
* Destroys a mutex and frees its resources. * Destroys a mutex and frees its resources.
* *
* \pre \c mutex has been initialized * \pre \c mutex has been initialized and is not NULL.
* \post \c mutex is uninitialized * \post \c mutex is uninitialized
* \notthreadsafe * \notthreadsafe
* \see embb_mutex_init() * \see embb_mutex_init()
...@@ -233,7 +233,7 @@ int embb_spin_unlock( ...@@ -233,7 +233,7 @@ int embb_spin_unlock(
/** /**
* Destroys a spinlock and frees its resources. * Destroys a spinlock and frees its resources.
* *
* \pre \c spinlock has been initialized * \pre \c spinlock has been initialized and is not NULL.
* \post \c spinlock is uninitialized * \post \c spinlock is uninitialized
* \notthreadsafe * \notthreadsafe
* \see embb_spin_init() * \see embb_spin_init()
......
...@@ -112,7 +112,7 @@ void* embb_tss_get( ...@@ -112,7 +112,7 @@ void* embb_tss_get(
* *
* Does not delete the values pointed to. * Does not delete the values pointed to.
* *
* \pre TSS has been created successfully * \pre \c tss has been created successfully and is not NULL.
* \post All slots are deleted * \post All slots are deleted
* \notthreadsafe * \notthreadsafe
* \see embb_tss_create() * \see embb_tss_create()
......
...@@ -146,13 +146,18 @@ int embb_core_set_contains(const embb_core_set_t* core_set, ...@@ -146,13 +146,18 @@ int embb_core_set_contains(const embb_core_set_t* core_set,
void embb_core_set_intersection(embb_core_set_t* set1, void embb_core_set_intersection(embb_core_set_t* set1,
const embb_core_set_t* set2) { const embb_core_set_t* set2) {
assert(set1 != NULL);
assert(set2 != NULL);
embb_bitset_intersect(&set1->rep, set2->rep); embb_bitset_intersect(&set1->rep, set2->rep);
} }
void embb_core_set_union(embb_core_set_t* set1, const embb_core_set_t* set2) { void embb_core_set_union(embb_core_set_t* set1, const embb_core_set_t* set2) {
assert(set1 != NULL);
assert(set2 != NULL);
embb_bitset_union(&set1->rep, set2->rep); embb_bitset_union(&set1->rep, set2->rep);
} }
unsigned int embb_core_set_count(const embb_core_set_t* core_set) { unsigned int embb_core_set_count(const embb_core_set_t* core_set) {
assert(core_set != NULL);
return embb_bitset_count(&core_set->rep); return embb_bitset_count(&core_set->rep);
} }
...@@ -38,23 +38,17 @@ int embb_counter_init(embb_counter_t* counter) { ...@@ -38,23 +38,17 @@ int embb_counter_init(embb_counter_t* counter) {
} }
unsigned int embb_counter_get(embb_counter_t* counter) { unsigned int embb_counter_get(embb_counter_t* counter) {
if (counter == NULL) { assert(counter != NULL);
return EMBB_ERROR;
}
return embb_atomic_load_unsigned_int(&(counter->value)); return embb_atomic_load_unsigned_int(&(counter->value));
} }
unsigned int embb_counter_increment(embb_counter_t* counter) { unsigned int embb_counter_increment(embb_counter_t* counter) {
if (counter == NULL) { assert(counter != NULL);
return EMBB_ERROR;
}
return embb_atomic_fetch_and_add_unsigned_int(&(counter->value), 1); return embb_atomic_fetch_and_add_unsigned_int(&(counter->value), 1);
} }
unsigned int embb_counter_decrement(embb_counter_t* counter) { unsigned int embb_counter_decrement(embb_counter_t* counter) {
if (counter == NULL) { assert(counter != NULL);
return EMBB_ERROR;
}
return embb_atomic_fetch_and_add_unsigned_int(&(counter->value), return embb_atomic_fetch_and_add_unsigned_int(&(counter->value),
(unsigned int)-1); (unsigned int)-1);
} }
......
...@@ -62,9 +62,7 @@ void* embb_alloc(size_t bytes) { ...@@ -62,9 +62,7 @@ void* embb_alloc(size_t bytes) {
} }
void embb_free(void * ptr) { void embb_free(void * ptr) {
if (ptr == NULL) { assert(ptr != NULL);
return;
}
size_t * alloc_type = (size_t*)ptr - 1; size_t * alloc_type = (size_t*)ptr - 1;
size_t * bytes_allocated = (size_t*)ptr - 2; size_t * bytes_allocated = (size_t*)ptr - 2;
...@@ -136,9 +134,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) { ...@@ -136,9 +134,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) {
} }
void embb_free_aligned(void* ptr) { void embb_free_aligned(void* ptr) {
if (ptr == NULL) { assert(ptr != NULL);
return;
}
size_t* ptr_conv = (size_t*)ptr; size_t* ptr_conv = (size_t*)ptr;
...@@ -165,10 +161,7 @@ void * embb_alloc(size_t bytes) { ...@@ -165,10 +161,7 @@ void * embb_alloc(size_t bytes) {
} }
void embb_free(void * ptr) { void embb_free(void * ptr) {
if (ptr == NULL) { assert(ptr != NULL);
return;
}
free(ptr); free(ptr);
} }
...@@ -201,9 +194,7 @@ void *embb_alloc_aligned(size_t alignment, size_t size) { ...@@ -201,9 +194,7 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
} }
void embb_free_aligned(void* ptr) { void embb_free_aligned(void* ptr) {
if (ptr == NULL) { assert(ptr != NULL);
return;
}
#ifdef EMBB_PLATFORM_COMPILER_MSVC #ifdef EMBB_PLATFORM_COMPILER_MSVC
_aligned_free(ptr); _aligned_free(ptr);
......
...@@ -69,9 +69,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) { ...@@ -69,9 +69,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
} }
void embb_mutex_destroy(embb_mutex_t* mutex) { void embb_mutex_destroy(embb_mutex_t* mutex) {
if (NULL == mutex) { assert(NULL != mutex);
return;
}
DeleteCriticalSection(mutex); DeleteCriticalSection(mutex);
} }
...@@ -139,9 +137,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) { ...@@ -139,9 +137,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
} }
void embb_mutex_destroy(embb_mutex_t* mutex) { void embb_mutex_destroy(embb_mutex_t* mutex) {
if (NULL == mutex) { assert(NULL != mutex);
return;
}
pthread_mutex_destroy(mutex); pthread_mutex_destroy(mutex);
} }
...@@ -210,6 +206,7 @@ int embb_spin_unlock(embb_spinlock_t* spinlock) { ...@@ -210,6 +206,7 @@ int embb_spin_unlock(embb_spinlock_t* spinlock) {
} }
void embb_spin_destroy(embb_spinlock_t* spinlock) { void embb_spin_destroy(embb_spinlock_t* spinlock) {
assert(NULL != spinlock);
// for now, doing nothing here... in future, will call the respective // for now, doing nothing here... in future, will call the respective
// destroy function for atomics... // destroy function for atomics...
EMBB_UNUSED(spinlock); EMBB_UNUSED(spinlock);
......
...@@ -75,8 +75,6 @@ void* embb_tss_get(const embb_tss_t* tss) { ...@@ -75,8 +75,6 @@ void* embb_tss_get(const embb_tss_t* tss) {
} }
void embb_tss_delete(embb_tss_t* tss) { void embb_tss_delete(embb_tss_t* tss) {
if (tss == NULL) { assert(tss != NULL);
return;
}
embb_free_aligned(tss->values); embb_free_aligned(tss->values);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment