Skip to content

Commit

Permalink
mem.c: add fallback implementations for stdatomic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Aug 12, 2024
1 parent d9aaf0f commit 3335423
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if !defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -13,6 +14,24 @@

#include "mem.h"

#if defined(__STDC_NO_ATOMICS__)
static size_t
atomic_fetch_sub(size_t *p, size_t diff)
{
size_t ov = *p;
*p -= diff;
return ov;
}

static bool
atomic_compare_exchange_weak(size_t *p, size_t *ov, size_t nv)
{
assert(*p == *ov);
*p = nv;
return true;
}
#endif

#if defined(TOYWASM_ENABLE_HEAP_TRACKING)
static void
mem_unreserve_one(struct mem_context *ctx, size_t diff)
Expand Down

0 comments on commit 3335423

Please sign in to comment.