diff options
Diffstat (limited to 'libc/src/errno/libc_errno.cpp')
| -rw-r--r-- | libc/src/errno/libc_errno.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp index 64f9f522ca29..bd1438c22614 100644 --- a/libc/src/errno/libc_errno.cpp +++ b/libc/src/errno/libc_errno.cpp @@ -7,16 +7,21 @@ //===----------------------------------------------------------------------===// #include "libc_errno.h" +#include "src/__support/CPP/atomic.h" #ifdef LIBC_TARGET_ARCH_IS_GPU -// LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just +// LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just // a global errno for gpu to use for now. extern "C" { -LIBC_THREAD_LOCAL int __llvmlibc_gpu_errno; +LIBC_THREAD_LOCAL LIBC_NAMESPACE::cpp::Atomic<int> __llvmlibc_errno; } -void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_gpu_errno = a; } -LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_gpu_errno; } +void LIBC_NAMESPACE::Errno::operator=(int a) { + __llvmlibc_errno.store(a, cpp::MemoryOrder::RELAXED); +} +LIBC_NAMESPACE::Errno::operator int() { + return __llvmlibc_errno.load(cpp::MemoryOrder::RELAXED); +} #elif !defined(LIBC_COPT_PUBLIC_PACKAGING) // This mode is for unit testing. We just use our internal errno. |
