Commit d9e48ba2 by Marcus Winter

Merge branch 'embb353_assertions_vs_exceptions' into development

parents 418d0143 5e2f3132
......@@ -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()
......
......@@ -33,8 +33,9 @@
int embb_condition_wait_for(embb_condition_t* condition_var,
embb_mutex_t* mutex,
const embb_duration_t* duration) {
assert(condition_var != NULL);
assert(mutex != NULL);
if (condition_var == NULL || mutex == NULL) {
return EMBB_ERROR;
}
embb_time_t time;
int status = embb_time_in(&time, duration);
if (status != EMBB_SUCCESS) {
......@@ -46,27 +47,34 @@ int embb_condition_wait_for(embb_condition_t* condition_var,
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
InitializeConditionVariable(condition_var);
return EMBB_SUCCESS;
}
int embb_condition_notify_one(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
WakeConditionVariable(condition_var);
return EMBB_SUCCESS;
}
int embb_condition_notify_all(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
WakeAllConditionVariable(condition_var);
return EMBB_SUCCESS;
}
int embb_condition_wait(embb_condition_t* condition_var,
embb_mutex_t* mutex) {
assert(condition_var != NULL);
assert(mutex != NULL);
if (condition_var == NULL || mutex == NULL) {
return EMBB_ERROR;
}
if (SleepConditionVariableCS(condition_var, mutex, INFINITE)) {
return EMBB_SUCCESS;
}
......@@ -75,9 +83,9 @@ int embb_condition_wait(embb_condition_t* condition_var,
int embb_condition_wait_until(embb_condition_t* condition_var,
embb_mutex_t* mutex, const embb_time_t* time) {
assert(condition_var != NULL);
assert(mutex != NULL);
assert(time != NULL);
if (condition_var == NULL || mutex == NULL || time == NULL) {
return EMBB_ERROR;
}
/* The Windows API needs a time duration, so we need to convert the given time
by using the time now. */
embb_time_t now;
......@@ -103,7 +111,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var,
}
int embb_condition_destroy(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
EMBB_UNUSED_IN_RELEASE(condition_var);
return EMBB_SUCCESS;
}
......@@ -113,35 +123,42 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_init(condition_var, NULL);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
}
int embb_condition_notify_one(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_signal(condition_var);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
}
int embb_condition_notify_all(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_broadcast(condition_var);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
}
int embb_condition_wait(embb_condition_t* condition_var, embb_mutex_t* mutex) {
assert(condition_var != NULL);
assert(mutex != NULL);
if (condition_var == NULL || mutex == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_wait(condition_var, mutex);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
}
int embb_condition_wait_until(embb_condition_t* condition_var,
embb_mutex_t* mutex, const embb_time_t* time) {
assert(condition_var != NULL);
assert(mutex != NULL);
assert(time != NULL);
if (condition_var == NULL || mutex == NULL || time == NULL) {
return EMBB_ERROR;
}
/* Convert EMBB time to Unix time format */
struct timespec unix_time;
unix_time.tv_sec = time->seconds;
......@@ -157,7 +174,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var,
}
int embb_condition_destroy(embb_condition_t* condition_var) {
assert(condition_var != NULL);
if (condition_var == NULL) {
return EMBB_ERROR;
}
int status = pthread_cond_destroy(condition_var);
if (status != 0) {
return EMBB_ERROR;
......
......@@ -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);
}
......@@ -30,7 +30,9 @@
#include <assert.h>
int embb_counter_init(embb_counter_t* counter) {
assert(counter != NULL);
if (counter == NULL) {
return EMBB_ERROR;
}
embb_atomic_store_unsigned_int(&(counter->value), 0);
return EMBB_SUCCESS;
}
......
......@@ -46,7 +46,9 @@ const embb_duration_t* embb_duration_zero() {
int embb_duration_set_nanoseconds(embb_duration_t* duration,
unsigned long long nanoseconds) {
assert(duration != NULL);
if (duration == NULL) {
return EMBB_ERROR;
}
if (nanoseconds > 0) {
if (embb_duration_min()->nanoseconds > nanoseconds) {
return EMBB_UNDERFLOW;
......@@ -63,7 +65,9 @@ int embb_duration_set_nanoseconds(embb_duration_t* duration,
int embb_duration_set_microseconds(embb_duration_t* duration,
unsigned long long microseconds) {
assert(duration != NULL);
if (duration == NULL) {
return EMBB_ERROR;
}
if (microseconds > 0) {
if (embb_duration_min()->nanoseconds > microseconds*1000) {
return EMBB_UNDERFLOW;
......@@ -80,7 +84,9 @@ int embb_duration_set_microseconds(embb_duration_t* duration,
int embb_duration_set_milliseconds(embb_duration_t* duration,
unsigned long long milliseconds) {
assert(duration != NULL);
if (duration == NULL) {
return EMBB_ERROR;
}
if (milliseconds > 0) {
if (embb_duration_min()->nanoseconds > milliseconds*1000000) {
return EMBB_UNDERFLOW;
......@@ -97,7 +103,9 @@ int embb_duration_set_milliseconds(embb_duration_t* duration,
int embb_duration_set_seconds(embb_duration_t* duration,
unsigned long long seconds) {
assert(duration != NULL);
if (duration == NULL) {
return EMBB_ERROR;
}
if (seconds > 0) {
if (embb_duration_min()->nanoseconds > seconds*1000000000) {
return EMBB_UNDERFLOW;
......@@ -113,8 +121,9 @@ int embb_duration_set_seconds(embb_duration_t* duration,
}
int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) {
assert(lhs != NULL);
assert(rhs != NULL);
if (lhs == NULL || rhs == NULL) {
return EMBB_ERROR;
}
int carry = (int)((lhs->nanoseconds + rhs->nanoseconds) / 1000000000);
if (lhs->seconds + rhs->seconds + carry > EMBB_DURATION_MAX_SECONDS) {
return EMBB_OVERFLOW;
......@@ -126,8 +135,9 @@ int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) {
int embb_duration_as_nanoseconds(const embb_duration_t* duration,
unsigned long long* nanoseconds) {
assert(duration != NULL);
assert(nanoseconds != NULL);
if (duration == NULL || nanoseconds == NULL) {
return EMBB_ERROR;
}
if (duration->seconds*1000000000 + duration->nanoseconds > ULLONG_MAX) {
return EMBB_OVERFLOW;
}
......@@ -137,8 +147,9 @@ int embb_duration_as_nanoseconds(const embb_duration_t* duration,
int embb_duration_as_microseconds(const embb_duration_t* duration,
unsigned long long* microseconds) {
assert(duration != NULL);
assert(microseconds != NULL);
if (duration == NULL || microseconds == NULL) {
return EMBB_ERROR;
}
if (duration->nanoseconds % 1000 > 0) {
return EMBB_UNDERFLOW;
}
......@@ -151,8 +162,9 @@ int embb_duration_as_microseconds(const embb_duration_t* duration,
int embb_duration_as_milliseconds(const embb_duration_t* duration,
unsigned long long* milliseconds) {
assert(duration != NULL);
assert(milliseconds != NULL);
if (duration == NULL || milliseconds == NULL) {
return EMBB_ERROR;
}
if (duration->nanoseconds % 1000000 > 0) {
return EMBB_UNDERFLOW;
}
......@@ -165,8 +177,9 @@ int embb_duration_as_milliseconds(const embb_duration_t* duration,
int embb_duration_as_seconds(const embb_duration_t* duration,
unsigned long long* seconds) {
assert(duration != NULL);
assert(seconds != NULL);
if (duration == NULL || seconds == NULL) {
return EMBB_ERROR;
}
if (duration->nanoseconds % 1000000000 > 0) {
return EMBB_UNDERFLOW;
}
......@@ -180,11 +193,12 @@ int embb_duration_as_seconds(const embb_duration_t* duration,
int embb_duration_compare(const embb_duration_t* lhs,
const embb_duration_t* rhs) {
assert(lhs != NULL);
assert(rhs != NULL);
assert(lhs->nanoseconds < 1000000000);
assert(rhs->nanoseconds < 1000000000);
if (lhs == NULL || rhs == NULL) {
return EMBB_ERROR;
}
if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) {
return EMBB_ERROR;
}
if (lhs->seconds > rhs->seconds) {
return 1;
} else if (lhs->seconds < rhs->seconds) {
......
......@@ -135,6 +135,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) {
void embb_free_aligned(void* ptr) {
assert(ptr != NULL);
size_t* ptr_conv = (size_t*)ptr;
// If embb_free_aligned is called, the memory block should have been allocated
......@@ -193,6 +194,8 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
}
void embb_free_aligned(void* ptr) {
assert(ptr != NULL);
#ifdef EMBB_PLATFORM_COMPILER_MSVC
_aligned_free(ptr);
#else
......
......@@ -33,6 +33,9 @@
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) {
if (NULL == mutex) {
return EMBB_ERROR;
}
/* Critical sections in Windows are always recursive */
InitializeCriticalSection(mutex);
EMBB_UNUSED(type);
......@@ -40,11 +43,17 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) {
}
int embb_mutex_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
EnterCriticalSection(mutex);
return EMBB_SUCCESS;
}
int embb_mutex_try_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
BOOL success;
success = TryEnterCriticalSection(mutex);
if (success == FALSE) return EMBB_ERROR;
......@@ -52,11 +61,15 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) {
}
int embb_mutex_unlock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
LeaveCriticalSection(mutex);
return EMBB_SUCCESS;
}
void embb_mutex_destroy(embb_mutex_t* mutex) {
assert(NULL != mutex);
DeleteCriticalSection(mutex);
}
......@@ -65,6 +78,9 @@ void embb_mutex_destroy(embb_mutex_t* mutex) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) {
if (NULL == mutex) {
return EMBB_ERROR;
}
if (type == EMBB_MUTEX_PLAIN) {
if (pthread_mutex_init(mutex, NULL) != 0) return EMBB_ERROR;
} else {
......@@ -85,6 +101,9 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) {
}
int embb_mutex_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_lock(mutex);
if (result != 0) {
return EMBB_ERROR;
......@@ -93,6 +112,9 @@ int embb_mutex_lock(embb_mutex_t* mutex) {
}
int embb_mutex_try_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_trylock(mutex);
if (result == 0) {
return EMBB_SUCCESS;
......@@ -104,6 +126,9 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) {
}
int embb_mutex_unlock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_unlock(mutex);
if (result != 0) {
return EMBB_ERROR;
......@@ -112,12 +137,16 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
}
void embb_mutex_destroy(embb_mutex_t* mutex) {
assert(NULL != mutex);
pthread_mutex_destroy(mutex);
}
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
int embb_spin_init(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
// For now, store the initial value. In the future will use atomic init
// function (as soon as available).
embb_atomic_store_int(&spinlock->atomic_spin_variable_, 0);
......@@ -125,6 +154,9 @@ int embb_spin_init(embb_spinlock_t* spinlock) {
}
int embb_spin_lock(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
int expected = 0;
int spins = 1;
......@@ -143,6 +175,9 @@ int embb_spin_lock(embb_spinlock_t* spinlock) {
int embb_spin_try_lock(embb_spinlock_t* spinlock,
unsigned int max_number_spins) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
if (max_number_spins == 0)
return EMBB_BUSY;
......@@ -161,6 +196,9 @@ int embb_spin_try_lock(embb_spinlock_t* spinlock,
}
int embb_spin_unlock(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
int expected = 1;
return embb_atomic_compare_and_swap_int(&spinlock->atomic_spin_variable_,
&expected, 0) ?
......@@ -168,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);
......
......@@ -80,7 +80,9 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void *arg) {
assert(thread != NULL);
if (thread == NULL) {
return EMBB_ERROR;
}
thread->embb_internal_arg = (embb_internal_thread_arg_t*)
embb_alloc(sizeof(embb_internal_thread_arg_t));
if (thread->embb_internal_arg == NULL) return EMBB_NOMEM;
......@@ -118,6 +120,9 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
}
int embb_thread_join(embb_thread_t* thread, int* result_code) {
if (thread == NULL) {
return EMBB_ERROR;
}
BOOL success;
DWORD result;
result = WaitForSingleObject(thread->embb_internal_handle, INFINITE);
......@@ -143,6 +148,9 @@ int embb_thread_join(embb_thread_t* thread, int* result_code) {
}
int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
if (lhs == NULL || rhs == NULL) {
return 0;
}
embb_thread_id_t idLhs = GetThreadId(lhs->embb_internal_handle);
embb_thread_id_t idRhs = GetThreadId(rhs->embb_internal_handle);
if (idLhs == idRhs) {
......@@ -203,6 +211,9 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void* arg) {
if (thread == NULL) {
return EMBB_ERROR;
}
pthread_attr_t attr; /* Used to set thread affinities */
int status = pthread_attr_init(&attr);
if (status != 0) return EMBB_ERROR;
......@@ -250,6 +261,9 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
}
int embb_thread_join(embb_thread_t* thread, int *result_code) {
if (thread == NULL) {
return EMBB_ERROR;
}
int status = 0;
status = pthread_join(thread->embb_internal_handle, NULL);
if (result_code != NULL) {
......@@ -263,6 +277,9 @@ int embb_thread_join(embb_thread_t* thread, int *result_code) {
}
int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
if (lhs == NULL || rhs == NULL) {
return 0;
}
return pthread_equal(lhs->embb_internal_handle, rhs->embb_internal_handle);
}
......
......@@ -32,7 +32,9 @@
#include <assert.h>
int embb_tss_create(embb_tss_t* tss) {
assert(tss != NULL);
if (tss == NULL) {
return EMBB_ERROR;
}
tss->size = embb_thread_get_max_count();
tss->values = (void**) embb_alloc_cache_aligned(tss->size * sizeof(void*));
if (tss->values == NULL) {
......@@ -45,7 +47,9 @@ int embb_tss_create(embb_tss_t* tss) {
}
int embb_tss_set(embb_tss_t* tss, void* value) {
assert(tss != NULL);
if (tss == NULL) {
return EMBB_ERROR;
}
unsigned int index = 0;
int status = embb_internal_thread_index(&index);
if ((status != EMBB_SUCCESS) || (index >= tss->size)) {
......@@ -56,8 +60,12 @@ int embb_tss_set(embb_tss_t* tss, void* value) {
}
void* embb_tss_get(const embb_tss_t* tss) {
assert(tss != NULL);
assert(tss->values != NULL);
if (tss == NULL) {
return NULL;
}
if (tss->values == NULL) {
return NULL;
}
unsigned int index = 0;
int status = embb_internal_thread_index(&index);
if ((status != EMBB_SUCCESS) || (index >= tss->size)) {
......
......@@ -33,10 +33,12 @@ void embb_time_now(embb_time_t* time) {
}
int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
assert(lhs != NULL);
assert(rhs != NULL);
assert(lhs->nanoseconds < 1000000000);
assert(rhs->nanoseconds < 1000000000);
if (lhs == NULL || rhs == NULL) {
return EMBB_ERROR;
}
if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) {
return EMBB_ERROR;
}
if (lhs->seconds > rhs->seconds) {
return 1;
......@@ -56,8 +58,9 @@ int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL);
assert(duration != NULL);
if (time == NULL || duration == NULL) {
return EMBB_ERROR;
}
/* Get system time */
SYSTEMTIME system_time;
GetLocalTime(&system_time);
......@@ -87,8 +90,9 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL);
assert(duration != NULL);
if (time == NULL || duration == NULL) {
return EMBB_ERROR;
}
struct timespec unix_time;
clock_gettime(CLOCK_REALTIME, &unix_time);
time->seconds = unix_time.tv_sec;
......
......@@ -32,7 +32,10 @@ namespace base {
namespace internal {
MutexBase::MutexBase(int mutex_type) : mutex_() {
embb_mutex_init(&mutex_, mutex_type);
int result = embb_mutex_init(&mutex_, mutex_type);
if (EMBB_SUCCESS != result) {
EMBB_THROW(ErrorException, "Could not initialize mutex.");
}
}
MutexBase::~MutexBase() {
......@@ -40,7 +43,10 @@ MutexBase::~MutexBase() {
}
void MutexBase::Lock() {
embb_mutex_lock(&mutex_);
int result = embb_mutex_lock(&mutex_);
if (EMBB_SUCCESS != result) {
EMBB_THROW(ErrorException, "Could not lock mutex.");
}
}
bool MutexBase::TryLock() {
......@@ -49,7 +55,10 @@ bool MutexBase::TryLock() {
}
void MutexBase::Unlock() {
embb_mutex_unlock(&mutex_);
int result = embb_mutex_unlock(&mutex_);
if (EMBB_SUCCESS != result) {
EMBB_THROW(ErrorException, "Could not unlock mutex.");
}
}
} // namespace internal
......
......@@ -57,9 +57,7 @@ class In {
Type GetValue(int clock) const {
SignalType const & signal = GetSignal(clock);
if (signal.IsBlank())
EMBB_THROW(embb::base::ErrorException,
"Signal is blank, cannot get a value.")
assert(!signal.IsBlank());
return signal.GetValue();
}
......@@ -86,9 +84,7 @@ class In {
void Receive(SignalType const & value) {
const int idx = value.GetClock() % Slices;
if (values_[idx].GetClock() >= value.GetClock())
EMBB_THROW(embb::base::ErrorException,
"Received signal does not increase clock.");
assert(values_[idx].GetClock() < value.GetClock());
values_[idx] = value;
listener_->OnClock(value.GetClock());
#if EMBB_DATAFLOW_TRACE_SIGNAL_HISTORY
......
......@@ -90,10 +90,7 @@ class Inputs<Slices, T1, embb::base::internal::Nil, embb::base::internal::Nil,
}
virtual void OnClock(int clock) {
const int idx = clock % Slices;
if (count_[idx] == 0) {
EMBB_THROW(embb::base::ErrorException,
"All inputs already fired for this clock.");
}
assert(count_[idx] > 0);
if (--count_[idx] == 0) {
count_[idx] = 1;
listener_->OnClock(clock);
......@@ -143,10 +140,7 @@ class Inputs<Slices, T1, T2, embb::base::internal::Nil,
}
virtual void OnClock(int clock) {
const int idx = clock % Slices;
if (count_[idx] == 0) {
EMBB_THROW(embb::base::ErrorException,
"All inputs already fired for this clock.");
}
assert(count_[idx] > 0);
if (--count_[idx] == 0) {
count_[idx] = 2;
listener_->OnClock(clock);
......@@ -200,10 +194,7 @@ class Inputs<Slices, T1, T2, T3, embb::base::internal::Nil,
}
virtual void OnClock(int clock) {
const int idx = clock % Slices;
if (count_[idx] == 0) {
EMBB_THROW(embb::base::ErrorException,
"All inputs already fired for this clock.");
}
assert(count_[idx] > 0);
if (--count_[idx] == 0) {
count_[idx] = 3;
listener_->OnClock(clock);
......@@ -260,10 +251,7 @@ class Inputs<Slices, T1, T2, T3, T4, embb::base::internal::Nil>
}
virtual void OnClock(int clock) {
const int idx = clock % Slices;
if (count_[idx] == 0) {
EMBB_THROW(embb::base::ErrorException,
"All inputs already fired for this clock.");
}
assert(count_[idx] > 0);
if (--count_[idx] == 0) {
count_[idx] = 4;
listener_->OnClock(clock);
......@@ -325,10 +313,7 @@ class Inputs
}
virtual void OnClock(int clock) {
const int idx = clock % Slices;
if (count_[idx] == 0) {
EMBB_THROW(embb::base::ErrorException,
"All inputs already fired for this clock.");
}
assert(count_[idx] > 0);
if (--count_[idx] == 0) {
count_[idx] = 5;
listener_->OnClock(clock);
......
......@@ -108,10 +108,7 @@ class Process< Slices, Serial, Inputs<Slices, I1, I2, I3, I4, I5>,
}
virtual void OnClock(int clock) {
if (!inputs_.AreAtClock(clock)) {
EMBB_THROW(embb::base::ErrorException,
"Some inputs are not at expected clock.")
}
assert(inputs_.AreAtClock(clock));
bool ordered = Serial;
if (ordered) {
......
......@@ -112,9 +112,7 @@ class Select
virtual void OnClock(int clock) {
//const int idx = clock % Slices;
if (!inputs_.AreAtClock(clock))
EMBB_THROW(embb::base::ErrorException,
"Some inputs are not at expected clock.")
assert(inputs_.AreAtClock(clock));
Run(clock);
}
......
......@@ -88,10 +88,8 @@ class Sink< Slices, Inputs<Slices, I1, I2, I3, I4, I5> >
}
virtual void OnClock(int clock) {
if (!inputs_.AreAtClock(clock)) {
EMBB_THROW(embb::base::ErrorException,
"Some inputs are not at expected clock.")
}
EMBB_UNUSED_IN_RELEASE(clock);
assert(inputs_.AreAtClock(clock));
bool retry = true;
while (retry) {
......
......@@ -110,9 +110,7 @@ class Switch
virtual void OnClock(int clock) {
//const int idx = clock % Slices;
if (!inputs_.AreAtClock(clock))
EMBB_THROW(embb::base::ErrorException,
"Some inputs are not at expected clock.")
assert(inputs_.AreAtClock(clock));
Run(clock);
}
......
......@@ -842,10 +842,8 @@ class Network : public internal::ClockListener {
*/
virtual void OnClock(int clock) {
const int idx = clock % Slices;
const int cnt = --sink_counter_[idx];
if (cnt < 0)
EMBB_THROW(embb::base::ErrorException,
"More sinks than expected signaled reception of given clock.")
assert(sink_counter_[idx] > 0);
--sink_counter_[idx];
}
/**
......
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