Skip to content

Commit 505d6dd

Browse files
committed
Make synchronize private by default
can be made public if required in descendant
1 parent 2a182b4 commit 505d6dd

File tree

8 files changed

+21
-15
lines changed

8 files changed

+21
-15
lines changed

ext/com/concurrent_ruby/ext/SynchronizationLibrary.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.jruby.runtime.builtin.IRubyObject;
1414
import org.jruby.runtime.load.Library;
1515
import org.jruby.runtime.Block;
16+
import org.jruby.runtime.Visibility;
1617
import org.jruby.RubyBoolean;
1718
import org.jruby.RubyNil;
1819
import org.jruby.runtime.ThreadContext;
@@ -54,14 +55,14 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
5455
}
5556
}
5657

57-
@JRubyMethod(name = "synchronize")
58+
@JRubyMethod(name = "synchronize", visibility = Visibility.PRIVATE)
5859
public IRubyObject rubySynchronize(ThreadContext context, Block block) {
5960
synchronized (this) {
6061
return block.yield(context, null);
6162
}
6263
}
6364

64-
@JRubyMethod(name = "ns_wait", optional = 1, visibility = 'private')
65+
@JRubyMethod(name = "ns_wait", optional = 1, visibility = Visibility.PRIVATE)
6566
public IRubyObject nsWait(ThreadContext context, IRubyObject[] args) {
6667
Ruby runtime = context.runtime;
6768
if (args.length > 1) {
@@ -93,13 +94,13 @@ public IRubyObject nsWait(ThreadContext context, IRubyObject[] args) {
9394
return this;
9495
}
9596

96-
@JRubyMethod(name = "ns_signal", visibility = 'private')
97+
@JRubyMethod(name = "ns_signal", visibility = Visibility.PRIVATE)
9798
public IRubyObject nsSignal(ThreadContext context) {
9899
notify();
99100
return this;
100101
}
101102

102-
@JRubyMethod(name = "ns_broadcast", visibility = 'private')
103+
@JRubyMethod(name = "ns_broadcast", visibility = Visibility.PRIVATE)
103104
public IRubyObject nsBroadcast(ThreadContext context) {
104105
notifyAll();
105106
return this;

lib/concurrent/delay.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def initialize(opts = {}, &block)
7979
@computing = false
8080
end
8181

82+
protected :synchronize
83+
8284
# Return the value this object represents after applying the options
8385
# specified by the `#set_deref_options` method. If the delayed operation
8486
# raised an exception this method will return nil. The execption object

lib/concurrent/ivar.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def initialize(value = NO_VALUE, opts = {})
6666
set(value) unless value == NO_VALUE
6767
end
6868

69+
protected :synchronize
70+
6971
# Add an observer on this object that will receive notification on update.
7072
#
7173
# Upon completion the `IVar` will notify all observers in a thread-safe way.

lib/concurrent/synchronization/abstract_object.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ def initialize(*args, &block)
3434
raise NotImplementedError
3535
end
3636

37+
private
38+
3739
# @yield runs the block synchronized against this object,
38-
# equvivalent of java's `synchronize(this) {}`
40+
# equivalent of java's `synchronize(this) {}`
41+
# @note can by made public in descendants if required by `public :synchronize`
3942
def synchronize
4043
raise NotImplementedError
4144
end
4245

43-
private
44-
4546
# initialization of the object called inside synchronize block
4647
def ns_initialize(*args, &block)
4748
end

lib/concurrent/synchronization/java_pure_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def initialize(*args, &block)
99
synchronize { ns_initialize(*args, &block) }
1010
end
1111

12+
private
13+
1214
def synchronize
1315
JRuby.reference0(self).synchronized { yield }
1416
end
1517

16-
private
17-
1818
def ns_wait(timeout = nil)
1919
success = JRuby.reference0(Thread.current).wait_timeout(JRuby.reference0(self), timeout)
2020
self

lib/concurrent/synchronization/monitor_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def initialize(*args, &block)
77
synchronize { ns_initialize(*args, &block) }
88
end
99

10+
private
11+
1012
def synchronize
1113
@__lock__do_not_use_directly.synchronize { yield }
1214
end
1315

14-
private
15-
1616
def ns_wait(timeout = nil)
1717
@__condition__do_not_use_directly.wait timeout
1818
self

lib/concurrent/synchronization/mutex_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def initialize(*args, &block)
77
synchronize { ns_initialize(*args, &block) }
88
end
99

10+
private
11+
1012
def synchronize
1113
if @__lock__do_not_use_directly.owned?
1214
yield
@@ -15,8 +17,6 @@ def synchronize
1517
end
1618
end
1719

18-
private
19-
2020
def ns_signal
2121
@__condition__do_not_use_directly.signal
2222
self

lib/concurrent/synchronization/rbx_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def initialize(*args, &block)
99
end
1010
end
1111

12+
private
13+
1214
def synchronize(&block)
1315
Rubinius.synchronize(self, &block)
1416
end
1517

16-
private
17-
1818
def ns_wait(timeout = nil)
1919
wchan = Rubinius::Channel.new
2020

0 commit comments

Comments
 (0)