From 22572a492e029db3f2bf266f9606a5dd42fb8844 Mon Sep 17 00:00:00 2001 From: Antonis Geralis Date: Tue, 27 Aug 2024 23:10:01 +0300 Subject: [PATCH] use default allocator. Why? Because I don't see a reason why this specific library should use a different allocator than the default. If there's a bug with nim's allocator -> use -d:usemalloc, whant a better/more stable multithreaded allocator -> use -d:usemimalloc and the mimalloc package. --- threading/channels.nim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/threading/channels.nim b/threading/channels.nim index a2e2f5a..f9d7529 100644 --- a/threading/channels.nim +++ b/threading/channels.nim @@ -101,7 +101,6 @@ when not (defined(gcArc) or defined(gcOrc) or defined(gcAtomicArc) or defined(ni {.error: "This module requires one of --mm:arc / --mm:atomicArc / --mm:orc compilation flags".} import std/[locks, isolation, atomics] -import system/ansi_c # Channel # ------------------------------------------------------------------------------ @@ -151,10 +150,10 @@ template isEmpty(chan: ChannelRaw): bool = # ------------------------------------------------------------------------------ proc allocChannel(size, n: int): ChannelRaw = - result = cast[ChannelRaw](c_malloc(csize_t sizeof(ChannelObj))) + result = cast[ChannelRaw](allocShared(sizeof(ChannelObj))) # To buffer n items, we allocate for n - result.buffer = cast[ptr UncheckedArray[byte]](c_malloc(csize_t n*size)) + result.buffer = cast[ptr UncheckedArray[byte]](allocShared(n*size)) initLock(result.lock) initCond(result.spaceAvailableCV) @@ -170,13 +169,13 @@ proc freeChannel(chan: ChannelRaw) = return if not chan.buffer.isNil: - c_free(chan.buffer) + deallocShared(chan.buffer) deinitLock(chan.lock) deinitCond(chan.spaceAvailableCV) deinitCond(chan.dataAvailableCV) - c_free(chan) + deallocShared(chan) # MPMC Channels (Multi-Producer Multi-Consumer) # ------------------------------------------------------------------------------