File: emscripten_atomics.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (38 lines) | stat: -rw-r--r-- 957 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <assert.h>
#include <emscripten/threading.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define OLD 42

int main() {
  uint8_t buffer[16];
  memset(&buffer[0], OLD, sizeof(buffer));

  uint8_t o8 = emscripten_atomic_exchange_u8(&buffer[0], 0x12);
  assert(o8 == OLD);
  assert(buffer[0] == 0x12);
  assert(buffer[1] == OLD);

  uint16_t o16 = emscripten_atomic_exchange_u16(&buffer[0], 0x3456);
  assert((o16 & 0xff) == 0x12);
  assert((o16 >> 8) == OLD);
  assert(buffer[0] == 0x56);
  assert(buffer[1] == 0x34);
  assert(buffer[2] == OLD);

  uint32_t o32 = emscripten_atomic_exchange_u32(&buffer[0], 0xabcdef91);
  assert((o32 & 0xff) == 0x56);
  assert(((o32 >> 8) & 0xff) == 0x34);
  assert(((o32 >> 16) & 0xff) == OLD);
  assert(((o32 >> 24) & 0xff) == OLD);
  assert(buffer[0] == 0x91);
  assert(buffer[1] == 0xef);
  assert(buffer[2] == 0xcd);
  assert(buffer[3] == 0xab);
  assert(buffer[4] == OLD);

  printf("OK\n");
}