-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
QE 2022-09-19, QE 2022-10-03, QE 2022-10-17, QE 2022-10-31, QE 2022-11-14, QE 2022-11-28, QE 2022-12-12, QE 2022-12-26, QE 2023-01-09, QE 2023-01-23
-
0
First, a `thread_local` storage object like this
thread_local std::atomic<MozJSImplScope*> kCurrentScope = nullptr; // NOLINT
should be disqualified from being called a k- constant as it has a subtle and dynamic lifecycle.
Second, the only use of this variable is as the returned pointer from getThreadScope.
And the only use of getThreadScope is to call setOOM() on it.
auto scope = mongo::mozjs::MozJSImplScope::getThreadScope();
if (scope)
scope->setOOM();
`scope` goes out of scope after this statement. No more statements in enclosing block.
One solution is to convert the thread_local to a class that has a definite destructor, similar to how it's done for ThreadName and the same technique should work here.