source: webkit/trunk/JavaScriptCore/kjs/JSLock.h@ 32687

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

JavaScriptCore:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and
functions accessing data members from Interpreter to JSGlobalObject.
Changed Interpreter member functions to static functions.


This resolves a bug in global object bootstrapping, where the global
ExecState could be used when uninitialized.


This is a big change, but it's mostly code motion and renaming.


Layout and JS tests, and testjsglue and testapi, pass. SunSpider reports
a .7% regression, but Shark sees no difference related to this patch,
and SunSpider reported a .7% speedup from an earlier step in this
refactoring, so I think it's fair to call that a wash.

JavaScriptGlue:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject. Replaced JSInterpreter
subclass with JSGlobalObject subclass.


  • JSRun.cpp: (JSRun::JSRun): (JSRun::Evaluate): (JSRun::CheckSyntax):
  • JSRun.h: (JSGlueGlobalObject::JSGlueGlobalObject):
  • JSUtils.cpp: (KJSValueToCFTypeInternal):
  • JSValueWrapper.cpp: (getThreadGlobalExecState):

WebCore:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject. Changed Interpreter
member functions to static functions. Same for the subclass,
ScriptInterpreter.


This is a big change, but it's mostly code motion and renaming.

WebKit/mac:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject.


  • WebView/WebFrame.mm: (-[WebFrame _attachScriptDebugger]):

WebKit/win:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject.


  • WebFrame.cpp: (WebFrame::globalContext): (WebFrame::attachScriptDebugger): (WebFrame::windowObjectCleared):
  • WebScriptDebugger.cpp: (WebScriptDebugger::WebScriptDebugger):
  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2005 Apple Computer, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef KJS_JSLock_h
24#define KJS_JSLock_h
25
26#include <wtf/Assertions.h>
27#include <wtf/Noncopyable.h>
28
29namespace KJS {
30
31 // To make it safe to use JavaScript on multiple threads, it is
32 // important to lock before doing anything that allocates a
33 // JavaScript data structure or that interacts with shared state
34 // such as the protect count hash table. The simplest way to lock
35 // is to create a local JSLock object in the scope where the lock
36 // must be held. The lock is recursive so nesting is ok. The JSLock
37 // object also acts as a convenience short-hand for running important
38 // initialization routines.
39
40 // To avoid deadlock, sometimes it is necessary to temporarily
41 // release the lock. Since it is recursive you actually have to
42 // release all locks held by your thread. This is safe to do if
43 // you are executing code that doesn't require the lock, and you
44 // reacquire the right number of locks at the end. You can do this
45 // by constructing a locally scoped JSLock::DropAllLocks object. The
46 // DropAllLocks object takes care to release the JSLock only if your
47 // thread acquired it to begin with.
48
49 class JSLock : Noncopyable {
50 public:
51 JSLock()
52 {
53 lock();
54 registerThread();
55 }
56
57 ~JSLock()
58 {
59 unlock();
60 }
61
62 static void lock();
63 static void unlock();
64 static int lockCount();
65 static bool currentThreadIsHoldingLock();
66
67 static void registerThread();
68
69 class DropAllLocks : Noncopyable {
70 public:
71 DropAllLocks();
72 ~DropAllLocks();
73
74 private:
75 int m_lockCount;
76 };
77 };
78
79} // namespace
80
81#endif // KJS_JSLock_h
Note: See TracBrowser for help on using the repository browser.