Go to the documentation of this file.
40 #ifndef INC_FREERTOS_H
41 #error "include FreeRTOS.h must appear in source files before include atomic.h"
59 #if defined( portSET_INTERRUPT_MASK_FROM_ISR )
62 #define ATOMIC_ENTER_CRITICAL() \
63 UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR()
65 #define ATOMIC_EXIT_CRITICAL() \
66 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType )
71 #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL()
72 #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL()
83 #ifndef portFORCE_INLINE
84 #define portFORCE_INLINE
87 #define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U
88 #define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U
109 uint32_t ulComparand )
111 uint32_t ulReturnValue;
113 ATOMIC_ENTER_CRITICAL();
115 if( *pulDestination == ulComparand )
117 *pulDestination = ulExchange;
125 ATOMIC_EXIT_CRITICAL();
127 return ulReturnValue;
148 ATOMIC_ENTER_CRITICAL();
150 pReturnValue = *ppvDestination;
151 *ppvDestination = pvExchange;
153 ATOMIC_EXIT_CRITICAL();
181 ATOMIC_ENTER_CRITICAL();
183 if( *ppvDestination == pvComparand )
185 *ppvDestination = pvExchange;
189 ATOMIC_EXIT_CRITICAL();
191 return ulReturnValue;
213 ATOMIC_ENTER_CRITICAL();
215 ulCurrent = *pulAddend;
216 *pulAddend += ulCount;
218 ATOMIC_EXIT_CRITICAL();
241 ATOMIC_ENTER_CRITICAL();
243 ulCurrent = *pulAddend;
244 *pulAddend -= ulCount;
246 ATOMIC_EXIT_CRITICAL();
266 ATOMIC_ENTER_CRITICAL();
268 ulCurrent = *pulAddend;
271 ATOMIC_EXIT_CRITICAL();
291 ATOMIC_ENTER_CRITICAL();
293 ulCurrent = *pulAddend;
296 ATOMIC_EXIT_CRITICAL();
314 static portFORCE_INLINE uint32_t
Atomic_OR_u32( uint32_t
volatile * pulDestination,
319 ATOMIC_ENTER_CRITICAL();
321 ulCurrent = *pulDestination;
322 *pulDestination |= ulValue;
324 ATOMIC_EXIT_CRITICAL();
341 static portFORCE_INLINE uint32_t
Atomic_AND_u32( uint32_t
volatile * pulDestination,
346 ATOMIC_ENTER_CRITICAL();
348 ulCurrent = *pulDestination;
349 *pulDestination &= ulValue;
351 ATOMIC_EXIT_CRITICAL();
373 ATOMIC_ENTER_CRITICAL();
375 ulCurrent = *pulDestination;
376 *pulDestination = ~( ulCurrent & ulValue );
378 ATOMIC_EXIT_CRITICAL();
395 static portFORCE_INLINE uint32_t
Atomic_XOR_u32( uint32_t
volatile * pulDestination,
400 ATOMIC_ENTER_CRITICAL();
402 ulCurrent = *pulDestination;
403 *pulDestination ^= ulValue;
405 ATOMIC_EXIT_CRITICAL();
static portFORCE_INLINE uint32_t Atomic_Add_u32(uint32_t volatile *pulAddend, uint32_t ulCount)
Atomically adds count to the value of the specified pointer points to.
Definition: atomic.h:208
#define ATOMIC_COMPARE_AND_SWAP_SUCCESS
Definition: atomic.h:87
static portFORCE_INLINE uint32_t Atomic_AND_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic AND operation on the specified values.
Definition: atomic.h:341
static portFORCE_INLINE void * Atomic_SwapPointers_p32(void *volatile *ppvDestination, void *pvExchange)
Atomically sets the address pointed to by *ppvDestination to the value of *pvExchange.
Definition: atomic.h:143
static portFORCE_INLINE uint32_t Atomic_XOR_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic XOR operation on the specified values.
Definition: atomic.h:395
static portFORCE_INLINE uint32_t Atomic_NAND_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic NAND operation on the specified values.
Definition: atomic.h:368
static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(void *volatile *ppvDestination, void *pvExchange, void *pvComparand)
Performs an atomic compare-and-swap operation on the specified pointer values.
Definition: atomic.h:175
static portFORCE_INLINE uint32_t Atomic_Decrement_u32(uint32_t volatile *pulAddend)
Atomically decrements the value of the specified pointer points to.
Definition: atomic.h:287
#define ATOMIC_COMPARE_AND_SWAP_FAILURE
Definition: atomic.h:88
static portFORCE_INLINE uint32_t Atomic_Subtract_u32(uint32_t volatile *pulAddend, uint32_t ulCount)
Atomically subtracts count from the value of the specified pointer pointers to.
Definition: atomic.h:236
static portFORCE_INLINE uint32_t Atomic_OR_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic OR operation on the specified values.
Definition: atomic.h:314
static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(uint32_t volatile *pulDestination, uint32_t ulExchange, uint32_t ulComparand)
Performs an atomic compare-and-swap operation on the specified values.
Definition: atomic.h:107
static portFORCE_INLINE uint32_t Atomic_Increment_u32(uint32_t volatile *pulAddend)
Atomically increments the value of the specified pointer points to.
Definition: atomic.h:262