Branch data Line data Source code
1 : : #pragma once
2 : : #include "LmuSharedMemoryWrapper.h"
3 : :
4 : : // Wrapper for SharedMemoryLock that adds timeout support without modifying vendor code
5 : : // This avoids the maintenance burden of modifying the vendor's SharedMemoryInterface.hpp
6 : : class SafeSharedMemoryLock {
7 : : public:
8 : : // Factory method that returns a SafeSharedMemoryLock wrapper
9 : 12413 : static std::optional<SafeSharedMemoryLock> MakeSafeSharedMemoryLock() {
10 [ + - ]: 12413 : auto vendorLock = SharedMemoryLock::MakeSharedMemoryLock();
11 [ + + ]: 12413 : if (vendorLock.has_value()) {
12 [ + - + - ]: 12410 : return SafeSharedMemoryLock(std::move(vendorLock.value()));
13 : : }
14 : 3 : return std::nullopt;
15 : 12413 : }
16 : :
17 : : // Lock with timeout support - wraps the vendor's Lock() method
18 : : // Returns false if timeout expires or lock acquisition fails
19 : 9921 : bool Lock(DWORD timeout_ms = 50) {
20 : : // The vendor implementation already supports timeout parameter
21 : : // We just expose it through our wrapper
22 : 9921 : return m_vendorLock.Lock(timeout_ms);
23 : : }
24 : :
25 : 9920 : void Unlock() {
26 : 9920 : m_vendorLock.Unlock();
27 : 9920 : }
28 : :
29 : : // Move constructor and assignment to allow std::optional usage
30 : 24820 : SafeSharedMemoryLock(SafeSharedMemoryLock&& other) = default;
31 : 1 : SafeSharedMemoryLock& operator=(SafeSharedMemoryLock&& other) = default;
32 : :
33 : : private:
34 : : // Private constructor - use factory method
35 : 12410 : explicit SafeSharedMemoryLock(SharedMemoryLock&& vendorLock)
36 : 12410 : : m_vendorLock(std::move(vendorLock)) {}
37 : :
38 : : SharedMemoryLock m_vendorLock;
39 : : };
|