ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Atomic.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cstdint>
11 
12 #ifdef MSC_VER
13 #include <intrin.h>
14 #pragma intrinsic(_InterlockedExchangeAdd)
15 #pragma intrinsic(_InterlockedExchangeAdd64)
16 #endif
17 
18 namespace cloudViewer {
19 namespace core {
20 
25 inline uint32_t AtomicFetchAddRelaxed(uint32_t* address, uint32_t val) {
26 #ifdef __GNUC__
27  return __atomic_fetch_add(address, val, __ATOMIC_RELAXED);
28 #elif _MSC_VER
29  static_assert(sizeof(long) == sizeof(uint32_t),
30  "Expected long to be a 32 bit type");
31  return static_cast<uint32_t>(_InterlockedExchangeAdd(
32  reinterpret_cast<long*>(address), static_cast<long>(val)));
33 #else
34  static_assert(false, "AtomicFetchAddRelaxed not implemented for platform");
35 #endif
36 }
37 
42 inline uint64_t AtomicFetchAddRelaxed(uint64_t* address, uint64_t val) {
43 #ifdef __GNUC__
44  return __atomic_fetch_add(address, val, __ATOMIC_RELAXED);
45 #elif _MSC_VER
46  return static_cast<uint64_t>(_InterlockedExchangeAdd64(
47  reinterpret_cast<int64_t*>(address), static_cast<int64_t>(val)));
48 #else
49  static_assert(false, "AtomicFetchAddRelaxed not implemented for platform");
50 #endif
51 }
52 
53 } // namespace core
54 } // namespace cloudViewer
uint32_t AtomicFetchAddRelaxed(uint32_t *address, uint32_t val)
Definition: Atomic.h:25
Generic file read and write utility for python interface.