23 #ifndef _ODE_THREADINGUTILS_H_
24 #define _ODE_THREADINGUTILS_H_
30 #if !dTHREADING_INTF_DISABLED
33 bool ThrsafeCompareExchange(
volatile atomicord32 *paoDestination, atomicord32 aoComparand, atomicord32 aoExchange)
35 return AtomicCompareExchange(paoDestination, aoComparand, aoExchange);
39 atomicord32 ThrsafeExchange(
volatile atomicord32 *paoDestination, atomicord32 aoExchange)
41 return AtomicExchange(paoDestination, aoExchange);
45 bool ThrsafeCompareExchangePointer(
volatile atomicptr *papDestination, atomicptr apComparand, atomicptr apExchange)
47 return AtomicCompareExchangePointer(papDestination, apComparand, apExchange);
51 atomicptr ThrsafeExchangePointer(
volatile atomicptr *papDestination, atomicptr apExchange)
53 return AtomicExchangePointer(papDestination, apExchange);
57 #else // #if dTHREADING_INTF_DISABLED
60 bool ThrsafeCompareExchange(
volatile atomicord32 *paoDestination, atomicord32 aoComparand, atomicord32 aoExchange)
62 return (*paoDestination == aoComparand) ? ((*paoDestination = aoExchange),
true) :
false;
66 atomicord32 ThrsafeExchange(
volatile atomicord32 *paoDestination, atomicord32 aoExchange)
68 atomicord32 aoDestinationValue = *paoDestination;
69 *paoDestination = aoExchange;
70 return aoDestinationValue;
74 bool ThrsafeCompareExchangePointer(
volatile atomicptr *papDestination, atomicptr apComparand, atomicptr apExchange)
76 return (*papDestination == apComparand) ? ((*papDestination = apExchange),
true) :
false;
80 atomicptr ThrsafeExchangePointer(
volatile atomicptr *papDestination, atomicptr apExchange)
82 atomicptr apDestinationValue = *papDestination;
83 *papDestination = apExchange;
84 return apDestinationValue;
88 #endif // #if dTHREADING_INTF_DISABLED
92 unsigned int ThrsafeIncrementIntUpToLimit(
volatile unsigned int *storagePointer,
unsigned int limitValue)
94 unsigned int resultValue;
96 resultValue = *storagePointer;
97 if (resultValue == limitValue) {
100 if (ThrsafeCompareExchange((
volatile atomicord32 *)storagePointer, (atomicord32)resultValue, (atomicord32)(resultValue + 1))) {
108 size_t ThrsafeIncrementSizeUpToLimit(
volatile size_t *storagePointer,
size_t limitValue)
112 resultValue = *storagePointer;
113 if (resultValue == limitValue) {
116 if (ThrsafeCompareExchangePointer((
volatile atomicptr *)storagePointer, (atomicptr)resultValue, (atomicptr)(resultValue + 1))) {
125 #endif // _ODE_THREADINGUTILS_H_