tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testThreadingMutex.cpp (1466B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #include "jsapi-tests/tests.h"
      9 #include "threading/LockGuard.h"
     10 #include "vm/MutexIDs.h"
     11 
     12 #ifdef DEBUG
     13 #  define DEBUG_CHECK(x) CHECK(x)
     14 #else
     15 #  define DEBUG_CHECK(x)
     16 #endif
     17 
     18 BEGIN_TEST(testThreadingMutex) {
     19  js::Mutex mutex MOZ_UNANNOTATED(js::mutexid::TestMutex);
     20  DEBUG_CHECK(!mutex.isOwnedByCurrentThread());
     21  mutex.lock();
     22  DEBUG_CHECK(mutex.isOwnedByCurrentThread());
     23  mutex.unlock();
     24  DEBUG_CHECK(!mutex.isOwnedByCurrentThread());
     25  return true;
     26 }
     27 END_TEST(testThreadingMutex)
     28 
     29 BEGIN_TEST(testThreadingLockGuard) {
     30  js::Mutex mutex MOZ_UNANNOTATED(js::mutexid::TestMutex);
     31  DEBUG_CHECK(!mutex.isOwnedByCurrentThread());
     32  js::LockGuard guard(mutex);
     33  DEBUG_CHECK(mutex.isOwnedByCurrentThread());
     34  return true;
     35 }
     36 END_TEST(testThreadingLockGuard)
     37 
     38 BEGIN_TEST(testThreadingUnlockGuard) {
     39  js::Mutex mutex MOZ_UNANNOTATED(js::mutexid::TestMutex);
     40  DEBUG_CHECK(!mutex.isOwnedByCurrentThread());
     41  js::LockGuard guard(mutex);
     42  DEBUG_CHECK(mutex.isOwnedByCurrentThread());
     43  js::UnlockGuard unguard(guard);
     44  DEBUG_CHECK(!mutex.isOwnedByCurrentThread());
     45  return true;
     46 }
     47 END_TEST(testThreadingUnlockGuard)
     48 
     49 #undef DEBUG_CHECK