Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / common / Lock.js
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 unbalanced " + 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 }