fix(player-db): restore old on-demand thread creation behavior. (#2167)

Fixes #2160
This commit is contained in:
Quentin
2023-09-21 20:08:23 +02:00
committed by GitHub
parent 639d776267
commit 92b6df7653
2 changed files with 29 additions and 14 deletions

View File

@ -273,26 +273,39 @@ namespace big
void player_database_service::start_update_loop()
{
// So that it doesnt immediately exit the first time.
static bool first_time = true;
if (!g.player_db.update_player_online_states)
{
first_time = false;
return;
}
g_thread_pool->push([this] {
while (!g_running)
std::this_thread::yield();
if (first_time)
{
while (!g_running)
{
std::this_thread::yield();
}
first_time = false;
}
static auto last_update = std::chrono::high_resolution_clock::now() - 45s;
while (g_running)
while (g_running && g.player_db.update_player_online_states)
{
if (g.player_db.update_player_online_states)
const auto cur = std::chrono::high_resolution_clock::now();
if (cur - last_update > 45s && !updating)
{
const auto cur = std::chrono::high_resolution_clock::now();
if (cur - last_update > 45s && !updating)
{
updating = true;
g_fiber_pool->queue_job([this] {
update_player_states(true);
updating = false;
last_update = std::chrono::high_resolution_clock::now();
});
}
updating = true;
g_fiber_pool->queue_job([this] {
update_player_states(true);
updating = false;
last_update = std::chrono::high_resolution_clock::now();
});
}
std::this_thread::sleep_for(1s);
@ -329,6 +342,7 @@ namespace big
{
rage::rlScTaskStatus status{};
// TODO: big sized object on the stack, might be a problem in the future
rage::rlQueryPresenceAttributesContext contexts[bucket_size][9]{};
rage::rlQueryPresenceAttributesContext* contexts_per_player[bucket_size]{};