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
|
|
|
|
|
2009-10-16 17: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
|
2010-01-12 03:32:22 +03:00
|
|
|
absolute_feature = File.join(File.dirname(File.realpath(file)), relative_feature)
|
2009-10-16 17:23:15 +04:00
|
|
|
require absolute_feature
|
2008-04-12 18:50:18 +04:00
|
|
|
end
|
|
|
|
end
|