- pthread_once(&createJSLockCountOnce, createJSLockCount);
-
- if (lockDropDepth++) {
- m_lockCount = 0;
- return;
- }
-
- m_lockCount = JSLock::lockCount();
- for (intptr_t i = 0; i < m_lockCount; i++)
- JSLock::unlock(m_lockBehavior);
+#if PLATFORM(IOS)
+ ASSERT_UNUSED(spinLock, spinLock.IsHeld());
+ // Check if this thread is currently holding the lock.
+ // FIXME: Maybe we want to require this, guard with an ASSERT?
+ unsigned lockCount = m_lockCount;
+ if (!lockCount || m_ownerThread != WTF::currentThread())
+ return 0;
+
+ // Don't drop the locks if they've already been dropped once.
+ // (If the prior drop came from another thread, and it resumed first,
+ // it could trash our register file).
+ if (m_lockDropDepth)
+ return 0;
+
+ // m_lockDropDepth is only incremented if any locks were dropped.
+ m_lockDropDepth++;
+ m_lockCount = 0;
+ m_lock.unlock();
+ return lockCount;
+#else
+ UNUSED_PARAM(spinLock);
+ if (m_lockDropDepth++)
+ return 0;
+
+ return dropAllLocksUnconditionally(spinLock);
+#endif