Fixed server

This commit is contained in:
Dmitry Kychanov 2024-10-05 02:47:02 +04:00
parent 98eab49e99
commit b171906162
4 changed files with 32 additions and 4 deletions

View file

@ -99,8 +99,8 @@ public:
protected:
std::string host;
unsigned short port_num;
bool server_online;
bool server_listening;
std::atomic<bool> server_online;
std::atomic<bool> server_listening;
std::vector<RGBController *>& controllers;

View file

@ -86,6 +86,7 @@ ResourceManager::ResourceManager()
InitThread = nullptr;
DetectDevicesThread = nullptr;
dynamic_detectors_processed = false;
init_finished = false;
SetupConfigurationDirectory();
@ -1632,6 +1633,8 @@ void ResourceManager::InitThreadFunction()
{
cli_post_detection();
}
init_finished = true;
}
void ResourceManager::UpdateDetectorSettings()
@ -1735,6 +1738,19 @@ void ResourceManager::UpdateDetectorSettings()
}
}
void ResourceManager::WaitForInitialization()
{
/*-------------------------------------------------*\
| A reliable sychronization of this kind is |
| impossible without the use of a `barrier` |
| implementation, which is only introduced in C++20 |
\*-------------------------------------------------*/
while (!init_finished)
{
std::this_thread::sleep_for(1ms);
};
}
void ResourceManager::WaitForDeviceDetection()
{
DetectDeviceMutex.lock();

View file

@ -208,6 +208,7 @@ public:
void StopDeviceDetection();
void WaitForInitialization();
void WaitForDeviceDetection();
private:
@ -243,6 +244,10 @@ private:
| Auto connection permitting flag |
\*-------------------------------------------------------------------------------------*/
bool apply_post_options;
/*-------------------------------------------------------------------------------------*\
| Initialization completion flag |
\*-------------------------------------------------------------------------------------*/
std::atomic<bool> init_finished;
/*-------------------------------------------------------------------------------------*\
| Profile Manager |

View file

@ -253,7 +253,14 @@ int main(int argc, char* argv[])
{
if(ret_flags & RET_FLAG_START_SERVER)
{
if(!ResourceManager::get()->GetServer()->GetOnline())
NetworkServer* server = ResourceManager::get()->GetServer();
ResourceManager::get()->WaitForInitialization();
/*---------------------------------------------------------*\
| The server is only started after detection finishes and |
| it takes some time to get the server online - we wait |
\*---------------------------------------------------------*/
if(!server->GetOnline())
{
#ifdef _MACOSX_X86_X64
CloseMacUSPCIODriver();
@ -262,7 +269,7 @@ int main(int argc, char* argv[])
}
else
{
WaitWhileServerOnline(ResourceManager::get()->GetServer());
WaitWhileServerOnline(server);
#ifdef _MACOSX_X86_X64
CloseMacUSPCIODriver();
#endif