fix(player-db): restore old on-demand thread creation behavior. (#2167)
Fixes #2160
This commit is contained in:
parent
639d776267
commit
92b6df7653
@ -273,26 +273,39 @@ namespace big
|
|||||||
|
|
||||||
void player_database_service::start_update_loop()
|
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] {
|
g_thread_pool->push([this] {
|
||||||
while (!g_running)
|
if (first_time)
|
||||||
std::this_thread::yield();
|
{
|
||||||
|
while (!g_running)
|
||||||
|
{
|
||||||
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
first_time = false;
|
||||||
|
}
|
||||||
|
|
||||||
static auto last_update = std::chrono::high_resolution_clock::now() - 45s;
|
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();
|
updating = true;
|
||||||
if (cur - last_update > 45s && !updating)
|
g_fiber_pool->queue_job([this] {
|
||||||
{
|
update_player_states(true);
|
||||||
updating = true;
|
updating = false;
|
||||||
g_fiber_pool->queue_job([this] {
|
last_update = std::chrono::high_resolution_clock::now();
|
||||||
update_player_states(true);
|
});
|
||||||
updating = false;
|
|
||||||
last_update = std::chrono::high_resolution_clock::now();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::sleep_for(1s);
|
std::this_thread::sleep_for(1s);
|
||||||
@ -329,6 +342,7 @@ namespace big
|
|||||||
{
|
{
|
||||||
rage::rlScTaskStatus status{};
|
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[bucket_size][9]{};
|
||||||
rage::rlQueryPresenceAttributesContext* contexts_per_player[bucket_size]{};
|
rage::rlQueryPresenceAttributesContext* contexts_per_player[bucket_size]{};
|
||||||
|
|
||||||
|
@ -300,6 +300,7 @@ namespace big
|
|||||||
{
|
{
|
||||||
if (components::command_checkbox<"player_db_auto_update_states">("Enable"))
|
if (components::command_checkbox<"player_db_auto_update_states">("Enable"))
|
||||||
g_player_database_service->start_update_loop();
|
g_player_database_service->start_update_loop();
|
||||||
|
|
||||||
ImGui::Checkbox("Notify When Online", &g.player_db.notify_when_online);
|
ImGui::Checkbox("Notify When Online", &g.player_db.notify_when_online);
|
||||||
ImGui::Checkbox("Notify When Joinable", &g.player_db.notify_when_joinable);
|
ImGui::Checkbox("Notify When Joinable", &g.player_db.notify_when_joinable);
|
||||||
ImGui::Checkbox("Notify When Unjoinable", &g.player_db.notify_when_unjoinable);
|
ImGui::Checkbox("Notify When Unjoinable", &g.player_db.notify_when_unjoinable);
|
||||||
|
Reference in New Issue
Block a user