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

Move AtomicMarkableReference out of Edge #461

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -122,6 +122,7 @@ Thread-safe variables:
* [ReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ReadWriteLock.html) A lock that supports multiple readers but only one writer.
* [ReentrantReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ReentrantReadWriteLock.html) A read/write lock with reentrant and upgrade features.
* [Semaphore](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Semaphore.html) A counting-based locking mechanism that uses permits.
* [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Atomic/AtomicMarkableReference.html)

### Edge Features

Expand All @@ -143,7 +144,6 @@ be obeyed though. Features developed in `concurrent-ruby-edge` are expected to m
Functionally equivalent to Go [channels](https://tour.golang.org/concurrency/2) with additional
inspiration from Clojure [core.async](https://clojure.github.io/core.async/).
* [LazyRegister](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/LazyRegister.html)
* [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Edge/AtomicMarkableReference.html)
* [LockFreeLinkedSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Edge/LockFreeLinkedSet.html)
* [LockFreeStack](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Edge/LockFreeStack.html)

Expand Down
1 change: 0 additions & 1 deletion lib/concurrent-edge.rb
Expand Up @@ -8,5 +8,4 @@

require 'concurrent/edge/future'
require 'concurrent/edge/lock_free_stack'
require 'concurrent/edge/atomic_markable_reference'
require 'concurrent/edge/lock_free_linked_set'
1 change: 1 addition & 0 deletions lib/concurrent.rb
Expand Up @@ -7,6 +7,7 @@
require 'concurrent/executors'
require 'concurrent/synchronization'

require 'concurrent/atomic/atomic_markable_reference'
require 'concurrent/atomic/atomic_reference'
require 'concurrent/agent'
require 'concurrent/atom'
Expand Down
@@ -1,6 +1,5 @@
module Concurrent
module Edge

module Atomic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no Atomic module. We are non-idiomatic in the way we handle some subdirectories and namespaces. We are going to fix this in 2.0. For now please leave atomic_markable_reference.rb in the lib/concurrent/atomic directory but make the namespace Concurrent:: AtomicMarkableReference.

# @!macro [attach] atomic_markable_reference
#
# An atomic reference which maintains an object reference along with a mark bit
Expand All @@ -10,7 +9,6 @@ module Edge
#
# @api Edge
class AtomicMarkableReference < ::Concurrent::Synchronization::Object

private(*attr_volatile_with_cas(:reference))

# @!macro [attach] atomic_markable_reference_method_initialize
Expand Down Expand Up @@ -145,9 +143,9 @@ def try_update!

unless compare_and_set old_val, new_val, old_mark, new_mark
fail ::Concurrent::ConcurrentUpdateError,
'AtomicMarkableReference: Update failed due to race condition.',
'Note: If you would like to guarantee an update, please use ' \
'the `AtomicMarkableReference#update` method.'
'AtomicMarkableReference: Update failed due to race condition.',
'Note: If you would like to guarantee an update, please use ' \
'the `AtomicMarkableReference#update` method.'
end

ImmutableArray[new_val, new_mark]
Expand Down
5 changes: 3 additions & 2 deletions lib/concurrent/edge/lock_free_linked_set/node.rb
@@ -1,16 +1,17 @@
require 'concurrent/edge/atomic_markable_reference'
require 'concurrent/atomic/atomic_markable_reference'

module Concurrent
module Edge
class LockFreeLinkedSet
class Node < Synchronization::Object
include Comparable
include Concurrent::Atomic

safe_initialization!

def initialize(data = nil, successor = nil)
super()
@SuccessorReference = AtomicMarkableReference.new(successor || Tail.new)
@SuccessorReference = AtomicMarkableReference.new(successor || Tail.new)
@Data = data
@Key = key_for data
end
Expand Down
2 changes: 1 addition & 1 deletion spec/concurrent/atomic/atomic_markable_reference_spec.rb
@@ -1,4 +1,4 @@
describe Concurrent::Edge::AtomicMarkableReference do
describe Concurrent::Atomic::AtomicMarkableReference do
subject { described_class.new 1000, true }

describe '.initialize' do
Expand Down