@@ -10,43 +10,46 @@ module Concurrent
10
10
11
11
# Suppresses all output when used for logging.
12
12
NULL_LOGGER = lambda { |level , progname , message = nil , &block | }
13
+ private_constant :NULL_LOGGER
13
14
14
- # initialize the global executors
15
- class << self
15
+ # @!visibility private
16
+ GLOBAL_LOGGER = Atomic . new ( NULL_LOGGER )
17
+ private_constant :GLOBAL_LOGGER
16
18
17
- # @!visibility private
18
- @@global_logger = Atomic . new ( NULL_LOGGER )
19
+ # @!visibility private
20
+ AUTO_TERMINATE_GLOBAL_EXECUTORS = AtomicBoolean . new ( true )
21
+ private_constant :AUTO_TERMINATE_GLOBAL_EXECUTORS
19
22
20
- # @!visibility private
21
- @@auto_terminate_global_executors = AtomicBoolean . new ( true )
23
+ # @!visibility private
24
+ AUTO_TERMINATE_ALL_EXECUTORS = AtomicBoolean . new ( true )
25
+ private_constant :AUTO_TERMINATE_ALL_EXECUTORS
22
26
23
- # @!visibility private
24
- @@auto_terminate_all_executors = AtomicBoolean . new ( true )
25
-
26
- # @!visibility private
27
- @@global_fast_executor = LazyReference . new do
28
- Concurrent . new_fast_executor (
29
- stop_on_exit : @@auto_terminate_global_executors . value )
30
- end
27
+ # @!visibility private
28
+ GLOBAL_FAST_EXECUTOR = LazyReference . new do
29
+ Concurrent . new_fast_executor (
30
+ stop_on_exit : AUTO_TERMINATE_GLOBAL_EXECUTORS . value )
31
+ end
32
+ private_constant :GLOBAL_FAST_EXECUTOR
31
33
32
- # @!visibility private
33
- @@global_io_executor = LazyReference . new do
34
- Concurrent . new_io_executor (
35
- stop_on_exit : @@auto_terminate_global_executors . value )
36
- end
34
+ # @!visibility private
35
+ GLOBAL_IO_EXECUTOR = LazyReference . new do
36
+ Concurrent . new_io_executor (
37
+ stop_on_exit : AUTO_TERMINATE_GLOBAL_EXECUTORS . value )
38
+ end
39
+ private_constant :GLOBAL_IO_EXECUTOR
37
40
38
- # @!visibility private
39
- @@global_timer_set = LazyReference . new do
40
- TimerSet . new ( stop_on_exit : @@auto_terminate_global_executors . value )
41
- end
41
+ # @!visibility private
42
+ GLOBAL_TIMER_SET = LazyReference . new do
43
+ TimerSet . new ( stop_on_exit : AUTO_TERMINATE_GLOBAL_EXECUTORS . value )
42
44
end
45
+ private_constant :GLOBAL_TIMER_SET
43
46
44
47
def self . global_logger
45
- @@global_logger . value
48
+ GLOBAL_LOGGER . value
46
49
end
47
50
48
51
def self . global_logger = ( value )
49
- @@global_logger . value = value
52
+ GLOBAL_LOGGER . value = value
50
53
end
51
54
52
55
# Defines if global executors should be auto-terminated with an
@@ -64,7 +67,7 @@ def self.global_logger=(value)
64
67
# application and even then it should be used only when necessary.
65
68
#
66
69
def self . disable_auto_termination_of_global_executors!
67
- @@auto_terminate_global_executors . make_false
70
+ AUTO_TERMINATE_GLOBAL_EXECUTORS . make_false
68
71
end
69
72
70
73
# Defines if global executors should be auto-terminated with an
@@ -85,7 +88,7 @@ def self.disable_auto_termination_of_global_executors!
85
88
# application exit using an `at_exit` handler; false when no auto-termination
86
89
# will occur.
87
90
def self . auto_terminate_global_executors?
88
- @@auto_terminate_global_executors . value
91
+ AUTO_TERMINATE_GLOBAL_EXECUTORS . value
89
92
end
90
93
91
94
# Defines if *ALL* executors should be auto-terminated with an
@@ -105,7 +108,7 @@ def self.auto_terminate_global_executors?
105
108
# gem. It should *only* be used from within the main application.
106
109
# And even then it should be used only when necessary.
107
110
def self . disable_auto_termination_of_all_executors!
108
- @@auto_terminate_all_executors . make_false
111
+ AUTO_TERMINATE_ALL_EXECUTORS . make_false
109
112
end
110
113
111
114
# Defines if *ALL* executors should be auto-terminated with an
@@ -129,21 +132,21 @@ def self.disable_auto_termination_of_all_executors!
129
132
# application exit using an `at_exit` handler; false when no auto-termination
130
133
# will occur.
131
134
def self . auto_terminate_all_executors?
132
- @@auto_terminate_all_executors . value
135
+ AUTO_TERMINATE_ALL_EXECUTORS . value
133
136
end
134
137
135
138
# Global thread pool optimized for short, fast *operations*.
136
139
#
137
140
# @return [ThreadPoolExecutor] the thread pool
138
141
def self . global_fast_executor
139
- @@global_fast_executor . value
142
+ GLOBAL_FAST_EXECUTOR . value
140
143
end
141
144
142
145
# Global thread pool optimized for long, blocking (IO) *tasks*.
143
146
#
144
147
# @return [ThreadPoolExecutor] the thread pool
145
148
def self . global_io_executor
146
- @@global_io_executor . value
149
+ GLOBAL_IO_EXECUTOR . value
147
150
end
148
151
149
152
# Global thread pool user for global *timers*.
@@ -152,7 +155,7 @@ def self.global_io_executor
152
155
#
153
156
# @see Concurrent::timer
154
157
def self . global_timer_set
155
- @@global_timer_set . value
158
+ GLOBAL_TIMER_SET . value
156
159
end
157
160
158
161
def self . shutdown_global_executors
@@ -250,17 +253,15 @@ def global_timer_set
250
253
# Use the :executor constructor option instead.
251
254
def global_task_pool = ( executor )
252
255
warn '[DEPRECATED] Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
253
- var = Concurrent . class_variable_get ( :@@global_io_executor )
254
- var . reconfigure { executor } or
256
+ GLOBAL_IO_EXECUTOR . reconfigure { executor } or
255
257
raise ConfigurationError . new ( 'global task pool was already set' )
256
258
end
257
259
258
260
# @deprecated Replacing global thread pools is deprecated.
259
261
# Use the :executor constructor option instead.
260
262
def global_operation_pool = ( executor )
261
263
warn '[DEPRECATED] Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
262
- var = Concurrent . class_variable_get ( :@@global_fast_executor )
263
- var . reconfigure { executor } or
264
+ GLOBAL_FAST_EXECUTOR . reconfigure { executor } or
264
265
raise ConfigurationError . new ( 'global operation pool was already set' )
265
266
end
266
267
0 commit comments