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"
22 friend class DefaultDelete
<ThreadLocal
>;
25 LoggingInfo mLoggingInfo
;
26 Maybe
<IDBTransaction
&> mCurrentTransaction
;
27 LoggingIdString
<false> mLoggingIdString
;
32 ThreadLocal() = delete;
33 ThreadLocal(const ThreadLocal
& aOther
) = delete;
35 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(ThreadLocal
); }
37 const LoggingInfo
& GetLoggingInfo() const {
38 AssertIsOnOwningThread();
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() >
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
;
88 explicit ThreadLocal(const nsID
& aBackgroundChildLoggingId
);
92 } // namespace indexedDB
94 } // namespace mozilla
96 #endif // mozilla_dom_indexeddb_threadlocal_h__