From da46a8fab285649c0ea21c63c897680da867daef Mon Sep 17 00:00:00 2001 From: Marko Car Date: Wed, 24 May 2017 13:36:16 +0200 Subject: [PATCH 1/2] fixed usage of atomic operation lib for armcc compiler, added conditional compilation --- .../driver/include/uavcan_stm32/thread.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index fe74e50357..6557cfee13 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -142,17 +142,29 @@ public: { (void)duration; bool lready = ready; - return __atomic_exchange_n (&lready, false, __ATOMIC_SEQ_CST); + #if defined ( __CC_ARM ) + return __sync_lock_test_and_set(&lready, false); + #elif defined ( __GNUC__ ) + return __atomic_exchange_n (&lready, false, __ATOMIC_SEQ_CST); + #endif } void signal() { - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #if defined ( __CC_ARM ) + __sync_lock_release(&ready); + #elif defined ( __GNUC__ ) + __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #endif } void signalFromInterrupt() { - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #if defined ( __CC_ARM ) + __sync_lock_release(&ready); + #elif defined ( __GNUC__ ) + __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #endif } }; From fab231d5dbdccb8b74e31f4e2e9b6c1a8493a87f Mon Sep 17 00:00:00 2001 From: Marko Car Date: Wed, 24 May 2017 17:01:49 +0200 Subject: [PATCH 2/2] changed tabs into spaces, added error if compiler is not supported --- .../driver/include/uavcan_stm32/thread.hpp | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index 6557cfee13..b2eac2a65c 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -142,29 +142,35 @@ public: { (void)duration; bool lready = ready; - #if defined ( __CC_ARM ) - return __sync_lock_test_and_set(&lready, false); - #elif defined ( __GNUC__ ) - return __atomic_exchange_n (&lready, false, __ATOMIC_SEQ_CST); - #endif + #if defined ( __CC_ARM ) + return __sync_lock_test_and_set(&lready, false); + #elif defined ( __GNUC__ ) + return __atomic_exchange_n (&lready, false, __ATOMIC_SEQ_CST); + #else + # error "This compiler is not supported" + #endif } void signal() { - #if defined ( __CC_ARM ) - __sync_lock_release(&ready); - #elif defined ( __GNUC__ ) - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); - #endif + #if defined ( __CC_ARM ) + __sync_lock_release(&ready); + #elif defined ( __GNUC__ ) + __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #else + # error "This compiler is not supported" + #endif } void signalFromInterrupt() { - #if defined ( __CC_ARM ) - __sync_lock_release(&ready); - #elif defined ( __GNUC__ ) - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); - #endif + #if defined ( __CC_ARM ) + __sync_lock_release(&ready); + #elif defined ( __GNUC__ ) + __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); + #else + # error "This compiler is not supported" + #endif } };