From 9ddc3635d6a04ff4b78611df00c905cc86e166ae Mon Sep 17 00:00:00 2001 From: Feyo Korenhof <35343640+feyokorenhof@users.noreply.github.com> Date: Wed, 26 May 2021 18:07:32 +0200 Subject: Implemented cServer::ScheduleTask() and cServer::TickQueuedTasks() (#5224) --- src/Server.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/Server.h') diff --git a/src/Server.h b/src/Server.h index 3d272d7c0..7701faa69 100644 --- a/src/Server.h +++ b/src/Server.h @@ -105,6 +105,9 @@ public: The command's output will be written to the a_Output callback. */ void QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); + /** Queues a lambda task onto the server tick thread, with the specified delay in ticks. */ + void ScheduleTask(cTickTime a_DelayTicks, std::function a_Task); + /** Lists all available console commands and their helpstrings */ void PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output); @@ -245,6 +248,18 @@ private: AStringVector m_Ports; + /** Time, in ticks, since the server started + Not persistent across server restarts */ + cTickTimeLong m_UpTime; + + /** Guards the m_Tasks */ + cCriticalSection m_CSTasks; + + /** Tasks that have been queued onto the tick thread, possibly to be + executed at target tick in the future; guarded by m_CSTasks */ + std::vector>> m_Tasks; + + cServer(void); /** Executes the console command, sends output through the specified callback. */ @@ -268,6 +283,11 @@ private: /** Executes commands queued in the command queue. */ void TickCommands(void); + + /** Executes all tasks queued onto the tick thread */ + void TickQueuedTasks(void); + + }; // tolua_export -- cgit v1.2.3