@@ -74,14 +74,15 @@ namespace tm_internal {
7474}
7575#elif  defined(ESP8266) || defined(ESP32)
7676#include  " Arduino.h" 
77- #include  " stdatomic.h" 
7877typedef  uint8_t  pintype_t ;
7978# define  IOA_USE_ARDUINO 
8079
8180namespace  tm_internal  {
82-     typedef  _Atomic (TimerTask*) TimerTaskAtomicPtr;
8381
8482#if  defined(ESP8266)
83+     #include  " stdatomic.h" 
84+     typedef  _Atomic (TimerTask*) TimerTaskAtomicPtr;
85+ 
8586    typedef  atomic_bool TmAtomicBool;
8687    /* *
8788     * Sets the boolean to the new value ONLY when the existing value matches expected. 
@@ -118,8 +119,30 @@ namespace tm_internal {
118119    inline  void  atomicWriteBool (TmAtomicBool *pPtr, bool  newVal) {
119120        atomic_store (pPtr, newVal);
120121    }
122+ 
123+     /* *
124+     * Dereferences and returns the value of the pointer at ptr type. On mbed boards this is already an atomic operation and 
125+     * therefore volatile is enough. 
126+     * @tparam PTR_TYPE class type of the pointer 
127+     * @param pPtr reference to memory of the pointer 
128+     * @return the pointer. 
129+     */  
130+     inline  TimerTask *atomicReadPtr (TimerTaskAtomicPtr *pPtr) {
131+         return  atomic_load (pPtr);
132+     }
133+ 
134+     /* *
135+      * Dereferences and then sets the memory of the pointer type. On mbed boards this is already an atomic operation 
136+      * @tparam PTR_TYPE 
137+      * @param pPtr 
138+      * @param newValue 
139+      */  
140+     inline  void  atomicWritePtr (TimerTaskAtomicPtr *pPtr, TimerTask *newValue) {
141+         atomic_store (pPtr, newValue);
142+     }
121143#else 
122-     typedef  uint32_t  TmAtomicBool; //  to use CAS, the bool must be 32 bits wide
144+     typedef  TimerTask* volatile  TimerTaskAtomicPtr;
145+     typedef  volatile  uint32_t  TmAtomicBool; //  to use CAS, the bool must be 32 bits wide
123146    inline  bool  atomicSwapBool (TmAtomicBool *ptr, bool  expected, bool  newValue) {
124147        uint32_t  exp32 = expected;
125148        uint32_t  new32 = newValue;
@@ -144,8 +167,6 @@ namespace tm_internal {
144167    inline  void  atomicWriteBool (TmAtomicBool *pPtr, bool  newVal) {
145168        *pPtr = newVal;
146169    }
147- #endif 
148- 
149170
150171    /* *
151172     * Dereferences and returns the value of the pointer at ptr type. On mbed boards this is already an atomic operation and 
@@ -155,7 +176,7 @@ namespace tm_internal {
155176     * @return the pointer. 
156177     */  
157178    inline  TimerTask *atomicReadPtr (TimerTaskAtomicPtr *pPtr) {
158-         return  atomic_load ( pPtr) ;
179+         return  * pPtr;
159180    }
160181
161182    /* *
@@ -165,8 +186,9 @@ namespace tm_internal {
165186     * @param newValue 
166187     */  
167188    inline  void  atomicWritePtr (TimerTaskAtomicPtr *pPtr, TimerTask *newValue) {
168-         atomic_store ( pPtr,  newValue) ;
189+         * pPtr =  newValue;
169190    }
191+ #endif 
170192}
171193
172194#else 
0 commit comments