WIP restart of lib
This commit is contained in:
parent
e239bfa0ea
commit
9f6b90d596
36 changed files with 15951 additions and 2 deletions
35
parser/nsrc/atomic.h
Normal file
35
parser/nsrc/atomic.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef TREE_SITTER_ATOMIC_H_
|
||||
#define TREE_SITTER_ATOMIC_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline size_t atomic_load(const volatile size_t *p)
|
||||
{
|
||||
#ifdef __ATOMIC_RELAXED
|
||||
return __atomic_load_n(p, __ATOMIC_RELAXED);
|
||||
#else
|
||||
return __sync_fetch_and_add((volatile size_t *)p, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t atomic_inc(volatile uint32_t *p)
|
||||
{
|
||||
#ifdef __ATOMIC_RELAXED
|
||||
return __atomic_add_fetch(p, 1U, __ATOMIC_SEQ_CST);
|
||||
#else
|
||||
return __sync_add_and_fetch(p, 1U);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t atomic_dec(volatile uint32_t *p)
|
||||
{
|
||||
#ifdef __ATOMIC_RELAXED
|
||||
return __atomic_sub_fetch(p, 1U, __ATOMIC_SEQ_CST);
|
||||
#else
|
||||
return __sync_sub_and_fetch(p, 1U);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // TREE_SITTER_ATOMIC_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue