CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/thread_factory.rb
Views: 1904
1
# -*- coding: binary -*-
2
module Rex
3
4
###
5
#
6
# This class provides a wrapper around Thread.new that can provide
7
# additional features if a corresponding thread provider is set.
8
#
9
###
10
11
class ThreadFactory
12
13
@@provider = nil
14
15
def self.provider=(val)
16
@@provider = val
17
end
18
19
def self.spawn(name, crit, *args, &block)
20
if @@provider
21
if block
22
return @@provider.spawn(name, crit, *args){ |*args_copy| block.call(*args_copy) }
23
else
24
return @@provider.spawn(name, crit, *args)
25
end
26
else
27
t = nil
28
if block
29
t = ::Thread.new(*args){ |*args_copy| block.call(*args_copy) }
30
else
31
t = ::Thread.new(*args)
32
end
33
t[:tm_name] = name
34
t[:tm_crit] = crit
35
t[:tm_time] = ::Time.now
36
t[:tm_call] = caller
37
return t
38
end
39
40
end
41
end
42
43
end
44
45