Skip to content

Commit 85d105c

Browse files
author
keiju
committed
* lib/sync.rb: bug fix if obj.initialize has parameters when obj.extend(Sync_m) * lib/mutex_m.rb: modified bit git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent b2658a3 commit 85d105c

File tree

3 files changed

+54
-53
lines changed

3 files changed

+54
-53
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Wed Jun 6 23:02:36 2001 Keiju Ishitsuka <keiju@ishitsuka.com>
2+
3+
* lib/sync.rb: bug fix if obj.initialize has parameters when
4+
obj.extend(Sync_m)
5+
6+
* lib/mutex_m.rb: modified bit
7+
18
Wed Jun 6 16:11:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
29

310
* eval.c (rb_load): should check if tainted even when wrap is

lib/mutex_m.rb

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@
2525
#
2626

2727
module Mutex_m
28+
def Mutex_m.define_aliases(cl)
29+
cl.module_eval %q{
30+
alias locked? mu_locked?
31+
alias lock mu_lock
32+
alias unlock mu_unlock
33+
alias try_lock mu_try_lock
34+
alias synchronize mu_synchronize
35+
}
36+
end
37+
2838
def Mutex_m.append_features(cl)
2939
super
30-
unless cl.instance_of?(Module)
31-
cl.module_eval %q{
32-
alias locked? mu_locked?
33-
alias lock mu_lock
34-
alias unlock mu_unlock
35-
alias try_lock mu_try_lock
36-
alias synchronize mu_synchronize
37-
}
38-
end
39-
self
40+
define_aliases(cl) unless cl.instance_of?(Module)
4041
end
4142

4243
def Mutex_m.extend_object(obj)
@@ -50,13 +51,7 @@ def mu_extended
5051
defined? unlock and
5152
defined? try_lock and
5253
defined? synchronize)
53-
eval "class << self
54-
alias locked? mu_locked?
55-
alias lock mu_lock
56-
alias unlock mu_unlock
57-
alias try_lock mu_try_lock
58-
alias synchronize mu_synchronize
59-
end"
54+
Mutex_m.define_aliases(class<<self;self;end)
6055
end
6156
mu_initialize
6257
end

lib/sync.rb

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#
22
# sync.rb - 2 phase lock with counter
3-
# $Release Version: 0.2$
3+
# $Release Version: 1.0$
44
# $Revision$
55
# $Date$
6-
# by Keiju ISHITSUKA
7-
# modified by matz
6+
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
87
#
98
# --
109
# Sync_m, Synchronizer_m
1110
# Usage:
1211
# obj.extend(Sync_m)
1312
# or
1413
# class Foo
15-
# Sync_m.include_to self
14+
# include Sync_m
1615
# :
1716
# end
1817
#
@@ -76,28 +75,32 @@ def LockModeFailer.Fail(mode)
7675
end
7776
end
7877

79-
def Sync_m.included(cl)
78+
def Sync_m.define_aliases(cl)
79+
cl.module_eval %q{
80+
alias locked? sync_locked?
81+
alias shared? sync_shared?
82+
alias exclusive? sync_exclusive?
83+
alias lock sync_lock
84+
alias unlock sync_unlock
85+
alias try_lock sync_try_lock
86+
alias synchronize sync_synchronize
87+
}
88+
end
89+
90+
def Sync_m.append_features(cl)
91+
super
8092
unless cl.instance_of?(Module)
8193
# do nothing for Modules
8294
# make aliases and include the proper module.
83-
cl.module_eval %q{
84-
alias locked? sync_locked?
85-
alias shared? sync_shared?
86-
alias exclusive? sync_exclusive?
87-
alias lock sync_lock
88-
alias unlock sync_unlock
89-
alias try_lock sync_try_lock
90-
alias synchronize sync_synchronize
91-
}
95+
define_aliases(cl)
9296
end
93-
return self
9497
end
9598

9699
def Sync_m.extend_object(obj)
97100
super
98101
obj.sync_extended
99102
end
100-
103+
101104
def sync_extended
102105
unless (defined? locked? and
103106
defined? shared? and
@@ -106,19 +109,11 @@ def sync_extended
106109
defined? unlock and
107110
defined? try_lock and
108111
defined? synchronize)
109-
eval "class << self
110-
alias locked? sync_locked?
111-
alias shared? sync_shared?
112-
alias exclusive? sync_exclusive?
113-
alias lock sync_lock
114-
alias unlock sync_unlock
115-
alias try_lock sync_try_lock
116-
alias synchronize sync_synchronize
117-
end"
112+
Sync_m.define_aliases(class<<self;self;end)
118113
end
119-
initialize
114+
sync_initialize
120115
end
121-
116+
122117
# accessing
123118
def sync_locked?
124119
sync_mode != UN
@@ -229,34 +224,38 @@ def sync_unlock(m = EX)
229224
end
230225

231226
def sync_synchronize(mode = EX)
232-
sync_lock(mode)
233227
begin
228+
sync_lock(mode)
234229
yield
235230
ensure
236231
sync_unlock
237232
end
238233
end
239-
234+
240235
attr :sync_mode, true
236+
241237
attr :sync_waiting, true
242238
attr :sync_upgrade_waiting, true
243239
attr :sync_sh_locker, true
244240
attr :sync_ex_locker, true
245241
attr :sync_ex_count, true
246-
242+
247243
private
248244

249-
def initialize(*args)
250-
ret = super
245+
def sync_initialize
251246
@sync_mode = UN
252247
@sync_waiting = []
253248
@sync_upgrade_waiting = []
254249
@sync_sh_locker = Hash.new
255250
@sync_ex_locker = nil
256251
@sync_ex_count = 0
257-
return ret
258252
end
259-
253+
254+
def initialize(*args)
255+
sync_initialize
256+
super
257+
end
258+
260259
def sync_try_lock_sub(m)
261260
case m
262261
when SH
@@ -301,12 +300,12 @@ def sync_try_lock_sub(m)
301300
Synchronizer_m = Sync_m
302301

303302
class Sync
303+
#Sync_m.extend_class self
304304
include Sync_m
305-
306-
private
307305

308306
def initialize
309307
super
310308
end
309+
311310
end
312311
Synchronizer = Sync

0 commit comments

Comments
 (0)