-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransferContext.cpp
More file actions
41 lines (32 loc) · 1.03 KB
/
TransferContext.cpp
File metadata and controls
41 lines (32 loc) · 1.03 KB
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
#include <TransferContext.h>
struct CfTransferKeyLess
{
bool operator()(const CF_TRANSFER_KEY &a, const CF_TRANSFER_KEY &b) const
{
return a.QuadPart < b.QuadPart;
}
};
static std::map<CF_TRANSFER_KEY, std::shared_ptr<TransferContext>, CfTransferKeyLess> g_transferContextMap;
static std::mutex g_contextMapMutex;
std::shared_ptr<TransferContext> CreateTransferContext(CF_TRANSFER_KEY transferKey)
{
auto ctx = std::make_shared<TransferContext>();
ctx->transferKey = transferKey;
std::scoped_lock lock(g_contextMapMutex);
g_transferContextMap[transferKey] = ctx;
return ctx;
}
std::shared_ptr<TransferContext> GetTransferContext(CF_TRANSFER_KEY transferKey)
{
std::scoped_lock lock(g_contextMapMutex);
if (auto it = g_transferContextMap.find(transferKey); it != g_transferContextMap.end())
{
return it->second;
}
return nullptr;
}
void RemoveTransferContext(CF_TRANSFER_KEY transferKey)
{
std::scoped_lock lock(g_contextMapMutex);
g_transferContextMap.erase(transferKey);
}