FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
android_external_webkit/JavaScriptCore/runtime/JSLock.h at froyo · Y6b/android_external_webkit · GitHub
Y6b
/
android_external_webkit
Public
forked from
CyanogenMod/android_external_webkit
Notifications
You must be signed in to change notification settings
Fork
6
Star
10
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
android_external_webkit
/
JavaScriptCore
/
runtime
/
JSLock.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (86 loc) · 3.53 KB
Breadcrumbs
android_external_webkit
/
JavaScriptCore
/
runtime
/
JSLock.h
Copy path
File metadata and controls
104 lines (86 loc) · 3.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) 2005, 2008, 2009 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#
ifndef
JSLock_h
#
define
JSLock_h
#
include
<
wtf/Assertions.h
>
#
include
<
wtf/Noncopyable.h
>
namespace
JSC
{
//
To make it safe to use JavaScript on multiple threads, it is
//
important to lock before doing anything that allocates a
//
JavaScript data structure or that interacts with shared state
//
such as the protect count hash table. The simplest way to lock
//
is to create a local JSLock object in the scope where the lock
//
must be held. The lock is recursive so nesting is ok. The JSLock
//
object also acts as a convenience short-hand for running important
//
initialization routines.
//
To avoid deadlock, sometimes it is necessary to temporarily
//
release the lock. Since it is recursive you actually have to
//
release all locks held by your thread. This is safe to do if
//
you are executing code that doesn't require the lock, and you
//
reacquire the right number of locks at the end. You can do this
//
by constructing a locally scoped JSLock::DropAllLocks object. The
//
DropAllLocks object takes care to release the JSLock only if your
//
thread acquired it to begin with.
//
For contexts other than the single shared one, implicit locking is not done,
//
but we still need to perform all the counting in order to keep debug
//
assertions working, so that clients that use the shared context don't break.
class
ExecState
;
enum
JSLockBehavior { SilenceAssertionsOnly, LockForReal };
class
JSLock
:
public
Noncopyable
{
public:
JSLock
(ExecState*);
JSLock
(JSLockBehavior lockBehavior)
: m_lockBehavior(lockBehavior)
{
#
ifdef
NDEBUG
//
Locking "not for real" is a debug-only feature.
if
(lockBehavior == SilenceAssertionsOnly)
return
;
#
endif
lock
(lockBehavior);
}
~JSLock
()
{
#
ifdef
NDEBUG
//
Locking "not for real" is a debug-only feature.
if
(m_lockBehavior == SilenceAssertionsOnly)
return
;
#
endif
unlock
(m_lockBehavior);
}
static
void
lock
(JSLockBehavior);
static
void
unlock
(JSLockBehavior);
static
void
lock
(ExecState*);
static
void
unlock
(ExecState*);
static
intptr_t
lockCount
();
static
bool
currentThreadIsHoldingLock
();
JSLockBehavior m_lockBehavior;
class
DropAllLocks
:
public
Noncopyable
{
public:
DropAllLocks
(ExecState* exec);
DropAllLocks
(JSLockBehavior);
~DropAllLocks
();
private:
intptr_t
m_lockCount;
JSLockBehavior m_lockBehavior;
};
};
}
//
namespace
#
endif
//
JSLock_h
Back
|
FazBrowse Home
|
New Git URL