Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: mutex_m.rb
#--
[0] Fix | Delete
# mutex_m.rb -
[1] Fix | Delete
# $Release Version: 3.0$
[2] Fix | Delete
# $Revision: 1.7 $
[3] Fix | Delete
# $Date: 1998/02/27 04:28:57 $
[4] Fix | Delete
# Original from mutex.rb
[5] Fix | Delete
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
[6] Fix | Delete
# modified by matz
[7] Fix | Delete
# patched by akira yamada
[8] Fix | Delete
#++
[9] Fix | Delete
#
[10] Fix | Delete
# == Usage
[11] Fix | Delete
#
[12] Fix | Delete
# Extend an object and use it like a Mutex object:
[13] Fix | Delete
#
[14] Fix | Delete
# require "mutex_m.rb"
[15] Fix | Delete
# obj = Object.new
[16] Fix | Delete
# obj.extend Mutex_m
[17] Fix | Delete
# # ...
[18] Fix | Delete
#
[19] Fix | Delete
# Or, include Mutex_m in a class to have its instances behave like a Mutex
[20] Fix | Delete
# object:
[21] Fix | Delete
#
[22] Fix | Delete
# class Foo
[23] Fix | Delete
# include Mutex_m
[24] Fix | Delete
# # ...
[25] Fix | Delete
# end
[26] Fix | Delete
#
[27] Fix | Delete
# obj = Foo.new
[28] Fix | Delete
[29] Fix | Delete
module Mutex_m
[30] Fix | Delete
def Mutex_m.define_aliases(cl)
[31] Fix | Delete
cl.module_eval %q{
[32] Fix | Delete
alias locked? mu_locked?
[33] Fix | Delete
alias lock mu_lock
[34] Fix | Delete
alias unlock mu_unlock
[35] Fix | Delete
alias try_lock mu_try_lock
[36] Fix | Delete
alias synchronize mu_synchronize
[37] Fix | Delete
}
[38] Fix | Delete
end
[39] Fix | Delete
[40] Fix | Delete
def Mutex_m.append_features(cl)
[41] Fix | Delete
super
[42] Fix | Delete
define_aliases(cl) unless cl.instance_of?(Module)
[43] Fix | Delete
end
[44] Fix | Delete
[45] Fix | Delete
def Mutex_m.extend_object(obj)
[46] Fix | Delete
super
[47] Fix | Delete
obj.mu_extended
[48] Fix | Delete
end
[49] Fix | Delete
[50] Fix | Delete
def mu_extended
[51] Fix | Delete
unless (defined? locked? and
[52] Fix | Delete
defined? lock and
[53] Fix | Delete
defined? unlock and
[54] Fix | Delete
defined? try_lock and
[55] Fix | Delete
defined? synchronize)
[56] Fix | Delete
Mutex_m.define_aliases(class<<self;self;end)
[57] Fix | Delete
end
[58] Fix | Delete
mu_initialize
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
# locking
[62] Fix | Delete
def mu_synchronize
[63] Fix | Delete
begin
[64] Fix | Delete
mu_lock
[65] Fix | Delete
yield
[66] Fix | Delete
ensure
[67] Fix | Delete
mu_unlock
[68] Fix | Delete
end
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
def mu_locked?
[72] Fix | Delete
@mu_locked
[73] Fix | Delete
end
[74] Fix | Delete
[75] Fix | Delete
def mu_try_lock
[76] Fix | Delete
result = false
[77] Fix | Delete
Thread.critical = true
[78] Fix | Delete
unless @mu_locked
[79] Fix | Delete
@mu_locked = true
[80] Fix | Delete
result = true
[81] Fix | Delete
end
[82] Fix | Delete
Thread.critical = false
[83] Fix | Delete
result
[84] Fix | Delete
end
[85] Fix | Delete
[86] Fix | Delete
def mu_lock
[87] Fix | Delete
while (Thread.critical = true; @mu_locked)
[88] Fix | Delete
@mu_waiting.push Thread.current
[89] Fix | Delete
Thread.stop
[90] Fix | Delete
end
[91] Fix | Delete
@mu_locked = true
[92] Fix | Delete
Thread.critical = false
[93] Fix | Delete
self
[94] Fix | Delete
end
[95] Fix | Delete
[96] Fix | Delete
def mu_unlock
[97] Fix | Delete
return unless @mu_locked
[98] Fix | Delete
Thread.critical = true
[99] Fix | Delete
wait = @mu_waiting
[100] Fix | Delete
@mu_waiting = []
[101] Fix | Delete
@mu_locked = false
[102] Fix | Delete
Thread.critical = false
[103] Fix | Delete
for w in wait
[104] Fix | Delete
w.run
[105] Fix | Delete
end
[106] Fix | Delete
self
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
private
[110] Fix | Delete
[111] Fix | Delete
def mu_initialize
[112] Fix | Delete
@mu_waiting = []
[113] Fix | Delete
@mu_locked = false;
[114] Fix | Delete
end
[115] Fix | Delete
[116] Fix | Delete
def initialize(*args)
[117] Fix | Delete
mu_initialize
[118] Fix | Delete
super
[119] Fix | Delete
end
[120] Fix | Delete
end
[121] Fix | Delete
[122] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function