CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/thread_factory.rb
Views: 11766
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