Plasma Engine  2.0
Loading...
Searching...
No Matches
MessageLoop.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Configuration/Singleton.h>
5#include <Foundation/Configuration/Startup.h>
6#include <Foundation/Containers/Deque.h>
7#include <Foundation/Threading/Mutex.h>
8#include <Foundation/Threading/Thread.h>
9
11class plIpcChannel;
12class plLoopThread;
13
19class PL_FOUNDATION_DLL plMessageLoop
20{
21 PL_DECLARE_SINGLETON(plMessageLoop);
22
23public:
25 virtual ~plMessageLoop() = default;
26 ;
27
29 void AddChannel(plIpcChannel* pChannel);
30
31 void RemoveChannel(plIpcChannel* pChannel);
32
33protected:
34 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, MessageLoop);
35 friend class plLoopThread;
36 friend class plIpcChannel;
37
38 void StartUpdateThread();
39 void StopUpdateThread();
40 void RunLoop();
41 bool ProcessTasks();
42 void Quit();
43
45 virtual void WakeUp() = 0;
50 virtual bool WaitForMessages(plInt32 iTimeout, plIpcChannel* pFilter) = 0;
51
52 plThreadID m_ThreadId = 0;
53 mutable plMutex m_Mutex;
54 bool m_bShouldQuit = false;
55 bool m_bCallTickFunction = false;
56 class plLoopThread* m_pUpdateThread = nullptr;
57
58 plMutex m_TasksMutex;
59 plDynamicArray<plIpcChannel*> m_ConnectQueue;
60 plDynamicArray<plIpcChannel*> m_DisconnectQueue;
62
63 // Thread local copies of the different queues for the ProcessTasks method
64 plDynamicArray<plIpcChannel*> m_ConnectQueueTask;
65 plDynamicArray<plIpcChannel*> m_DisconnectQueueTask;
66 plDynamicArray<plIpcChannel*> m_SendQueueTask;
67
68 plDynamicArray<plIpcChannel*> m_AllAddedChannels;
69};
Definition DynamicArray.h:81
Base class for a communication channel between processes.
Definition IpcChannel.h:44
Internal sub-system used by plIpcChannel.
Definition MessageLoop.h:20
virtual bool WaitForMessages(plInt32 iTimeout, plIpcChannel *pFilter)=0
Waits until a new message has been processed (sent, received).
virtual void WakeUp()=0
Wake up the message loop when new work comes in.
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Base class for IPC messages transmitted by plIpcChannel.
Definition RemoteMessage.h:64