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