1616#include < stdint.h>
1717#include < stdio.h>
1818#include < stdlib.h>
19- #include < stdatomic.h >
19+ #include < atomic >
2020
2121#include " libunwind.h"
2222#include " dwarf2.h"
@@ -85,29 +85,29 @@ class StackBuffer
8585 static constexpr size_t entrySize = sizeof (FreeListEntry);
8686 static constexpr size_t buffer_size = LIBUNWIND_MAX_STACK_SIZE * entrySize;
8787 static char buffer[buffer_size];
88- static _Atomic size_t next_not_allocated_entry;
89- static void * _Atomic next_allocated_entry;
88+ static std::atomic< size_t > next_not_allocated_entry;
89+ static std::atomic<FreeListEntry *> next_allocated_entry;
9090
9191public:
9292 static FreeListEntry * alloc ()
9393 {
9494 // / At first, try to get element from free list.
9595 {
96- void * expected = nullptr ;
97- void * desired = nullptr ;
98- while (!atomic_compare_exchange_weak (& next_allocated_entry, & expected, desired))
96+ FreeListEntry * expected = nullptr ;
97+ FreeListEntry * desired = nullptr ;
98+ while (!next_allocated_entry. compare_exchange_weak ( expected, desired))
9999 {
100100 if (expected == nullptr )
101101 break ;
102102
103- desired = static_cast <FreeListEntry *>( expected) ->next ;
103+ desired = expected->next ;
104104 }
105105
106106 if (expected)
107- return static_cast <FreeListEntry *>( expected) ;
107+ return expected;
108108 }
109109
110- size_t prev = atomic_fetch_add (& next_not_allocated_entry, 1 );
110+ size_t prev = next_not_allocated_entry. fetch_add ( 1 );
111111 if (prev >= buffer_size)
112112 abort ();
113113
@@ -116,12 +116,12 @@ class StackBuffer
116116
117117 static void free (FreeListEntry * entry)
118118 {
119- void * expected = nullptr ;
120- entry->next = nullptr ;
119+ FreeListEntry * expected = nullptr ;
120+ entry->next = expected ;
121121
122- while (!atomic_compare_exchange_weak (& next_allocated_entry, & expected, entry))
122+ while (!next_allocated_entry. compare_exchange_weak ( expected, entry))
123123 {
124- entry->next = static_cast <FreeListEntry *>( expected) ;
124+ entry->next = expected;
125125 }
126126 }
127127};
0 commit comments