Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channels: Use default allocator. #77

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions threading/channels.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand All @@ -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)
# ------------------------------------------------------------------------------
Expand Down
Loading