Skip to content

Commit 0225b55

Browse files
committed
Moved NULL to constants file.
1 parent df1deea commit 0225b55

14 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Upcoming Release v1.0.0 (TBD)
2+
3+
* Shared constants now in `lib/concurrent/constants.rb`
4+
15
## Current Release v1.0.0.pre2 (19 September 2015)
26

37
* Simplification of `RubySingleThreadExecutor`

lib/concurrent.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
require 'concurrent/version'
2+
require 'concurrent/constants'
3+
require 'concurrent/errors'
24
require 'concurrent/configuration'
35

46
require 'concurrent/atomics'
5-
require 'concurrent/errors'
67
require 'concurrent/executors'
78
require 'concurrent/synchronization'
89

@@ -126,9 +127,4 @@
126127
# * Be small, lean, and loosely coupled
127128
module Concurrent
128129

129-
# Various classes within allows for +nil+ values to be stored,
130-
# so a special +NULL+ token is required to indicate the "nil-ness".
131-
# @!visibility private
132-
NULL = Object.new
133-
134130
end

lib/concurrent/atomic/abstract_thread_local_var.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
require 'concurrent/constants'
2+
13
module Concurrent
24

35
# @!macro thread_local_var
46
# @!macro internal_implementation_note
57
# @!visibility private
68
class AbstractThreadLocalVar
79

8-
# @!visibility private
9-
NIL_SENTINEL = Object.new
10-
private_constant :NIL_SENTINEL
11-
1210
# @!macro thread_local_var_method_initialize
1311
def initialize(default = nil)
1412
@default = default

lib/concurrent/atomic/java_thread_local_var.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def value
1414

1515
if value.nil?
1616
@default
17-
elsif value == NIL_SENTINEL
17+
elsif value == NULL
1818
nil
1919
else
2020
value

lib/concurrent/atomic/ruby_thread_local_var.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def value
5151
value = array[@index]
5252
if value.nil?
5353
@default
54-
elsif value.equal?(NIL_SENTINEL)
54+
elsif value.equal?(NULL)
5555
nil
5656
else
5757
value
@@ -72,7 +72,7 @@ def value=(value)
7272
LOCK.synchronize { ARRAYS[array.object_id] = array }
7373
ObjectSpace.define_finalizer(me, self.class.thread_finalizer(array))
7474
end
75-
array[@index] = (value.nil? ? NIL_SENTINEL : value)
75+
array[@index] = (value.nil? ? NULL : value)
7676
value
7777
end
7878

@@ -159,7 +159,7 @@ def value_for(thread)
159159
value = array[@index]
160160
if value.nil?
161161
@default
162-
elsif value.equal?(NIL_SENTINEL)
162+
elsif value.equal?(NULL)
163163
nil
164164
else
165165
value

lib/concurrent/collection/map/atomic_reference_map_backend.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'concurrent/constants'
12
require 'concurrent/thread_safe/util'
23
require 'concurrent/thread_safe/util/adder'
34
require 'concurrent/thread_safe/util/cheap_lockable'

lib/concurrent/collection/map/non_concurrent_map_backend.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/constants'
2+
13
module Concurrent
24

35
# @!visibility private

lib/concurrent/constants.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Concurrent
2+
3+
# Various classes within allows for +nil+ values to be stored,
4+
# so a special +NULL+ token is required to indicate the "nil-ness".
5+
# @!visibility private
6+
NULL = Object.new
7+
8+
end

lib/concurrent/exchanger.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'concurrent/constants'
12
require 'concurrent/errors'
23
require 'concurrent/maybe'
34
require 'concurrent/atomic/atomic_reference'
@@ -139,10 +140,6 @@ class RubyExchanger < AbstractExchanger
139140
# not include the arena or the multi-processor spin loops.
140141
# http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/concurrent/Exchanger.java
141142

142-
# @!visibility private
143-
NIL_SENTINEL = Object.new
144-
private_constant :NIL_SENTINEL
145-
146143
# @!visibility private
147144
class Node < Concurrent::AtomicReference
148145
attr_reader :item, :latch
@@ -249,7 +246,7 @@ def do_exchange(value, timeout)
249246
# - Wake the sleeping occupier
250247
# - Return the occupier's item
251248

252-
value = NIL_SENTINEL if value.nil? # The sentinel allows nil to be a valid value
249+
value = NULL if value.nil? # The sentinel allows nil to be a valid value
253250
slot = @slot # Convenience to minimize typing @
254251
me = Node.new(value) # create my node in case I need to occupy
255252
end_at = Concurrent.monotonic_time + timeout.to_f # The time to give up
@@ -282,7 +279,7 @@ def do_exchange(value, timeout)
282279
break CANCEL if timeout && Concurrent.monotonic_time >= end_at
283280
end
284281

285-
result == NIL_SENTINEL ? nil : result
282+
result == NULL ? nil : result
286283
end
287284
end
288285

lib/concurrent/future.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'thread'
2+
require 'concurrent/constants'
23
require 'concurrent/errors'
34
require 'concurrent/ivar'
45
require 'concurrent/executor/safe_task_executor'

0 commit comments

Comments
 (0)