]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/JSLock.h
1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2005 Apple Computer, Inc.
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.
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.
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.
26 #include <wtf/Assertions.h>
27 #include <wtf/Noncopyable.h>
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.
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.
49 class JSLock
: Noncopyable
{
64 static int lockCount();
65 static bool currentThreadIsHoldingLock();
67 static void registerThread();
69 class DropAllLocks
: Noncopyable
{
81 #endif // KJS_JSLock_h