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