diff options
author | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-06-06 14:19:33 +0000 |
---|---|---|
committer | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-06-06 14:19:33 +0000 |
commit | 85d105cf8c7c664d34bf86b8d72c728cb5b6e7ab (patch) | |
tree | 261030f30316bd72fa88aba98d1d0932bfa6158f /lib | |
parent | b2658a3d839916db0cde8e810212932d1dc63cd5 (diff) |
* 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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mutex_m.rb | 29 | ||||
-rw-r--r-- | lib/sync.rb | 71 |
2 files changed, 47 insertions, 53 deletions
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb index fe05a45e9d..0192d83bee 100644 --- a/lib/mutex_m.rb +++ b/lib/mutex_m.rb @@ -25,18 +25,19 @@ # module Mutex_m + def Mutex_m.define_aliases(cl) + cl.module_eval %q{ + alias locked? mu_locked? + alias lock mu_lock + alias unlock mu_unlock + alias try_lock mu_try_lock + alias synchronize mu_synchronize + } + end + def Mutex_m.append_features(cl) super - unless cl.instance_of?(Module) - cl.module_eval %q{ - alias locked? mu_locked? - alias lock mu_lock - alias unlock mu_unlock - alias try_lock mu_try_lock - alias synchronize mu_synchronize - } - end - self + define_aliases(cl) unless cl.instance_of?(Module) end def Mutex_m.extend_object(obj) @@ -50,13 +51,7 @@ module Mutex_m defined? unlock and defined? try_lock and defined? synchronize) - eval "class << self - alias locked? mu_locked? - alias lock mu_lock - alias unlock mu_unlock - alias try_lock mu_try_lock - alias synchronize mu_synchronize - end" + Mutex_m.define_aliases(class<<self;self;end) end mu_initialize end diff --git a/lib/sync.rb b/lib/sync.rb index 6ddd837dad..79522ed885 100644 --- a/lib/sync.rb +++ b/lib/sync.rb @@ -1,10 +1,9 @@ # # sync.rb - 2 phase lock with counter -# $Release Version: 0.2$ +# $Release Version: 1.0$ # $Revision$ # $Date$ -# by Keiju ISHITSUKA -# modified by matz +# by Keiju ISHITSUKA(keiju@ishitsuka.com) # # -- # Sync_m, Synchronizer_m @@ -12,7 +11,7 @@ # obj.extend(Sync_m) # or # class Foo -# Sync_m.include_to self +# include Sync_m # : # end # @@ -76,28 +75,32 @@ module Sync_m end end - def Sync_m.included(cl) + def Sync_m.define_aliases(cl) + cl.module_eval %q{ + 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 + + def Sync_m.append_features(cl) + super unless cl.instance_of?(Module) # do nothing for Modules # make aliases and include the proper module. - cl.module_eval %q{ - 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 - } + define_aliases(cl) end - return self end def Sync_m.extend_object(obj) super obj.sync_extended end - + def sync_extended unless (defined? locked? and defined? shared? and @@ -106,19 +109,11 @@ module Sync_m defined? unlock and defined? try_lock and defined? synchronize) - eval "class << self - 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" + Sync_m.define_aliases(class<<self;self;end) end - initialize + sync_initialize end - + # accessing def sync_locked? sync_mode != UN @@ -229,34 +224,38 @@ module Sync_m end def sync_synchronize(mode = EX) - sync_lock(mode) begin + sync_lock(mode) yield ensure sync_unlock end end - + attr :sync_mode, true + attr :sync_waiting, true attr :sync_upgrade_waiting, true attr :sync_sh_locker, true attr :sync_ex_locker, true attr :sync_ex_count, true - + private - def initialize(*args) - ret = super + def sync_initialize @sync_mode = UN @sync_waiting = [] @sync_upgrade_waiting = [] @sync_sh_locker = Hash.new @sync_ex_locker = nil @sync_ex_count = 0 - return ret end - + + def initialize(*args) + sync_initialize + super + end + def sync_try_lock_sub(m) case m when SH @@ -301,12 +300,12 @@ end Synchronizer_m = Sync_m class Sync + #Sync_m.extend_class self include Sync_m - - private def initialize super end + end Synchronizer = Sync |