Commit 68e03e73 authored by pmonette's avatar pmonette Committed by Commit bot

Enforce singleton not allowed behavior for CONTINUE_ON_SHUTDOWN tasks

CONTINUE_ON_SHUTDOWN means the thread running the task will not be
joined on shutdown and may not have a valid singleton/lazy_instance
at that moment.

Also made DhcpcsvcInitSingleton explicitly leaky to avoid
the AssertSingletonAllowed() dcheck.

BUG=478209

Committed: https://crrev.com/de7e9038663d69356e558764d5a7b215e8b49b5b
Review-Url: https://codereview.chromium.org/1904273002
Cr-Original-Commit-Position: refs/heads/master@{#390125}
Cr-Commit-Position: refs/heads/master@{#406053}
parent 7b4239d4
...@@ -247,6 +247,14 @@ class SequencedWorkerPool::Worker : public SimpleThread { ...@@ -247,6 +247,14 @@ class SequencedWorkerPool::Worker : public SimpleThread {
is_processing_task_ = true; is_processing_task_ = true;
task_sequence_token_ = token; task_sequence_token_ = token;
task_shutdown_behavior_ = shutdown_behavior; task_shutdown_behavior_ = shutdown_behavior;
// It is dangerous for tasks with CONTINUE_ON_SHUTDOWN to access a class
// that implements a non-leaky base::Singleton because they are generally
// destroyed before the process terminates via an AtExitManager
// registration. This will trigger a DCHECK to warn of such cases. See the
// comment about CONTINUE_ON_SHUTDOWN for more details.
ThreadRestrictions::SetSingletonAllowed(task_shutdown_behavior_ !=
CONTINUE_ON_SHUTDOWN);
} }
// Indicates that the task has finished running. // Indicates that the task has finished running.
......
...@@ -19,15 +19,12 @@ class DhcpcsvcInitSingleton { ...@@ -19,15 +19,12 @@ class DhcpcsvcInitSingleton {
DWORD err = DhcpCApiInitialize(&version); DWORD err = DhcpCApiInitialize(&version);
DCHECK(err == ERROR_SUCCESS); // DCHECK_EQ complains of unsigned mismatch. DCHECK(err == ERROR_SUCCESS); // DCHECK_EQ complains of unsigned mismatch.
} }
~DhcpcsvcInitSingleton() {
// Worker pool threads that use the DHCP API may still be running, so skip
// cleanup.
}
}; };
static base::LazyInstance<DhcpcsvcInitSingleton> g_dhcpcsvc_init_singleton = // Worker pool threads that use the DHCP API may still be running at shutdown.
LAZY_INSTANCE_INITIALIZER; // Leak instance and skip cleanup.
static base::LazyInstance<DhcpcsvcInitSingleton>::Leaky
g_dhcpcsvc_init_singleton = LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment