2007-08-24 19:26:28 +04:00
|
|
|
|
|
|
|
# Mutex
|
|
|
|
|
|
|
|
class Mutex
|
2007-08-24 22:10:37 +04:00
|
|
|
def synchronize
|
|
|
|
self.lock
|
2007-08-27 20:48:14 +04:00
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
2008-01-10 12:01:30 +03:00
|
|
|
self.unlock rescue nil
|
2007-08-27 20:48:14 +04:00
|
|
|
end
|
2007-08-24 19:26:28 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-08-25 05:09:08 +04:00
|
|
|
# Thread
|
|
|
|
|
|
|
|
class Thread
|
|
|
|
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
|
|
|
|
def self.exclusive
|
|
|
|
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
|
|
|
|
yield
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-04-12 18:50:18 +04:00
|
|
|
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
|
|
|
|
end
|