| 55 | |
| 56 | template<typename T, typename M = std::mutex> |
| 57 | class Synchronized |
| 58 | { |
| 59 | public: |
| 60 | template <typename... Args> |
| 61 | Synchronized(Args&&... args) : contents(std::forward<Args>(args)...) {} |
| 62 | |
| 63 | struct Locker |
| 64 | { |
| 65 | T* operator->() { return &contents; } |
| 66 | std::unique_lock<M> lock; |
| 67 | T& contents; |
| 68 | }; |
| 69 | |
| 70 | Locker Acquire() { return { std::unique_lock(m), contents }; } |
| 71 | Locker operator->() { return Acquire(); } |
| 72 | T Copy() { return Acquire().contents; } |
| 73 | |
| 74 | private: |
| 75 | T contents; |
| 76 | M m; |
| 77 | }; |
| 78 | |
| 79 | template <typename F> |
| 80 | void SpawnThread(const F& f) // works in DllMain unlike std thread |
nothing calls this directly
no outgoing calls
no test coverage detected