Skip to content

Commit

Permalink
wutnewlib: Use OSCompareAndSwapAtomicEx for sbrk
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts authored and fincs committed Aug 5, 2022
1 parent e81c3a1 commit 42292fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libraries/wutnewlib/wut_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions libraries/wutnewlib/wut_sbrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 42292fa

Please sign in to comment.