Commit 2fdf534c by Michael Schmid

edited time for more safety with overflow, and thread join method

parent bffe02d6
......@@ -132,7 +132,7 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "")
EMBB_PLATFORM_INLINE int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \
EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* expected, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired) { \
register /*__extension__ */ uint64_t e_reg = ((uint64_t)*expected << 32U) | desired; \
register uint64_t e_reg = ((uint64_t)*expected << 32U) | desired; \
__asm__ __volatile__ ("cmpswap" EMBB_ATOMIC_TC_SIZE_SUFFIX " [%1]0, %A0\n\t" \
: "+d"(e_reg) \
: "a"(pointer_to_value) \
......
......@@ -387,15 +387,8 @@ int embb_thread_join(embb_thread_t* thread, int *result_code) {
return EMBB_ERROR;
}
TickType_t xTicksToWait = 0xFFFFFFFF;
TimeOut_t xTimeOut;
vTaskSetTimeOutState( &xTimeOut );
while(thread->embb_internal_handle != NULL) {
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE ) {
break;
}
while(thread->embb_internal_handle != NULL && eTaskGetState(thread->embb_internal_handle) != eDeleted) {
taskYIELD();
}
if (thread->embb_internal_arg != NULL) {
......
......@@ -105,20 +105,22 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS
#include <FreeRTOS/FreeRTOSConfig.h>
#include <FreeRTOS/task.h>
#include <stdint.h>
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
if (time == NULL || duration == NULL) {
return EMBB_ERROR;
}
//scm34681: implement correctly for different ticks/second
//scm34681: check for overflow of tick count
uint32_t ticks_count = xTaskGetTickCount();
time->seconds = ticks_count / 1000;
time->nanoseconds = (ticks_count % 1000) * 1000000;
uint64_t ticks_count = xTaskGetTickCount();
time->seconds = ticks_count / configTICK_RATE_HZ;
time->nanoseconds = ((ticks_count % configTICK_RATE_HZ) * 1000000000ul)/configTICK_RATE_HZ;
if (time->seconds + duration->seconds > EMBB_TIME_MAX_SECONDS) {
ticks_count = (uint64_t)(duration->seconds *configTICK_RATE_HZ + (duration->nanoseconds * configTICK_RATE_HZ / 1000000000ul));
if (ticks_count > UINT32_MAX || time->seconds + duration->seconds > EMBB_TIME_MAX_SECONDS) {
return EMBB_OVERFLOW;
}
......
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