Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Introduce Scheduler::GetSequenced() API #15985

Merged
merged 1 commit into from
Nov 28, 2019

Conversation

pozdnyakov
Copy link
Contributor

@pozdnyakov pozdnyakov commented Nov 27, 2019

The newly introduced Scheduler::GetSequenced() returns sequenced schedulers from the cache limited to 10 instances, preventing from spawning too many threads.

Required for #15953 (comment)

@pozdnyakov pozdnyakov added the Core The cross-platform C++ core, aka mbgl label Nov 27, 2019
@pozdnyakov pozdnyakov self-assigned this Nov 27, 2019
static std::mutex mtx;
static std::size_t lastUsedIndex = 0u;

if (++lastUsedIndex == kSchedulersCount) lastUsedIndex = 0u;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not thread safe, should be after the lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the catch!

@@ -41,4 +41,30 @@ std::shared_ptr<Scheduler> Scheduler::GetBackground() {
return scheduler;
}

// static
std::shared_ptr<Scheduler> Scheduler::GetSequenced() {
const std::size_t kSchedulersCount = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just an upper bound for the possible amount of threads, can be any other number.

The newly introduced `Scheduler::GetSequenced()` returns
sequenced schedulers from the cache limited to 10 instances,
preventing from spawning too many threads.
@pozdnyakov pozdnyakov force-pushed the mikhail_scheduler_get_sequenced branch from 1404709 to bbda46d Compare November 28, 2019 09:48
@pozdnyakov pozdnyakov merged commit b579473 into master Nov 28, 2019
@pozdnyakov pozdnyakov deleted the mikhail_scheduler_get_sequenced branch November 28, 2019 12:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants