Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- '1.9'
- '1.10'
- '1.11'
- '1.12'
- 'nightly'
fail-fast: false
name: Test with Julia ${{ matrix.julia-version }}
Expand Down
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ desc = "a simple distributed data store"
version = "0.4.14"

[deps]
ConcurrentCollections = "5060bff5-0b44-40c5-b522-fcd3ca5cecdd"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
DistributedNext = "fab6aee4-877b-4bac-a744-3eca44acbb6f"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Expand All @@ -16,7 +15,6 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[compat]
ConcurrentCollections = "0.1"
DistributedNext = "1"
Preferences = "1"
ScopedValues = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/MemPool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Serialization: serialize, deserialize
export DRef, FileRef, poolset, poolget, mmwrite, mmread, cleanup
import .Threads: ReentrantLock
using ScopedValues
using ConcurrentCollections

## Wrapping-unwrapping of payloads:

Expand Down Expand Up @@ -70,6 +69,7 @@ end
include("io.jl")
include("lock.jl")
include("read_write_lock.jl")
include("stack.jl")
include("clock.jl")
include("datastore.jl")

Expand Down
50 changes: 50 additions & 0 deletions src/stack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Adapted from ConcurrentCollections.jl/src/stack.jl

mutable struct TSNode{T}
value::T
@atomic next::Union{TSNode{T},Nothing}
end

TSNode{T}(value::T) where {T} = TSNode{T}(value, nothing)

mutable struct ConcurrentStack{T}
@atomic next::Union{TSNode{T},Nothing}
end

ConcurrentStack{T}() where {T} = ConcurrentStack{T}(nothing)

function Base.push!(stack::ConcurrentStack{T}, v) where {T}
v = convert(T, v)
node = TSNode{T}(v)

next = @atomic stack.next
while true
@atomic node.next = next
next, ok = @atomicreplace(stack.next, next => node)
ok && break
end

return stack
end

function maybepop!(stack::ConcurrentStack)
while true
node = @atomic stack.next
node === nothing && return nothing

next = @atomic node.next
next, ok = @atomicreplace(stack.next, node => next)
if ok
return Some(node.value)
end
end
end

function Base.pop!(stack::ConcurrentStack)
r = maybepop!(stack)
if r === nothing
error("stack is empty")
else
return something(r)
end
end
Loading