Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2718)

Unified Diff: base/win/scoped_handle.cc

Issue 2667513003: Remove some LazyInstance use in base/ (Closed)
Patch Set: no message_window Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/win/scoped_handle.cc
diff --git a/base/win/scoped_handle.cc b/base/win/scoped_handle.cc
index 6d152aec4141be25af2f6b3d1ee70b24e9d45a64..47ab8542de3b5affdb05e50669fa1c807987aec7 100644
--- a/base/win/scoped_handle.cc
+++ b/base/win/scoped_handle.cc
@@ -11,7 +11,6 @@
#include "base/debug/alias.h"
#include "base/debug/stack_trace.h"
#include "base/hash.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/synchronization/lock_impl.h"
@@ -43,10 +42,13 @@ struct Info {
};
typedef std::unordered_map<HANDLE, Info, HandleHash> HandleMap;
-// g_lock protects the handle map and setting g_active_verifier within this
+// GetLock() protects the handle map and setting g_active_verifier within this
// module.
typedef base::internal::LockImpl NativeLock;
-base::LazyInstance<NativeLock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
+NativeLock* GetLock() {
+ static auto native_lock = new NativeLock();
+ return native_lock;
+}
// Simple automatic locking using a native critical section so it supports
// recursive locking.
@@ -70,9 +72,7 @@ class AutoNativeLock {
// way to delete this object from the wrong side of it (or any side, actually).
class ActiveVerifier {
public:
- explicit ActiveVerifier(bool enabled)
- : enabled_(enabled), lock_(g_lock.Pointer()) {
- }
+ explicit ActiveVerifier(bool enabled) : enabled_(enabled), lock_(GetLock()) {}
// Retrieves the current verifier.
static ActiveVerifier* Get();
@@ -117,11 +117,11 @@ bool CloseHandleWrapper(HANDLE handle) {
return true;
}
-// Assigns the g_active_verifier global within the g_lock lock.
+// Assigns the g_active_verifier global within the GetLock() lock.
// If |existing_verifier| is non-null then |enabled| is ignored.
void ThreadSafeAssignOrCreateActiveVerifier(ActiveVerifier* existing_verifier,
bool enabled) {
- AutoNativeLock lock(g_lock.Get());
+ AutoNativeLock lock(*GetLock());
// Another thread in this module might be trying to assign the global
// verifier, so check that within the lock here.
if (g_active_verifier)

Powered by Google App Engine
This is Rietveld 408576698