source: webkit/trunk/JavaScriptCore/runtime/JSLock.cpp@ 39851

Last change on this file since 39851 was 38528, checked in by [email protected], 17 years ago

JavaScriptCore:

2008-11-17 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Moved runtime/ExecState.* => interpreter/CallFrame.*.

  • API/JSBase.cpp:
  • API/OpaqueJSString.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • debugger/DebuggerCallFrame.h:
  • interpreter/CallFrame.cpp: Copied from runtime/ExecState.cpp.
  • interpreter/CallFrame.h: Copied from runtime/ExecState.h.
  • interpreter/Interpreter.cpp:
  • parser/Nodes.cpp:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:
  • runtime/ClassInfo.h:
  • runtime/Collector.cpp:
  • runtime/Completion.cpp:
  • runtime/ExceptionHelpers.cpp:
  • runtime/ExecState.cpp: Removed.
  • runtime/ExecState.h: Removed.
  • runtime/Identifier.cpp:
  • runtime/JSFunction.cpp:
  • runtime/JSGlobalObjectFunctions.cpp:
  • runtime/JSLock.cpp:
  • runtime/JSNumberCell.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:
  • runtime/Lookup.h:
  • runtime/PropertyNameArray.h:

JavaScriptGlue:

2008-11-17 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Updated for JavaScriptCore rename.

  • ForwardingHeaders/runtime/CallFrame.h: Copied from JavaScriptGlue/ForwardingHeaders/runtime/ExecState.h.
  • ForwardingHeaders/runtime/ExecState.h: Removed.
  • config.h:

WebCore:

2008-11-17 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Updated for JavaScriptCore rename.

  • ForwardingHeaders/interpreter/CallFrame.h: Copied from WebCore/ForwardingHeaders/runtime/ExecState.h.
  • ForwardingHeaders/runtime/ExecState.h: Removed.
  • bindings/objc/WebScriptObject.mm:
  • bridge/c/c_instance.cpp:
  • bridge/jni/jni_jsobject.mm:
  • dom/Node.cpp:
  • dom/NodeFilter.cpp:
  • dom/NodeIterator.cpp:
  • dom/TreeWalker.cpp:
  • inspector/JavaScriptCallFrame.h:
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/*
2 * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the NU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA
18 *
19 */
20
21#include "config.h"
22#include "JSLock.h"
23
24#include "Collector.h"
25#include "CallFrame.h"
26
27#if ENABLE(JSC_MULTIPLE_THREADS)
28#include <pthread.h>
29#endif
30
31namespace JSC {
32
33#if ENABLE(JSC_MULTIPLE_THREADS)
34
35// Acquire this mutex before accessing lock-related data.
36static pthread_mutex_t JSMutex = PTHREAD_MUTEX_INITIALIZER;
37
38// Thread-specific key that tells whether a thread holds the JSMutex, and how many times it was taken recursively.
39pthread_key_t JSLockCount;
40
41static void createJSLockCount()
42{
43 pthread_key_create(&JSLockCount, 0);
44}
45
46pthread_once_t createJSLockCountOnce = PTHREAD_ONCE_INIT;
47
48// Lock nesting count.
49intptr_t JSLock::lockCount()
50{
51 pthread_once(&createJSLockCountOnce, createJSLockCount);
52
53 return reinterpret_cast<intptr_t>(pthread_getspecific(JSLockCount));
54}
55
56static void setLockCount(intptr_t count)
57{
58 ASSERT(count >= 0);
59 pthread_setspecific(JSLockCount, reinterpret_cast<void*>(count));
60}
61
62JSLock::JSLock(ExecState* exec)
63 : m_lockingForReal(exec->globalData().isSharedInstance)
64{
65 lock(m_lockingForReal);
66}
67
68void JSLock::lock(bool lockForReal)
69{
70#ifdef NDEBUG
71 // Locking "not for real" is a debug-only feature.
72 if (!lockForReal)
73 return;
74#endif
75
76 pthread_once(&createJSLockCountOnce, createJSLockCount);
77
78 intptr_t currentLockCount = lockCount();
79 if (!currentLockCount && lockForReal) {
80 int result;
81 result = pthread_mutex_lock(&JSMutex);
82 ASSERT(!result);
83 }
84 setLockCount(currentLockCount + 1);
85}
86
87void JSLock::unlock(bool lockForReal)
88{
89 ASSERT(lockCount());
90
91#ifdef NDEBUG
92 // Locking "not for real" is a debug-only feature.
93 if (!lockForReal)
94 return;
95#endif
96
97 intptr_t newLockCount = lockCount() - 1;
98 setLockCount(newLockCount);
99 if (!newLockCount && lockForReal) {
100 int result;
101 result = pthread_mutex_unlock(&JSMutex);
102 ASSERT(!result);
103 }
104}
105
106void JSLock::lock(ExecState* exec)
107{
108 lock(exec->globalData().isSharedInstance);
109}
110
111void JSLock::unlock(ExecState* exec)
112{
113 unlock(exec->globalData().isSharedInstance);
114}
115
116bool JSLock::currentThreadIsHoldingLock()
117{
118 pthread_once(&createJSLockCountOnce, createJSLockCount);
119 return !!pthread_getspecific(JSLockCount);
120}
121
122JSLock::DropAllLocks::DropAllLocks(ExecState* exec)
123 : m_lockingForReal(exec->globalData().isSharedInstance)
124{
125 pthread_once(&createJSLockCountOnce, createJSLockCount);
126
127 m_lockCount = JSLock::lockCount();
128 for (intptr_t i = 0; i < m_lockCount; i++)
129 JSLock::unlock(m_lockingForReal);
130}
131
132JSLock::DropAllLocks::DropAllLocks(bool lockingForReal)
133 : m_lockingForReal(lockingForReal)
134{
135 pthread_once(&createJSLockCountOnce, createJSLockCount);
136
137 // It is necessary to drop even "unreal" locks, because having a non-zero lock count
138 // will prevent a real lock from being taken.
139
140 m_lockCount = JSLock::lockCount();
141 for (intptr_t i = 0; i < m_lockCount; i++)
142 JSLock::unlock(m_lockingForReal);
143}
144
145JSLock::DropAllLocks::~DropAllLocks()
146{
147 for (intptr_t i = 0; i < m_lockCount; i++)
148 JSLock::lock(m_lockingForReal);
149}
150
151#else
152
153JSLock::JSLock(ExecState*)
154 : m_lockingForReal(false)
155{
156}
157
158// If threading support is off, set the lock count to a constant value of 1 so ssertions
159// that the lock is held don't fail
160intptr_t JSLock::lockCount()
161{
162 return 1;
163}
164
165bool JSLock::currentThreadIsHoldingLock()
166{
167 return true;
168}
169
170void JSLock::lock(bool)
171{
172}
173
174void JSLock::unlock(bool)
175{
176}
177
178void JSLock::lock(ExecState*)
179{
180}
181
182void JSLock::unlock(ExecState*)
183{
184}
185
186JSLock::DropAllLocks::DropAllLocks(ExecState*)
187{
188}
189
190JSLock::DropAllLocks::DropAllLocks(bool)
191{
192}
193
194JSLock::DropAllLocks::~DropAllLocks()
195{
196}
197
198#endif // USE(MULTIPLE_THREADS)
199
200} // namespace JSC
Note: See TracBrowser for help on using the repository browser.