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

Unified Diff: Source/devtools/front_end/common/Lock.js

Issue 475803002: Make profiling lock global rather than per Target (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Extracted Lock.js Created 6 years, 4 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
« no previous file with comments | « Source/devtools/front_end/audits/AuditLauncherView.js ('k') | Source/devtools/front_end/common/Object.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/common/Lock.js
diff --git a/Source/devtools/front_end/common/Lock.js b/Source/devtools/front_end/common/Lock.js
new file mode 100644
index 0000000000000000000000000000000000000000..c200cdc06acb1ac2584029a49096e26bf5f4cd0a
--- /dev/null
+++ b/Source/devtools/front_end/common/Lock.js
@@ -0,0 +1,51 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @constructor
+ * @extends {WebInspector.Object}
+ */
+WebInspector.Lock = function()
+{
+ this._count = 0; // Reentrant.
+}
+
+/**
+ * @enum {string}
+ */
+WebInspector.Lock.Events = {
+ StateChanged: "StateChanged"
+}
+
+WebInspector.Lock.prototype = {
+ /**
+ * @return {boolean}
+ */
+ isAcquired: function()
+ {
+ return !!this._count;
+ },
+
+ acquire: function()
+ {
+ if (++this._count === 1)
+ this.dispatchEventToListeners(WebInspector.Lock.Events.StateChanged);
+ },
+
+ release: function()
+ {
+ --this._count;
+ if (this._count < 0) {
+ console.error("WebInspector.Lock acquire/release calls are unbalanced " + new Error().stack);
+ return;
+ }
+ if (!this._count)
+ this.dispatchEventToListeners(WebInspector.Lock.Events.StateChanged);
+ },
+
+ __proto__: WebInspector.Object.prototype
+}
+
+/** @type {!WebInspector.Lock} */
+WebInspector.profilingLock = new WebInspector.Lock();
pfeldman 2014/08/15 09:09:03 Lets create this profiling lock in the app.
« no previous file with comments | « Source/devtools/front_end/audits/AuditLauncherView.js ('k') | Source/devtools/front_end/common/Object.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698