2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-11-12 06:19:49 +00:00
|
|
|
module Rex
|
|
|
|
|
|
|
|
###
|
2012-05-24 23:10:26 +00:00
|
|
|
#
|
|
|
|
# This class provides a wrapper around Thread.new that can provide
|
2010-11-12 06:19:49 +00:00
|
|
|
# additional features if a corresponding thread provider is set.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
class ThreadFactory
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
@@provider = nil
|
2012-05-24 23:10:26 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.provider=(val)
|
|
|
|
@@provider = val
|
|
|
|
end
|
2010-11-12 06:19:49 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.spawn(name, crit, *args, &block)
|
|
|
|
if @@provider
|
|
|
|
if block
|
|
|
|
return @@provider.spawn(name, crit, *args){ |*args_copy| block.call(*args_copy) }
|
|
|
|
else
|
|
|
|
return @@provider.spawn(name, crit, *args)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
t = nil
|
|
|
|
if block
|
|
|
|
t = ::Thread.new(*args){ |*args_copy| block.call(*args_copy) }
|
|
|
|
else
|
|
|
|
t = ::Thread.new(*args)
|
|
|
|
end
|
|
|
|
t[:tm_name] = name
|
|
|
|
t[:tm_crit] = crit
|
|
|
|
t[:tm_time] = Time.now
|
|
|
|
t[:tm_call] = caller
|
|
|
|
return t
|
|
|
|
end
|
2012-05-24 23:10:26 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
end
|
2010-11-12 06:19:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|