2007-08-24 11:26:28 -04:00
|
|
|
|
|
|
|
# Mutex
|
|
|
|
|
|
|
|
class Mutex
|
2007-08-24 14:10:37 -04:00
|
|
|
def synchronize
|
|
|
|
self.lock
|
2007-08-27 12:48:14 -04:00
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
2008-01-10 04:01:30 -05:00
|
|
|
self.unlock rescue nil
|
2007-08-27 12:48:14 -04:00
|
|
|
end
|
2007-08-24 11:26:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-08-24 21:09:08 -04:00
|
|
|
# Thread
|
|
|
|
|
|
|
|
class Thread
|
|
|
|
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
|
|
|
|
def self.exclusive
|
|
|
|
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
|
|
|
|
yield
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-16 09:23:15 -04:00
|
|
|
module Kernel
|
|
|
|
module_function
|
|
|
|
def require_relative(relative_feature)
|
|
|
|
c = caller.first
|
|
|
|
e = c.rindex(/:\d+:in /)
|
|
|
|
file = $`
|
|
|
|
if /\A\((.*)\)/ =~ file # eval, etc.
|
|
|
|
raise LoadError, "require_relative is called in #{$1}"
|
|
|
|
end
|
|
|
|
absolute_feature = File.expand_path(File.join(File.dirname(file), relative_feature))
|
|
|
|
require absolute_feature
|
2008-04-12 10:50:18 -04:00
|
|
|
end
|
|
|
|
end
|