| 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..a33e54be4cbfd103ff27746fc7847ece2835d997
|
| --- /dev/null
|
| +++ b/Source/devtools/front_end/common/Lock.js
|
| @@ -0,0 +1,48 @@
|
| +// 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
|
| +}
|
|
|