| 1 | /* |
| 2 | * Copyright (C) 2005, 2008, 2009 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 GNU |
| 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 | #ifndef JSLock_h |
| 22 | #define JSLock_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSLock.h:22:9`! |
| 23 | |
| 24 | #include <wtf/Assertions.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h`/ |
| 25 | #include <wtf/Noncopyable.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Noncopyable.h`/ |
| 26 | |
| 27 | namespace JSCcxx . . $ `<built-in>:463:9`! { |
| 28 | |
| 29 | // To make it safe to use JavaScript on multiple threads, it is |
| 30 | // important to lock before doing anything that allocates a |
| 31 | // JavaScript data structure or that interacts with shared state |
| 32 | // such as the protect count hash table. The simplest way to lock |
| 33 | // is to create a local JSLock object in the scope where the lock |
| 34 | // must be held. The lock is recursive so nesting is ok. The JSLock |
| 35 | // object also acts as a convenience short-hand for running important |
| 36 | // initialization routines. |
| 37 | |
| 38 | // To avoid deadlock, sometimes it is necessary to temporarily |
| 39 | // release the lock. Since it is recursive you actually have to |
| 40 | // release all locks held by your thread. This is safe to do if |
| 41 | // you are executing code that doesn't require the lock, and you |
| 42 | // reacquire the right number of locks at the end. You can do this |
| 43 | // by constructing a locally scoped JSLock::DropAllLocks object. The |
| 44 | // DropAllLocks object takes care to release the JSLock only if your |
| 45 | // thread acquired it to begin with. |
| 46 | |
| 47 | // For contexts other than the single shared one, implicit locking is not done, |
| 48 | // but we still need to perform all the counting in order to keep debug |
| 49 | // assertions working, so that clients that use the shared context don't break. |
| 50 | |
| 51 | class ExecStatecxx . . $ QTJSC/ExecState#; |
| 52 | |
| 53 | enum JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior# { SilenceAssertionsOnlycxx . . $ QTJSC/SilenceAssertionsOnly., LockForRealcxx . . $ QTJSC/LockForReal. }; |
| 54 | |
| 55 | class JSLockcxx . . $ QTJSC/JSLock# : public Noncopyablecxx . . $ Noncopyable# { |
| 56 | public: |
| 57 | JSLockcxx . . $ QTJSC/JSLock#JSLock(d2cb180e190a9680).(ExecStatecxx . . $ QTJSC/ExecState#*); |
| 58 | |
| 59 | JSLockcxx . . $ QTJSC/JSLock#JSLock(a237af5886395a97).(JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior# lockBehavior) |
| 60 | : m_lockBehaviorcxx . . $ QTJSC/JSLock#m_lockBehavior.(lockBehavior) |
| 61 | { |
| 62 | #ifdef NDEBUGcxx . . $ `<built-in>:472:9`! |
| 63 | // Locking "not for real" is a debug-only feature. |
| 64 | if (lockBehavior == SilenceAssertionsOnlycxx . . $ QTJSC/SilenceAssertionsOnly.) |
| 65 | return; |
| 66 | #endif |
| 67 | lockcxx . . $ QTJSC/JSLock#lock(a237af5886395a97).(lockBehavior); |
| 68 | } |
| 69 | |
| 70 | ~cxx . . $ QTJSC/JSLock#`~JSLock`(49f6e7a06ebc5aa8).JSLockcxx . . $ QTJSC/JSLock#() |
| 71 | { |
| 72 | #ifdef NDEBUGcxx . . $ `<built-in>:472:9`! |
| 73 | // Locking "not for real" is a debug-only feature. |
| 74 | if (m_lockBehaviorcxx . . $ QTJSC/JSLock#m_lockBehavior. == SilenceAssertionsOnlycxx . . $ QTJSC/SilenceAssertionsOnly.) |
| 75 | return; |
| 76 | #endif |
| 77 | unlockcxx . . $ QTJSC/JSLock#unlock(a237af5886395a97).(m_lockBehaviorcxx . . $ QTJSC/JSLock#m_lockBehavior.); |
| 78 | } |
| 79 | |
| 80 | static void lockcxx . . $ QTJSC/JSLock#lock(a237af5886395a97).(JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior#); |
| 81 | static void unlockcxx . . $ QTJSC/JSLock#unlock(a237af5886395a97).(JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior#); |
| 82 | static void lockcxx . . $ QTJSC/JSLock#lock(d2cb180e190a9680).(ExecStatecxx . . $ QTJSC/ExecState#*); |
| 83 | static void unlockcxx . . $ QTJSC/JSLock#unlock(d2cb180e190a9680).(ExecStatecxx . . $ QTJSC/ExecState#*); |
| 84 | |
| 85 | static intptr_tcxx . . $ intptr_t# lockCountcxx . . $ QTJSC/JSLock#lockCount(da6335ded91d79c2).(); |
| 86 | static bool currentThreadIsHoldingLockcxx . . $ QTJSC/JSLock#currentThreadIsHoldingLock(c9857a73d68e59ba).(); |
| 87 | |
| 88 | JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior# m_lockBehaviorcxx . . $ QTJSC/JSLock#m_lockBehavior.; |
| 89 | |
| 90 | class DropAllLockscxx . . $ QTJSC/JSLock#DropAllLocks# : public Noncopyablecxx . . $ WTFNoncopyable/Noncopyable# { |
| 91 | public: |
| 92 | DropAllLockscxx . . $ QTJSC/JSLock#DropAllLocks#DropAllLocks(d2cb180e190a9680).(ExecStatecxx . . $ QTJSC/ExecState#* exec); |
| 93 | DropAllLockscxx . . $ QTJSC/JSLock#DropAllLocks#DropAllLocks(a237af5886395a97).(JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior#); |
| 94 | ~cxx . . $ QTJSC/JSLock#DropAllLocks#`~DropAllLocks`(49f6e7a06ebc5aa8).DropAllLockscxx . . $ QTJSC/JSLock#DropAllLocks#(); |
| 95 | |
| 96 | private: |
| 97 | intptr_tcxx . . $ intptr_t# m_lockCountcxx . . $ QTJSC/JSLock#DropAllLocks#m_lockCount.; |
| 98 | JSLockBehaviorcxx . . $ QTJSC/JSLockBehavior# m_lockBehaviorcxx . . $ QTJSC/JSLock#DropAllLocks#m_lockBehavior.; |
| 99 | }; |
| 100 | }; |
| 101 | |
| 102 | } // namespace |
| 103 | |
| 104 | #endif // JSLock_h |