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

Alternative architecture for smartptrs #7

Open
planetis-m opened this issue Jul 23, 2021 · 2 comments
Open

Alternative architecture for smartptrs #7

planetis-m opened this issue Jul 23, 2021 · 2 comments

Comments

@planetis-m
Copy link
Contributor

planetis-m commented Jul 23, 2021

To accommodate the use-cases specified in #5 (comment), here is my proposed alternative:

https://github.com/planetis-m/dumpster/blob/master/expsmarts.nim#L18-L30

type
  SharedPtr*[T] = object
    ## Shared ownership reference counting pointer.
    deleter*: Deleter[T]
    val*: ptr Payload[T]

proc `=destroy`*[T](p: var SharedPtr[T]) =
  if p.val != nil:
    if p.val.counter.load(Consume) == 0:
      `=destroy`(p.val.value)
      if p.deleter != nil:
        p.deleter(p.val[])
    else:
      atomicDec(p.val.counter)

Can the deleter field be removed somehow?
Every field must be exported, so that libraries can provide their implementations like this:

https://github.com/planetis-m/dumpster/blob/master/pools.nim#L24

Opinions? @arnetheduck, @timotheecour, @Araq

@planetis-m planetis-m changed the title Alternative Alternative archetecture for smartptrs Jul 23, 2021
@planetis-m planetis-m changed the title Alternative archetecture for smartptrs Alternative architecture for smartptrs Jul 23, 2021
@timotheecour
Copy link
Member

I know @Araq suggested this repo, but why not use fusion for that? soon enough we'll end up with mutual dependencies (fusion needs threading or vice versa) or, more likely, we'll end up writing sub-optimal workarounds because of that

@Araq
Copy link
Member

Araq commented Jul 23, 2021

Here it can be developed and ripe before it becomes part of the stdlib. I don't see how mutual deps would arise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants