Skip to content

Commit 4562dfe

Browse files
committed
Do not write to the default allocators state.
1 parent 3f7de91 commit 4562dfe

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/snmalloc/mem/remotecache.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ namespace snmalloc
206206
*/
207207
size_t cache_bytes{REMOTE_CACHE};
208208

209-
#ifndef NDEBUG
210209
bool initialised = false;
211-
#endif
212210

213211
/// Used to find the index into the array of queues for remote
214212
/// deallocation
@@ -238,8 +236,21 @@ namespace snmalloc
238236

239237
size_t size = n * sizeclass_full_to_size(entry.get_sizeclass());
240238

241-
cache_bytes += size;
242-
return cache_bytes < REMOTE_CACHE;
239+
size_t new_cache_bytes = cache_bytes + size;
240+
if (SNMALLOC_UNLIKELY(new_cache_bytes > REMOTE_CACHE))
241+
{
242+
// Check if this is the default allocator, and if not, we
243+
// can update the state.
244+
if (initialised)
245+
{
246+
cache_bytes = new_cache_bytes;
247+
}
248+
249+
return false;
250+
}
251+
252+
cache_bytes = new_cache_bytes;
253+
return true;
243254
}
244255

245256
template<size_t allocator_size>
@@ -376,9 +387,8 @@ namespace snmalloc
376387
*/
377388
void init()
378389
{
379-
#ifndef NDEBUG
380390
initialised = true;
381-
#endif
391+
382392
for (auto& l : list)
383393
{
384394
// We do not need to initialise with a particular slab, so pass

0 commit comments

Comments
 (0)