tor-browser

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

ThreadLocal.h (2453B)


      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 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_indexeddb_threadlocal_h__
      8 #define mozilla_dom_indexeddb_threadlocal_h__
      9 
     10 #include "IDBTransaction.h"
     11 #include "ProfilerHelpers.h"
     12 #include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 class IDBFactory;
     17 
     18 namespace indexedDB {
     19 
     20 class ThreadLocal {
     21  friend DefaultDelete<ThreadLocal>;
     22  friend IDBFactory;
     23 
     24  LoggingInfo mLoggingInfo;
     25  Maybe<IDBTransaction&> mCurrentTransaction;
     26  LoggingIdString<false> mLoggingIdString;
     27 
     28  NS_DECL_OWNINGTHREAD
     29 
     30 public:
     31  ThreadLocal() = delete;
     32  ThreadLocal(const ThreadLocal& aOther) = delete;
     33 
     34  void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(ThreadLocal); }
     35 
     36  const LoggingInfo& GetLoggingInfo() const {
     37    AssertIsOnOwningThread();
     38 
     39    return mLoggingInfo;
     40  }
     41 
     42  const nsID& Id() const {
     43    AssertIsOnOwningThread();
     44 
     45    return mLoggingInfo.backgroundChildLoggingId();
     46  }
     47 
     48  const nsCString& IdString() const {
     49    AssertIsOnOwningThread();
     50 
     51    return mLoggingIdString;
     52  }
     53 
     54  int64_t NextTransactionSN(IDBTransaction::Mode aMode) {
     55    AssertIsOnOwningThread();
     56    MOZ_ASSERT(mLoggingInfo.nextTransactionSerialNumber() < INT64_MAX);
     57    MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
     58               INT64_MIN);
     59 
     60    if (aMode == IDBTransaction::Mode::VersionChange) {
     61      return mLoggingInfo.nextVersionChangeTransactionSerialNumber()--;
     62    }
     63 
     64    return mLoggingInfo.nextTransactionSerialNumber()++;
     65  }
     66 
     67  uint64_t NextRequestSN() {
     68    AssertIsOnOwningThread();
     69    MOZ_ASSERT(mLoggingInfo.nextRequestSerialNumber() < UINT64_MAX);
     70 
     71    return mLoggingInfo.nextRequestSerialNumber()++;
     72  }
     73 
     74  void SetCurrentTransaction(Maybe<IDBTransaction&> aCurrentTransaction) {
     75    AssertIsOnOwningThread();
     76 
     77    mCurrentTransaction = aCurrentTransaction;
     78  }
     79 
     80  Maybe<IDBTransaction&> MaybeCurrentTransactionRef() const {
     81    AssertIsOnOwningThread();
     82 
     83    return mCurrentTransaction;
     84  }
     85 
     86 private:
     87  explicit ThreadLocal(const nsID& aBackgroundChildLoggingId);
     88  ~ThreadLocal();
     89 };
     90 
     91 }  // namespace indexedDB
     92 }  // namespace mozilla::dom
     93 
     94 #endif  // mozilla_dom_indexeddb_threadlocal_h__