Skip to content

Commit 7350be4

Browse files
committed
Seeking TSAN's approval
1 parent e05cd7f commit 7350be4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/snmalloc/ds_core/stats.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ namespace snmalloc
7070
*/
7171
class MonotoneLocalStat
7272
{
73-
size_t value{0};
73+
std::atomic<size_t> value{0};
7474

7575
public:
7676
void operator++(int)
7777
{
78-
value++;
78+
value.fetch_add(1, std::memory_order_relaxed);
7979
}
8080

8181
void operator+=(const MonotoneLocalStat& other)
8282
{
83-
value += other.value;
83+
value.fetch_add(other.value.load(std::memory_order_relaxed), std::memory_order_relaxed);
8484
}
8585

8686
size_t operator*()
8787
{
88-
return value;
88+
return value.load(std::memory_order_relaxed);
8989
}
9090
};
9191
} // namespace snmalloc

src/snmalloc/mem/globalalloc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,14 @@ namespace snmalloc
139139
}
140140

141141
template<SNMALLOC_CONCEPT(IsConfig) Config>
142-
inline static AllocStats get_stats()
142+
inline static void get_stats(AllocStats& stats)
143143
{
144144
auto alloc = AllocPool<Config>::iterate();
145-
AllocStats stats;
146145
while (alloc != nullptr)
147146
{
148147
stats += alloc->get_stats();
149148
alloc = AllocPool<Config>::iterate(alloc);
150149
}
151-
return stats;
152150
}
153151

154152
template<SNMALLOC_CONCEPT(IsConfig) Config>
@@ -168,7 +166,8 @@ namespace snmalloc
168166
"count");
169167
}
170168

171-
auto stats = snmalloc::get_stats<Config>();
169+
AllocStats stats;
170+
snmalloc::get_stats<Config>(stats);
172171
size_t total_live{0};
173172
size_t total_live_slabs{0};
174173
for (size_t i = 0; i < snmalloc::SIZECLASS_REP_SIZE; i++)

0 commit comments

Comments
 (0)