MCPcopy Create free account
hub / github.com/Apache553/SubtitleFontHelper / QueryCache

Class QueryCache

FontLoadInterceptor/RpcClient.cpp:55–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 }
54
55 class QueryCache
56 {
57 private:
58 wil::unique_handle m_version;
59 wil::unique_mapview_ptr<uint32_t> m_versionMem;
60 uint32_t m_lastKnownVersion = std::numeric_limits<uint32_t>::max();
61 bool m_good = false;
62
63 std::unordered_set<std::wstring> m_cache;
64 std::mutex m_lock;
65
66 QueryCache()
67 {
68 try
69 {
70 std::wstring versionShmName = L"SubtitleFontAutoLoaderSHM-";
71 versionShmName += GetCurrentProcessUserSid();
72 m_version.reset(CreateFileMappingW(
73 INVALID_HANDLE_VALUE,
74 nullptr,
75 PAGE_READWRITE,
76 0, 4,
77 versionShmName.c_str()));
78 THROW_LAST_ERROR_IF(!m_version.is_valid());
79 m_versionMem.reset(static_cast<uint32_t*>(MapViewOfFile(
80 m_version.get(),
81 FILE_MAP_WRITE,
82 0, 0,
83 sizeof(uint32_t))));
84 THROW_LAST_ERROR_IF(m_versionMem.get() == nullptr);
85 }
86 catch (...)
87 {
88 }
89 m_good = true;
90 }
91
92 public:
93 static QueryCache& GetInstance()
94 {
95 static QueryCache instance;
96 return instance;
97 }
98
99 void CheckNewVerison()
100 {
101 uint32_t newVerison = InterlockedCompareExchange(m_versionMem.get(), 0, 0);
102 if (newVerison != m_lastKnownVersion)
103 {
104 m_lastKnownVersion = newVerison;
105 m_cache.clear();
106 }
107 }
108
109 bool IsQueryNeeded(const wchar_t* str)
110 {
111 if (!m_good)return true;
112 std::lock_guard lg(m_lock);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected