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();
* The second parameter specifies whether the set is initially empty or contains
* all cores.
*
* \pre \c core_set is not NULL.
*
* \notthreadsafe
*/
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.
*
* \pre \c core_set is not NULL and \c core_number is smaller than
* embb_core_count_available().
*
* \notthreadsafe
* \see embb_core_set_remove()
*/
......@@ -107,13 +112,16 @@ void embb_core_set_add(
);
/**
* Removes a core from the specified set.
*
* If the core is not in the set, the operation has no effect.
*
* \notthreadsafe
* \see embb_core_set_add()
*/
* Removes a core from the specified set.
*
* If the core is not 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
* \see embb_core_set_add()
*/
void embb_core_set_remove(
embb_core_set_t* core_set,
/**< [IN/OUT] Core set to be manipulated */
......@@ -124,8 +132,11 @@ void embb_core_set_remove(
/**
* 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
* than zero.
* \pre \c core_set is not NULL and \c core_number is smaller than
* embb_core_count_available().
*
* \return 0 if the core is not contained in the set, otherwise a number
* greater than zero.
* \notthreadsafe
*/
int embb_core_set_contains(
......@@ -140,6 +151,8 @@ int embb_core_set_contains(
*
* The result is stored in \c set1.
*
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe
* \see embb_core_set_union()
*/
......@@ -155,6 +168,8 @@ void embb_core_set_intersection(
*
* The result is stored in \c set1.
*
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe
* \see embb_core_set_intersection()
*/
......@@ -168,6 +183,8 @@ void embb_core_set_union(
/**
* Returns the number of cores contained in the specified set.
*
* \pre \c core_set is not NULL.
*
* \notthreadsafe
* \return Number of cores in \c core_set
*/
......
......@@ -67,6 +67,8 @@ int embb_counter_init(
/**
* Returns the current value of \c counter.
*
* \pre \c counter is not NULL.
*
* \return Current value
*
* \waitfree
......@@ -79,6 +81,8 @@ unsigned int embb_counter_get(
/**
* Increments \c counter and returns the old value.
*
* \pre \c counter is not NULL.
*
* \return Old, non-incremented value
* \waitfree
*/
......@@ -90,6 +94,8 @@ unsigned int embb_counter_increment(
/**
* Decrements \c counter and returns the old value.
*
* \pre \c counter is not NULL.
*
* \return Old, non-decremented value
* \waitfree
*/
......@@ -101,8 +107,8 @@ unsigned int embb_counter_decrement(
/**
* Destroys an initialized counter.
*
* \pre Counter is initialized
* \post Counter is invalid and cannot be used anymore
* \pre \c counter is initialized and not NULL.
* \post \c counter is invalid and cannot be used anymore
* \waitfree
*/
void embb_counter_destroy(
......
......@@ -73,6 +73,8 @@ extern "C" {
*
* Keeps track of freed memory in debug mode.
*
* \pre \c ptr is not NULL.
*
* \threadsafe
*
* \see embb_get_bytes_allocated()
......@@ -161,6 +163,8 @@ extern "C" {
*
* Keeps track of freed memory in debug mode.
*
* \pre \c ptr is not NULL and was allocated by an aligned method.
*
* \threadsafe
*
* \see embb_alloc_aligned(), embb_alloc_cache_aligned(),
......
......@@ -150,7 +150,7 @@ int embb_mutex_unlock(
/**
* 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
* \notthreadsafe
* \see embb_mutex_init()
......@@ -233,7 +233,7 @@ int embb_spin_unlock(
/**
* 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
* \notthreadsafe
* \see embb_spin_init()
......
......@@ -112,7 +112,7 @@ void* embb_tss_get(
*
* 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
* \notthreadsafe
* \see embb_tss_create()
......
......@@ -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,
const embb_core_set_t* set2) {
assert(set1 != NULL);
assert(set2 != NULL);
embb_bitset_intersect(&set1->rep, set2->rep);
}
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);
}
unsigned int embb_core_set_count(const embb_core_set_t* core_set) {
assert(core_set != NULL);
return embb_bitset_count(&core_set->rep);
}
......@@ -38,23 +38,17 @@ int embb_counter_init(embb_counter_t* counter) {
}
unsigned int embb_counter_get(embb_counter_t* counter) {
if (counter == NULL) {
return EMBB_ERROR;
}
assert(counter != NULL);
return embb_atomic_load_unsigned_int(&(counter->value));
}
unsigned int embb_counter_increment(embb_counter_t* counter) {
if (counter == NULL) {
return EMBB_ERROR;
}
assert(counter != NULL);
return embb_atomic_fetch_and_add_unsigned_int(&(counter->value), 1);
}
unsigned int embb_counter_decrement(embb_counter_t* counter) {
if (counter == NULL) {
return EMBB_ERROR;
}
assert(counter != NULL);
return embb_atomic_fetch_and_add_unsigned_int(&(counter->value),
(unsigned int)-1);
}
......
......@@ -62,9 +62,7 @@ void* embb_alloc(size_t bytes) {
}
void embb_free(void * ptr) {
if (ptr == NULL) {
return;
}
assert(ptr != NULL);
size_t * alloc_type = (size_t*)ptr - 1;
size_t * bytes_allocated = (size_t*)ptr - 2;
......@@ -136,9 +134,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) {
}
void embb_free_aligned(void* ptr) {
if (ptr == NULL) {
return;
}
assert(ptr != NULL);
size_t* ptr_conv = (size_t*)ptr;
......@@ -165,10 +161,7 @@ void * embb_alloc(size_t bytes) {
}
void embb_free(void * ptr) {
if (ptr == NULL) {
return;
}
assert(ptr != NULL);
free(ptr);
}
......@@ -201,9 +194,7 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
}
void embb_free_aligned(void* ptr) {
if (ptr == NULL) {
return;
}
assert(ptr != NULL);
#ifdef EMBB_PLATFORM_COMPILER_MSVC
_aligned_free(ptr);
......
......@@ -69,9 +69,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
}
void embb_mutex_destroy(embb_mutex_t* mutex) {
if (NULL == mutex) {
return;
}
assert(NULL != mutex);
DeleteCriticalSection(mutex);
}
......@@ -139,9 +137,7 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
}
void embb_mutex_destroy(embb_mutex_t* mutex) {
if (NULL == mutex) {
return;
}
assert(NULL != mutex);
pthread_mutex_destroy(mutex);
}
......@@ -210,6 +206,7 @@ int embb_spin_unlock(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
// destroy function for atomics...
EMBB_UNUSED(spinlock);
......
......@@ -75,8 +75,6 @@ void* embb_tss_get(const embb_tss_t* tss) {
}
void embb_tss_delete(embb_tss_t* tss) {
if (tss == NULL) {
return;
}
assert(tss != NULL);
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