Skip to content

Commit 44d8ab4

Browse files
committed
Merge pull request #401 from ruby-concurrency/each-class-in-one-file
Every class/module in own file
2 parents ce6884c + 5946545 commit 44d8ab4

31 files changed

+1732
-1549
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Concurrent
2+
3+
# @!macro thread_local_var
4+
# @!macro internal_implementation_note
5+
# @!visibility private
6+
class AbstractThreadLocalVar
7+
8+
# @!visibility private
9+
NIL_SENTINEL = Object.new
10+
private_constant :NIL_SENTINEL
11+
12+
# @!macro thread_local_var_method_initialize
13+
def initialize(default = nil)
14+
@default = default
15+
allocate_storage
16+
end
17+
18+
# @!macro thread_local_var_method_get
19+
def value
20+
raise NotImplementedError
21+
end
22+
23+
# @!macro thread_local_var_method_set
24+
def value=(value)
25+
raise NotImplementedError
26+
end
27+
28+
# @!macro thread_local_var_method_bind
29+
def bind(value, &block)
30+
raise NotImplementedError
31+
end
32+
33+
protected
34+
35+
# @!visibility private
36+
def allocate_storage
37+
raise NotImplementedError
38+
end
39+
end
40+
end
Lines changed: 81 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,80 @@
1+
require 'concurrent/atomic/mutex_atomic_boolean'
12
require 'concurrent/utility/native_extension_loader'
2-
require 'concurrent/synchronization'
33

44
module Concurrent
55

6-
# @!macro [attach] atomic_boolean
6+
###################################################################
7+
8+
# @!macro [new] atomic_boolean_method_initialize
79
#
8-
# A boolean value that can be updated atomically. Reads and writes to an atomic
9-
# boolean and thread-safe and guaranteed to succeed. Reads and writes may block
10-
# briefly but no explicit locking is required.
10+
# Creates a new `AtomicBoolean` with the given initial value.
1111
#
12-
# Testing with ruby 2.1.2
13-
# Testing with Concurrent::MutexAtomicBoolean...
14-
# 2.790000 0.000000 2.790000 ( 2.791454)
15-
# Testing with Concurrent::CAtomicBoolean...
16-
# 0.740000 0.000000 0.740000 ( 0.740206)
12+
# @param [Boolean] initial the initial value
13+
14+
# @!macro [new] atomic_boolean_method_value_get
1715
#
18-
# Testing with jruby 1.9.3
19-
# Testing with Concurrent::MutexAtomicBoolean...
20-
# 5.240000 2.520000 7.760000 ( 3.683000)
21-
# Testing with Concurrent::JavaAtomicBoolean...
22-
# 3.340000 0.010000 3.350000 ( 0.855000)
16+
# Retrieves the current `Boolean` value.
2317
#
24-
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html java.util.concurrent.atomic.AtomicBoolean
18+
# @return [Boolean] the current value
19+
20+
# @!macro [new] atomic_boolean_method_value_set
2521
#
26-
# @!visibility private
22+
# Explicitly sets the value.
2723
#
28-
# @!macro internal_implementation_note
29-
class MutexAtomicBoolean < Synchronization::Object
30-
31-
# @!macro [attach] atomic_boolean_method_initialize
32-
#
33-
# Creates a new `AtomicBoolean` with the given initial value.
34-
#
35-
# @param [Boolean] initial the initial value
36-
def initialize(initial = false)
37-
super()
38-
synchronize { ns_initialize(initial) }
39-
end
40-
41-
# @!macro [attach] atomic_boolean_method_value_get
42-
#
43-
# Retrieves the current `Boolean` value.
44-
#
45-
# @return [Boolean] the current value
46-
def value
47-
synchronize { @value }
48-
end
49-
50-
# @!macro [attach] atomic_boolean_method_value_set
51-
#
52-
# Explicitly sets the value.
53-
#
54-
# @param [Boolean] value the new value to be set
55-
#
56-
# @return [Boolean] the current value
57-
def value=(value)
58-
synchronize { @value = !!value }
59-
end
60-
61-
# @!macro [attach] atomic_boolean_method_true_question
62-
#
63-
# Is the current value `true`
64-
#
65-
# @return [Boolean] true if the current value is `true`, else false
66-
def true?
67-
synchronize { @value }
68-
end
24+
# @param [Boolean] value the new value to be set
25+
#
26+
# @return [Boolean] the current value
6927

