Get an object from the cache
| 69 | |
| 70 | // Get an object from the cache |
| 71 | Process* ProcessResolver::getObject(DWORD id) { |
| 72 | { |
| 73 | std::lock_guard<std::mutex> lock(cache_mutex); |
| 74 | auto it = cache.find(id); |
| 75 | if (it != cache.end()) { |
| 76 | return &it->second; // Return a pointer to the object |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Does not exist, create and add to cache |
| 81 | Process* process = MakeProcess(id, targetProcessNames); |
| 82 | if (process == nullptr) { |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
| 86 | { |
| 87 | std::lock_guard<std::mutex> lock(cache_mutex); |
| 88 | cache[id] = *process; |
| 89 | } |
| 90 | |
| 91 | // Clean up the temporary process object |
| 92 | delete process; |
| 93 | |
| 94 | { |
| 95 | std::lock_guard<std::mutex> lock(cache_mutex); |
| 96 | return &cache[id]; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Remove an object from the cache |
| 101 | void ProcessResolver::removeObject(DWORD id) { |