fix event loop timing issue

The event loop tries to run no faster than every 10ms. If it detects
that it goes faster, it would incorrectly calculate the difference, and
then wait (what I assume was) way too long or too short.
Either way, now it's fixed and it correctly works, even when introducing
new lua states.
This commit is contained in:
Lion Kortlepel
2022-07-20 14:31:32 +02:00
parent 6a94060970
commit fd7b11f436
14 changed files with 71 additions and 51 deletions

View File

@@ -12,6 +12,7 @@ extern TSentry Sentry;
#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <sstream>
#include <zlib.h>
@@ -96,6 +97,8 @@ public:
static void CheckForUpdates();
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
static bool IsOutdated(const Version& Current, const Version& Newest);
static bool IsShuttingDown();
static void SleepSafeSeconds(size_t Seconds);
static void InitializeConsole() {
if (!mConsole) {
@@ -121,10 +124,14 @@ public:
static void SetSubsystemStatus(const std::string& Subsystem, Status status);
private:
static void SetShutdown(bool Val);
static inline SystemStatusMap mSystemStatusMap {};
static inline std::mutex mSystemStatusMapMutex {};
static inline std::string mPPS;
static inline std::unique_ptr<TConsole> mConsole;
static inline std::shared_mutex mShutdownMtx {};
static inline bool mShutdown { false };
static inline std::mutex mShutdownHandlersMutex {};
static inline std::deque<TShutdownHandler> mShutdownHandlers {};

View File

@@ -15,7 +15,6 @@ private:
std::string GenerateCall();
std::string GetPlayers();
bool mShutdown = false;
TResourceManager& mResourceManager;
TServer& mServer;
};

View File

@@ -187,7 +187,7 @@ private:
class StateThreadData : IThreaded {
public:
StateThreadData(const std::string& Name, std::atomic_bool& Shutdown, TLuaStateId StateId, TLuaEngine& Engine);
StateThreadData(const std::string& Name, TLuaStateId StateId, TLuaEngine& Engine);
StateThreadData(const StateThreadData&) = delete;
~StateThreadData() noexcept { beammp_debug("\"" + mStateId + "\" destroyed"); }
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(const TLuaChunk& Script);
@@ -218,7 +218,6 @@ private:
sol::table Lua_FS_ListDirectories(const std::string& Path);
std::string mName;
std::atomic_bool& mShutdown;
TLuaStateId mStateId;
lua_State* mState;
std::thread mThread;
@@ -247,8 +246,7 @@ private:
TNetwork* mNetwork;
TServer* mServer;
std::atomic_bool mShutdown { false };
fs::path mResourceServerPath;
const fs::path mResourceServerPath;
std::vector<std::shared_ptr<TLuaPlugin>> mLuaPlugins;
std::unordered_map<TLuaStateId, std::unique_ptr<StateThreadData>> mLuaStates;
std::recursive_mutex mLuaStatesMutex;

View File

@@ -32,7 +32,6 @@ private:
TServer& mServer;
TPPSMonitor& mPPSMonitor;
SOCKET mUDPSock {};
bool mShutdown { false };
TResourceManager& mResourceManager;
std::thread mUDPThread;
std::thread mTCPThread;

View File

@@ -22,6 +22,5 @@ private:
TServer& mServer;
std::optional<std::reference_wrapper<TNetwork>> mNetwork { std::nullopt };
bool mShutdown { false };
int mInternalPPS { 0 };
};
};

View File

@@ -18,6 +18,5 @@ public:
private:
std::shared_ptr<TLuaEngine> mEngine;
fs::path mPath;
std::atomic_bool mShutdown { false };
std::unordered_map<std::string, fs::file_time_type> mFileTimes;
};