Merge branch 'fix-plugin-locking'

This commit is contained in:
Oliver Bristow
2017-04-09 19:56:14 +01:00
2 changed files with 23 additions and 30 deletions
+5 -2
View File
@@ -22,13 +22,16 @@ class Plugin
def_field :examples
#, :category
@registered_plugins = {}
attr :mutex
class << self
attr_reader :registered_plugins
private :new
attr_reader :locked
attr_reader :plugin_name
@locked=false
end
def initialize
@mutex = Mutex.new
end
def self.define(name, &block)
+18 -28
View File
@@ -384,34 +384,24 @@ end
### core
def run_plugins(target)
results=[]
$plugins_to_use.each do |name,plugin|
begin
while plugin.locked?
#sleep 0.1
puts "Waiting for plugin:#{name} to unlock" if $verbose > 2
Thread.pass
end
plugin.lock
plugin.init(target)
# eXecute the plugin
#start_time = Time.now
result=plugin.x
#end_time = Time.now
#$PLUGIN_TIMES[name] += end_time - start_time
plugin.unlock
rescue Exception => err
error("ERROR: Plugin #{name} failed for #{target.to_s}. #{err}")
plugin.unlock
raise if $WWDEBUG == true
end
results << [name, result] unless result.nil? or result.empty?
end
results
results = []
$plugins_to_use.each do |name, plugin|
result = plugin.mutex.synchronize do
begin
plugin.init(target)
# eXecute the plugin
#start_time = Time.now
plugin.x
#end_time = Time.now
#$PLUGIN_TIMES[name] += end_time - start_time
rescue Exception => err
error("ERROR: Plugin #{name} failed for #{target}. #{err}")
raise if $WWDEBUG == true
end
end
results << [name, result] unless result.nil? or result.empty?
end
results
end