diff options
| author | Stefan Boberg <[email protected]> | 2021-09-16 21:04:35 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-16 21:04:35 +0200 |
| commit | 4b1b3edc21acf3b19649a85e49a57464bf169314 (patch) | |
| tree | 4a2ccf74343c57d8c3698efb8d76bf549227da08 /zencore/include | |
| parent | Minor CbPackage serialization tweaks (diff) | |
| download | zen-4b1b3edc21acf3b19649a85e49a57464bf169314.tar.xz zen-4b1b3edc21acf3b19649a85e49a57464bf169314.zip | |
Added ProcessMonitor class, which is used to monitor a number of sponsor processes, to control Zen instance lifetime
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/thread.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/zencore/include/zencore/thread.h b/zencore/include/zencore/thread.h index b18da6031..0e34d6518 100644 --- a/zencore/include/zencore/thread.h +++ b/zencore/include/zencore/thread.h @@ -8,6 +8,8 @@ # include <shared_mutex> #endif +#include <vector> + namespace zen { /** @@ -93,6 +95,7 @@ public: ZENCORE_API void Set(); ZENCORE_API void Reset(); ZENCORE_API bool Wait(int TimeoutMs = -1); + ZENCORE_API void Close(); protected: explicit Event(void* EventHandle) : m_EventHandle(EventHandle) {} @@ -125,7 +128,7 @@ private: }; /** Basic process abstraction - */ + */ class ProcessHandle { public: @@ -150,6 +153,28 @@ private: int m_Pid = 0; }; +/** Process monitor - monitors a list of running processes via polling + + Intended to be used to monitor a set of "sponsor" processes, where + we need to determine when none of them remain alive + + */ + +class ProcessMonitor +{ +public: + ProcessMonitor(); + ~ProcessMonitor(); + + ZENCORE_API bool IsRunning(); + ZENCORE_API void AddPid(int Pid); + ZENCORE_API bool IsActive() const; + +private: + mutable RwLock m_Lock; + std::vector<void*> m_ProcessHandles; +}; + ZENCORE_API bool IsProcessRunning(int pid); ZENCORE_API int GetCurrentProcessId(); |