lib/merb/merb_utils.rb in merb-0.0.5 vs lib/merb/merb_utils.rb in merb-0.0.6
- old
+ new
@@ -64,10 +64,11 @@
self[key.to_s] if key.is_a?(Symbol)
end
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
alias_method :regular_update, :update unless method_defined?(:regular_update)
+ alias_method :u, :regular_update
def []=(key, value)
regular_writer(convert_key(key), convert_value(value))
end
@@ -103,18 +104,53 @@
end
def delete(key)
super(convert_key(key))
end
-
+
def method_missing(m,*a)
- m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:raise(NoMethodError,"#{m}")
+ m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:raise(NoMethodError,"#{m}")
end
-
+
protected
def convert_key(key)
key.kind_of?(Symbol) ? key.to_s : key
end
def convert_value(value)
value.is_a?(Hash) ? value.with_indifferent_access : value
end
end
+
+require 'thread'
+
+# monkey patch Mutex so it does not leak memory.
+class Mutex
+
+ def lock
+ while (Thread.critical = true; @locked)
+ @waiting.unshift Thread.current
+ Thread.stop
+ end
+ @locked = true
+ Thread.critical = false
+ self
+ end
+
+ def unlock
+ return unless @locked
+ Thread.critical = true
+ @locked = false
+ begin
+ t = @waiting.pop
+ t.wakeup if t
+ rescue ThreadError
+ retry
+ end
+ Thread.critical = false
+ begin
+ t.run if t
+ rescue ThreadError
+ end
+ self
+ end
+
+end
\ No newline at end of file