diff --git a/libraries/wutnewlib/wut_lock.c b/libraries/wutnewlib/wut_lock.c index 915a59a4b..b16987a7a 100644 --- a/libraries/wutnewlib/wut_lock.c +++ b/libraries/wutnewlib/wut_lock.c @@ -6,7 +6,7 @@ #define MAX_LOCKS 16 static OSMutex sLibcLocks[MAX_LOCKS]; -static uint32_t sLibcLockUsedMask = 0; +static volatile uint32_t sLibcLockUsedMask = 0; static inline bool __wut_is_lock_valid(int *lock) diff --git a/libraries/wutnewlib/wut_sbrk.c b/libraries/wutnewlib/wut_sbrk.c index e9d11c8e4..2226f2584 100644 --- a/libraries/wutnewlib/wut_sbrk.c +++ b/libraries/wutnewlib/wut_sbrk.c @@ -14,17 +14,17 @@ void * __wut_sbrk_r(struct _reent *r, ptrdiff_t incr) { - uint32_t oldSize, newSize; + uint32_t newSize; + uint32_t oldSize = sHeapSize; do { - oldSize = sHeapSize; newSize = oldSize + incr; if (newSize > sHeapMaxSize) { r->_errno = ENOMEM; return (void *)-1; } - } while (!OSCompareAndSwapAtomic(&sHeapSize, oldSize, newSize)); + } while (!OSCompareAndSwapAtomicEx(&sHeapSize, oldSize, newSize, &oldSize)); return ((uint8_t *)sHeapBase) + oldSize; }