<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/146205>146205</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [rpmalloc] Fake atomic operations in case of MSVC
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          slydiman
      </td>
    </tr>
</table>

<pre>
    In case of MSVC dummy functions are used for atomic operations. 
This can cause side effects and difficult to debug issues.
```
/// Atomic access abstraction (since MSVC does not do C11 yet)

#if defined(_MSC_VER) && !defined(__clang__)

typedef volatile long atomic32_t;

static FORCEINLINE int32_t atomic_load32(atomic32_t *src) { return *src; }

static FORCEINLINE void atomic_store32(atomic32_t *dst, int32_t val) {
  *dst = val;
}
```
Is there any reason do not use intrinsics somethink like the following?
```
#include <intrin.h>

static FORCEINLINE int32_t atomic_load32(atomic32_t *src) { 
  return _InterlockedOr(src, 0); 
}

static FORCEINLINE void atomic_store32(atomic32_t *dst, int32_t val) {
  _InterlockedExchange(dst, val);
}
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VE2v2zYQ_DXUZRGDJiVbOujg52cDBpoESIpcDYpcSawp0uBSbv3vC3285BVpbi1AQIB2dnY4K40isp1HrFnxworXTI2pD7Em9zR2UD5rgnnWFw9aEUJo4ePXb0cw4zA8oR29TjZ4AhURRkIDbYigUhishnDHqObyBhg__N5bAq0mopEQyBoEbFvUiUB5A8a2rdWjS5ACGGzGDizRiLRh_MB2fD38wMR5OXBYBimtkQhUQymqWRAwUZL1Gle1AQl8SGACHLdbeGJiopqoJjZpWzDYWo-GifL68evx-u30hYkKmNgxsQMmtu_qV-2U767X7wzpeUeDLTyCU8k6BBd8t5ogxTUx-bIAKalkNZw_fzmeLp9-u3w6gfVpgqzoqwvKSMFE-aMbmDhQ1LOc_QtETGP0by_lC7D96y_ZH8GaN2pKIeK_cBtKTBy_C3kot45i_AArAJh8nSvLTZaJ7zZyIUg9RgTlnxBRUfCT1ZPj06qtT9F6spqAwoCpt_4Gzt5w6oI2OBf-tL5j8vzTpqX12o0GgcnjQrPpmTz9d37Ot1xNvV58wuiCvqH5HKdPaMIdgU-rljP2_3X7vYDTX7pXvkMmyrVpAf9qB4wfMlNLU8lKZVhv98V2y_N9WWZ9XeRKaaWqHZeykc2-KkxZ5NhgtZM5L1Vma8FFwXei5FVR5eUmx51sizYX3FS54JrlHAdl3ca5x7AJscvmf7Pe5jvBi8ypBh29JUisJ9SHZuyI5dxZSvSjL9nk5qyJ90E5FzQrXuGsbvhzbID9Z-pkY3R1n9KdmFxToLOpH5uNDgMT52nG-vhwj-EP1ImJ8xIiTJxXrY9a_B0AAP__4WGKxg">