-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataScope.cpp
111 lines (95 loc) · 2.83 KB
/
DataScope.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//--------------------------------------------------------------------------------------
// File: DataScope.cpp
//
// Distributed as part of NVIDIA Nsight serialization output.
//
// Copyright (c) NVIDIA Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "DataScope.h"
#include "ReadOnlyDatabase.h"
namespace Serialization {
DataScope::DataScope(DataScopeTracker& tracker)
: m_Tracker(tracker)
, m_pParent()
, m_staticStorage{}
, m_dynamicStorage()
, m_pUsedPages(m_staticStorage)
, m_usedPageCount()
, m_pDatabase()
{
m_pParent = m_Tracker.m_pCurrentDataScope;
m_Tracker.m_pCurrentDataScope = this;
}
DataScope::~DataScope()
{
if (m_pDatabase) {
for (int i = 0; i < m_usedPageCount; ++i) {
m_pDatabase->Unlock(m_pUsedPages[i]);
}
}
m_Tracker.m_pCurrentDataScope = m_pParent;
}
void DataScope::SetUsesPage(PageId pageOffset, IReadOnlyDatabase& database)
{
auto pPageHandle = database.Lock(pageOffset);
if (!pPageHandle)
{
NV_DATABASE_WARN(!pPageHandle, "No page handle for the given page id.");
return;
}
if (m_usedPageCount < NUM_STATIC_IDS)
{
m_pUsedPages[m_usedPageCount] = pPageHandle;
}
else
{
if (m_usedPageCount == NUM_STATIC_IDS)
{
m_dynamicStorage.assign(m_staticStorage, m_staticStorage + NUM_STATIC_IDS);
}
m_dynamicStorage.push_back(pPageHandle);
m_pUsedPages = m_dynamicStorage.data();
}
++m_usedPageCount;
NV_DATABASE_WARN(!m_pDatabase || m_pDatabase == &database, "There should be a single database.");
m_pDatabase = &database;
}
#if defined(__arm__)
void DataScope::AddBlobProxy(std::shared_ptr<BlobProxyBase>& pBlobProxy)
{
m_blobProxyVec.push_back(pBlobProxy);
}
#endif
DataScopeTracker& DataScopeTracker::Instance()
{
static TLS_STORAGE DataScopeTracker* pTracker = nullptr;
DataScopeTracker* pLocal = pTracker;
if (!pLocal) {
pTracker = new DataScopeTracker();
return *pTracker;
}
return *pLocal;
}
void DataScopeTracker::SetUsesPage(uint64_t pageOffset, IReadOnlyDatabase& database)
{
if (!m_pCurrentDataScope)
{
return;
}
m_pCurrentDataScope->SetUsesPage(pageOffset, database);
}
#if defined(__arm__)
void DataScopeTracker::AddBlobProxyToCurrentDataScope(std::shared_ptr<BlobProxyBase>& pBlobProxy)
{
NV_DATABASE_WARN(m_pCurrentDataScope != nullptr, "No current data scope");
if (m_pCurrentDataScope != nullptr)
{
m_pCurrentDataScope->AddBlobProxy(pBlobProxy);
}
}
#endif
DataScopeTracker::DataScopeTracker()
: m_pCurrentDataScope()
{
}
} // namespace Serialization