Only run background thread if runcallbacks has been called more than 1 seconds ago.

This commit is contained in:
Mr_Goldberg 2020-02-14 15:01:10 -05:00
parent 8cdf5cee26
commit 6f4273bf3a
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
2 changed files with 12 additions and 6 deletions

View File

@ -36,11 +36,15 @@ static void background_thread(Steam_Client *client)
} }
} }
global_mutex.lock(); unsigned long long time = std::chrono::duration_cast<std::chrono::duration<unsigned long long>>(std::chrono::system_clock::now().time_since_epoch()).count();
PRINT_DEBUG("background thread run\n");
client->network->Run(); if (time > client->last_cb_run + 1) {
client->steam_matchmaking->RunBackground(); global_mutex.lock();
global_mutex.unlock(); PRINT_DEBUG("background thread run\n");
client->network->Run();
client->steam_matchmaking->RunBackground();
global_mutex.unlock();
}
} }
} }
@ -104,6 +108,7 @@ Steam_Client::Steam_Client()
steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb); steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb); steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
last_cb_run = 0;
PRINT_DEBUG("client init end\n"); PRINT_DEBUG("client init end\n");
} }
@ -1536,8 +1541,8 @@ void Steam_Client::RunCallbacks(bool runClientCB, bool runGameserverCB)
callbacks_server->runCallBacks(); callbacks_server->runCallBacks();
PRINT_DEBUG("Steam_Client::RunCallbacks callbacks_client\n"); PRINT_DEBUG("Steam_Client::RunCallbacks callbacks_client\n");
callbacks_client->runCallBacks(); callbacks_client->runCallBacks();
last_cb_run = std::chrono::duration_cast<std::chrono::duration<unsigned long long>>(std::chrono::system_clock::now().time_since_epoch()).count();
PRINT_DEBUG("Steam_Client::RunCallbacks done\n"); PRINT_DEBUG("Steam_Client::RunCallbacks done\n");
} }
void Steam_Client::DestroyAllInterfaces() void Steam_Client::DestroyAllInterfaces()

View File

@ -135,6 +135,7 @@ public:
bool server_init = false; bool server_init = false;
std::thread background_keepalive; std::thread background_keepalive;
bool steamclient_server_inited = false; bool steamclient_server_inited = false;
std::atomic<unsigned long long> last_cb_run;
unsigned steam_pipe_counter = 1; unsigned steam_pipe_counter = 1;
std::map<HSteamPipe, enum Steam_Pipe> steam_pipes; std::map<HSteamPipe, enum Steam_Pipe> steam_pipes;