splited ASyncEvent

This commit is contained in:
2022-07-07 21:32:35 +08:00
parent 5a88a6072c
commit d3608bee15
7 changed files with 198 additions and 131 deletions

74
inc/hgl/event/EventProc.h Normal file
View File

@@ -0,0 +1,74 @@
#ifndef HGL_EVENT_PROC_INCLUDE
#define HGL_EVENT_PROC_INCLUDE
#include<hgl/type/Queue.h>
namespace hgl
{
/**
* <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
*/
class EventProc
{
public:
EventProc()=default;
virtual ~EventProc()=default;
virtual bool Proc()=0;
};//class EventProc
using EventProcQueue=Queue<EventProc *>;
/**
* ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD>
*/
inline bool UpdateEvent(EventProcQueue *epq)
{
if(!epq||epq->GetCount()<=0)
return(false);
EventProc *e;
if(epq->Pop(e))
{
e->Proc();
delete e;
return(true);
}
return(false);
}
/**
* ˢ<><CBA2>ִ<EFBFBD><D6B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
* @param epq <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
* @param max_count <20><><EFBFBD><EFBFBD>ˢ<EFBFBD>¸<EFBFBD><C2B8><EFBFBD>(-1<><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
*/
inline int UpdateEventQueue(EventProcQueue *epq,int max_count=-1)
{
if(!epq||epq->GetCount()<=0||max_count==0)
return(0);
int count=0;
EventProc *e;
while(epq->Pop(e))
{
if(e)
{
e->Proc();
delete e;
}
++count;
if(--max_count==0)
break;
}
return count;
}
}//namespace hgl
#endif//HGL_EVENT_PROC_INCLUDE