* 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
This commit is contained in:
parent
b2658a3d83
commit
85d105cf8c
@ -1,3 +1,10 @@
|
|||||||
|
Wed Jun 6 23:02:36 2001 Keiju Ishitsuka <keiju@ishitsuka.com>
|
||||||
|
|
||||||
|
* lib/sync.rb: bug fix if obj.initialize has parameters when
|
||||||
|
obj.extend(Sync_m)
|
||||||
|
|
||||||
|
* lib/mutex_m.rb: modified bit
|
||||||
|
|
||||||
Wed Jun 6 16:11:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed Jun 6 16:11:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_load): should check if tainted even when wrap is
|
* eval.c (rb_load): should check if tainted even when wrap is
|
||||||
|
@ -25,9 +25,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
module Mutex_m
|
module Mutex_m
|
||||||
def Mutex_m.append_features(cl)
|
def Mutex_m.define_aliases(cl)
|
||||||
super
|
|
||||||
unless cl.instance_of?(Module)
|
|
||||||
cl.module_eval %q{
|
cl.module_eval %q{
|
||||||
alias locked? mu_locked?
|
alias locked? mu_locked?
|
||||||
alias lock mu_lock
|
alias lock mu_lock
|
||||||
@ -36,7 +34,10 @@ module Mutex_m
|
|||||||
alias synchronize mu_synchronize
|
alias synchronize mu_synchronize
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
self
|
|
||||||
|
def Mutex_m.append_features(cl)
|
||||||
|
super
|
||||||
|
define_aliases(cl) unless cl.instance_of?(Module)
|
||||||
end
|
end
|
||||||
|
|
||||||
def Mutex_m.extend_object(obj)
|
def Mutex_m.extend_object(obj)
|
||||||
@ -50,13 +51,7 @@ module Mutex_m
|
|||||||
defined? unlock and
|
defined? unlock and
|
||||||
defined? try_lock and
|
defined? try_lock and
|
||||||
defined? synchronize)
|
defined? synchronize)
|
||||||
eval "class << self
|
Mutex_m.define_aliases(class<<self;self;end)
|
||||||
alias locked? mu_locked?
|
|
||||||
alias lock mu_lock
|
|
||||||
alias unlock mu_unlock
|
|
||||||
alias try_lock mu_try_lock
|
|
||||||
alias synchronize mu_synchronize
|
|
||||||
end"
|
|
||||||
end
|
end
|
||||||
mu_initialize
|
mu_initialize
|
||||||
end
|
end
|
||||||
|
49
lib/sync.rb
49
lib/sync.rb
@ -1,10 +1,9 @@
|
|||||||
#
|
#
|
||||||
# sync.rb - 2 phase lock with counter
|
# sync.rb - 2 phase lock with counter
|
||||||
# $Release Version: 0.2$
|
# $Release Version: 1.0$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
# by Keiju ISHITSUKA
|
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
|
||||||
# modified by matz
|
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
# Sync_m, Synchronizer_m
|
# Sync_m, Synchronizer_m
|
||||||
@ -12,7 +11,7 @@
|
|||||||
# obj.extend(Sync_m)
|
# obj.extend(Sync_m)
|
||||||
# or
|
# or
|
||||||
# class Foo
|
# class Foo
|
||||||
# Sync_m.include_to self
|
# include Sync_m
|
||||||
# :
|
# :
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
@ -76,10 +75,7 @@ module Sync_m
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def Sync_m.included(cl)
|
def Sync_m.define_aliases(cl)
|
||||||
unless cl.instance_of?(Module)
|
|
||||||
# do nothing for Modules
|
|
||||||
# make aliases and include the proper module.
|
|
||||||
cl.module_eval %q{
|
cl.module_eval %q{
|
||||||
alias locked? sync_locked?
|
alias locked? sync_locked?
|
||||||
alias shared? sync_shared?
|
alias shared? sync_shared?
|
||||||
@ -90,7 +86,14 @@ module Sync_m
|
|||||||
alias synchronize sync_synchronize
|
alias synchronize sync_synchronize
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return self
|
|
||||||
|
def Sync_m.append_features(cl)
|
||||||
|
super
|
||||||
|
unless cl.instance_of?(Module)
|
||||||
|
# do nothing for Modules
|
||||||
|
# make aliases and include the proper module.
|
||||||
|
define_aliases(cl)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def Sync_m.extend_object(obj)
|
def Sync_m.extend_object(obj)
|
||||||
@ -106,17 +109,9 @@ module Sync_m
|
|||||||
defined? unlock and
|
defined? unlock and
|
||||||
defined? try_lock and
|
defined? try_lock and
|
||||||
defined? synchronize)
|
defined? synchronize)
|
||||||
eval "class << self
|
Sync_m.define_aliases(class<<self;self;end)
|
||||||
alias locked? sync_locked?
|
|
||||||
alias shared? sync_shared?
|
|
||||||
alias exclusive? sync_exclusive?
|
|
||||||
alias lock sync_lock
|
|
||||||
alias unlock sync_unlock
|
|
||||||
alias try_lock sync_try_lock
|
|
||||||
alias synchronize sync_synchronize
|
|
||||||
end"
|
|
||||||
end
|
end
|
||||||
initialize
|
sync_initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
# accessing
|
# accessing
|
||||||
@ -229,8 +224,8 @@ module Sync_m
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sync_synchronize(mode = EX)
|
def sync_synchronize(mode = EX)
|
||||||
sync_lock(mode)
|
|
||||||
begin
|
begin
|
||||||
|
sync_lock(mode)
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
sync_unlock
|
sync_unlock
|
||||||
@ -238,6 +233,7 @@ module Sync_m
|
|||||||
end
|
end
|
||||||
|
|
||||||
attr :sync_mode, true
|
attr :sync_mode, true
|
||||||
|
|
||||||
attr :sync_waiting, true
|
attr :sync_waiting, true
|
||||||
attr :sync_upgrade_waiting, true
|
attr :sync_upgrade_waiting, true
|
||||||
attr :sync_sh_locker, true
|
attr :sync_sh_locker, true
|
||||||
@ -246,15 +242,18 @@ module Sync_m
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def initialize(*args)
|
def sync_initialize
|
||||||
ret = super
|
|
||||||
@sync_mode = UN
|
@sync_mode = UN
|
||||||
@sync_waiting = []
|
@sync_waiting = []
|
||||||
@sync_upgrade_waiting = []
|
@sync_upgrade_waiting = []
|
||||||
@sync_sh_locker = Hash.new
|
@sync_sh_locker = Hash.new
|
||||||
@sync_ex_locker = nil
|
@sync_ex_locker = nil
|
||||||
@sync_ex_count = 0
|
@sync_ex_count = 0
|
||||||
return ret
|
end
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
sync_initialize
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_try_lock_sub(m)
|
def sync_try_lock_sub(m)
|
||||||
@ -301,12 +300,12 @@ end
|
|||||||
Synchronizer_m = Sync_m
|
Synchronizer_m = Sync_m
|
||||||
|
|
||||||
class Sync
|
class Sync
|
||||||
|
#Sync_m.extend_class self
|
||||||
include Sync_m
|
include Sync_m
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Synchronizer = Sync
|
Synchronizer = Sync
|
||||||
|
Loading…
x
Reference in New Issue
Block a user