-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
195f4d0
commit def99be
Showing
5 changed files
with
951 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Compability header for stdatomic.h that works for all compilers supported | ||
by V. For TCC the atomic features missing are implemented using mutex locks | ||
*/ | ||
#ifndef __cplusplus | ||
// If C just use stdatomic.h | ||
#ifndef __TINYC__ | ||
#include <stdatomic.h> | ||
#endif | ||
#else | ||
// CPP wrapper for atomic operations that are compatible with C | ||
#include "atomic_cpp.h" | ||
#endif | ||
|
||
#ifdef __TINYC__ | ||
#include <pthread.h> | ||
|
||
typedef intptr_t atomic_llong; | ||
typedef intptr_t atomic_ullong; | ||
|
||
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
/* | ||
Wrapper for TCC to use mutex locks since it lacks the atomic functions | ||
*/ | ||
static inline intptr_t atomic_fetch_add_explicit(intptr_t *x, size_t offset, int mo) | ||
{ | ||
pthread_mutex_lock(&lock); | ||
|
||
intptr_t old_value = *x; | ||
*x = *x + offset; | ||
|
||
pthread_mutex_unlock(&lock); | ||
|
||
return old_value; | ||
} | ||
|
||
/* | ||
Wrapper for TCC to use mutex locks since it lacks the atomic functions | ||
*/ | ||
static inline intptr_t atomic_fetch_sub_explicit(intptr_t *x, size_t offset, int mo) | ||
{ | ||
pthread_mutex_lock(&lock); | ||
|
||
intptr_t old_value = *x; | ||
*x = *x - offset; | ||
|
||
pthread_mutex_unlock(&lock); | ||
|
||
return old_value; | ||
} | ||
|
||
#endif |
Oops, something went wrong.