70-
# @!macro [attach] atomic_boolean_method_false_question
71-
#
72-
# Is the current value `false`
73-
#
74-
# @return [Boolean] true if the current value is `false`, else false
75-
def false?
76-
synchronize { !@value }
77-
end
28+
# @!macro [new] atomic_boolean_method_true_question
29+
#
30+
# Is the current value `true`
31+
#
32+
# @return [Boolean] true if the current value is `true`, else false
7833

79-
# @!macro [attach] atomic_boolean_method_make_true
80-
#
81-
# Explicitly sets the value to true.
82-
#
83-
# @return [Boolean] true is value has changed, otherwise false
84-
def make_true
85-
synchronize { ns_make_value(true) }
86-
end
34+
# @!macro [new] atomic_boolean_method_false_question
35+
#
36+
# Is the current value `false`
37+
#
38+
# @return [Boolean] true if the current value is `false`, else false
8739

88-
# @!macro [attach] atomic_boolean_method_make_false
89-
#
90-
# Explicitly sets the value to false.
91-
#
92-
# @return [Boolean] true is value has changed, otherwise false
93-
def make_false
94-
synchronize { ns_make_value(false) }
95-
end
40+
# @!macro [new] atomic_boolean_method_make_true
41+
#
42+
# Explicitly sets the value to true.
43+
#
44+
# @return [Boolean] true is value has changed, otherwise false
9645

97-
protected
46+
# @!macro [new] atomic_boolean_method_make_false
47+
#
48+
# Explicitly sets the value to false.
49+
#
50+
# @return [Boolean] true is value has changed, otherwise false
51+
52+
###################################################################
9853

99-
# @!visibility private
100-
def ns_initialize(initial)
101-
@value = !!initial
102-
end
54+
# @!macro [new] atomic_boolean_public_api
55+
#
56+
# @!method initialize(initial = false)
57+
# @!macro atomic_boolean_method_initialize
58+
#
59+
# @!method value
60+
# @!macro atomic_boolean_method_value_get
61+
#
62+
# @!method value=(value)
63+
# @!macro atomic_boolean_method_value_set
64+
#
65+
# @!method true?
66+
# @!macro atomic_boolean_method_true_question
67+
#
68+
# @!method false?
69+
# @!macro atomic_boolean_method_false_question
70+
#
71+
# @!method make_true
72+
# @!macro atomic_boolean_method_make_true
73+
#
74+
# @!method make_false
75+
# @!macro atomic_boolean_method_make_false
10376

104-
# @!visibility private
105-
def ns_make_value(value)
106-
old = @value
107-
@value = value
108-
old != @value
109-
end
110-
end
77+
###################################################################
11178

11279
# @!visibility private
11380
# @!macro internal_implementation_note
@@ -121,31 +88,27 @@ def ns_make_value(value)
12188
end
12289
private_constant :AtomicBooleanImplementation
12390

124-
# @!macro atomic_boolean
91+
# @!macro [attach] atomic_boolean
92+
#
93+
# A boolean value that can be updated atomically. Reads and writes to an atomic
94+
# boolean and thread-safe and guaranteed to succeed. Reads and writes may block
95+
# briefly but no explicit locking is required.
96+
#
97+
# Testing with ruby 2.1.2
98+
# Testing with Concurrent::MutexAtomicBoolean...
99+
# 2.790000 0.000000 2.790000 ( 2.791454)
100+
# Testing with Concurrent::CAtomicBoolean...
101+
# 0.740000 0.000000 0.740000 ( 0.740206)
102+
#
103+
# Testing with jruby 1.9.3
104+
# Testing with Concurrent::MutexAtomicBoolean...
105+
# 5.240000 2.520000 7.760000 ( 3.683000)
106+
# Testing with Concurrent::JavaAtomicBoolean...
107+
# 3.340000 0.010000 3.350000 ( 0.855000)
108+
#
109+
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html java.util.concurrent.atomic.AtomicBoolean
125110
#
126-
# @see Concurrent::MutexAtomicBoolean
111+
# @!macro atomic_boolean_public_api
127112
class AtomicBoolean < AtomicBooleanImplementation
128-
129-
# @!method initialize(initial = false)
130-
# @!macro atomic_boolean_method_initialize
131-
132-
# @!method value
133-
# @!macro atomic_boolean_method_value_get
134-
135-
# @!method value=(value)
136-
# @!macro atomic_boolean_method_value_set
137-
138-
# @!method true?
139-
# @!macro atomic_boolean_method_true_question
140-
141-
# @!method false?
142-
# @!macro atomic_boolean_method_false_question
143-
144-
# @!method make_true
145-
# @!macro atomic_boolean_method_make_true
146-
147-
# @!method make_false
148-
# @!macro atomic_boolean_method_make_false
149-
150113
end
151114
end

0 commit comments

Comments
 (0)