Browse Source

Fix data races with Cortex-M4 intrinsics

https://en.wikipedia.org/wiki/Intrinsic_function

https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
DricomDragon 5 years ago
parent
commit
a312998d59
1 changed files with 5 additions and 4 deletions
  1. 5 4
      prog/sources/setup-loop.cpp

+ 5 - 4
prog/sources/setup-loop.cpp

@@ -22,10 +22,11 @@ void setup (USER_MODE) {
 
 void loop (USER_MODE) {
 	if (gPerformCount) {
-		gCount1 += 1 ;
-		gCount2 += 1 ;
-		gCount3 += 1 ;
-		gCount4 += 1 ;
+		__atomic_fetch_add (& gCount1, 1, __ATOMIC_ACQ_REL);
+		__atomic_fetch_add (& gCount2, 1, __ATOMIC_ACQ_REL);
+		__atomic_fetch_add (& gCount3, 1, __ATOMIC_ACQ_REL);
+		__atomic_fetch_add (& gCount4, 1, __ATOMIC_ACQ_REL);
+
 		if (5000 <= millis (MODE)) {
 			gPerformCount = false ;
 			gotoLineColumn (MODE_ 0, 0) ;