Bug 1671598 [wpt PR 26128] - [AspectRatio] Fix divide by zero with a small float...
[gecko.git] / dom / indexedDB / ThreadLocal.h
blob4d33546f695ed4a9f81ef14dc4368d731fafed1c
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/. */
7 #ifndef mozilla_dom_indexeddb_threadlocal_h__
8 #define mozilla_dom_indexeddb_threadlocal_h__
10 #include "IDBTransaction.h"
11 #include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
12 #include "ProfilerHelpers.h"
14 namespace mozilla {
15 namespace dom {
17 class IDBFactory;
19 namespace indexedDB {
21 class ThreadLocal {
22 friend class DefaultDelete<ThreadLocal>;
23 friend IDBFactory;
25 LoggingInfo mLoggingInfo;
26 Maybe<IDBTransaction&> mCurrentTransaction;
27 LoggingIdString<false> mLoggingIdString;
29 NS_DECL_OWNINGTHREAD
31 public:
32 ThreadLocal() = delete;
33 ThreadLocal(const ThreadLocal& aOther) = delete;
35 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(ThreadLocal); }
37 const LoggingInfo& GetLoggingInfo() const {
38 AssertIsOnOwningThread();
40 return mLoggingInfo;
43 const nsID& Id() const {
44 AssertIsOnOwningThread();
46 return mLoggingInfo.backgroundChildLoggingId();
49 const nsCString& IdString() const {
50 AssertIsOnOwningThread();
52 return mLoggingIdString;
55 int64_t NextTransactionSN(IDBTransaction::Mode aMode) {
56 AssertIsOnOwningThread();
57 MOZ_ASSERT(mLoggingInfo.nextTransactionSerialNumber() < INT64_MAX);
58 MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
59 INT64_MIN);
61 if (aMode == IDBTransaction::Mode::VersionChange) {
62 return mLoggingInfo.nextVersionChangeTransactionSerialNumber()--;
65 return mLoggingInfo.nextTransactionSerialNumber()++;
68 uint64_t NextRequestSN() {
69 AssertIsOnOwningThread();
70 MOZ_ASSERT(mLoggingInfo.nextRequestSerialNumber() < UINT64_MAX);
72 return mLoggingInfo.nextRequestSerialNumber()++;
75 void SetCurrentTransaction(Maybe<IDBTransaction&> aCurrentTransaction) {
76 AssertIsOnOwningThread();
78 mCurrentTransaction = aCurrentTransaction;
81 Maybe<IDBTransaction&> MaybeCurrentTransactionRef() const {
82 AssertIsOnOwningThread();
84 return mCurrentTransaction;
87 private:
88 explicit ThreadLocal(const nsID& aBackgroundChildLoggingId);
89 ~ThreadLocal();
92 } // namespace indexedDB
93 } // namespace dom
94 } // namespace mozilla
96 #endif // mozilla_dom_indexeddb_threadlocal_h__