Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.Object} | |
| 8 */ | |
| 9 WebInspector.Lock = function() | |
| 10 { | |
| 11 this._count = 0; // Reentrant. | |
| 12 } | |
| 13 | |
| 14 /** | |
| 15 * @enum {string} | |
| 16 */ | |
| 17 WebInspector.Lock.Events = { | |
| 18 StateChanged: "StateChanged" | |
| 19 } | |
| 20 | |
| 21 WebInspector.Lock.prototype = { | |
| 22 /** | |
| 23 * @return {boolean} | |
| 24 */ | |
| 25 isAcquired: function() | |
| 26 { | |
| 27 return !!this._count; | |
| 28 }, | |
| 29 | |
| 30 acquire: function() | |
| 31 { | |
| 32 if (++this._count === 1) | |
| 33 this.dispatchEventToListeners(WebInspector.Lock.Events.StateChanged) ; | |
| 34 }, | |
| 35 | |
| 36 release: function() | |
| 37 { | |
| 38 --this._count; | |
| 39 if (this._count < 0) { | |
| 40 console.error("WebInspector.Lock acquire/release calls are unbalance d " + new Error().stack); | |
| 41 return; | |
| 42 } | |
| 43 if (!this._count) | |
| 44 this.dispatchEventToListeners(WebInspector.Lock.Events.StateChanged) ; | |
| 45 }, | |
| 46 | |
| 47 __proto__: WebInspector.Object.prototype | |
| 48 } | |
| 49 | |
| 50 /** @type {!WebInspector.Lock} */ | |
| 51 WebInspector.profilingLock = new WebInspector.Lock(); | |
|
pfeldman
2014/08/15 09:09:03
Lets create this profiling lock in the app.
| |
| OLD | NEW |