mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Why not `thread_local`?

Open bylee20 opened this issue 4 years ago • 0 comments

The ThreadLocal<T> class depends on each platform's implementation of ThreadLocalBase. As far as I can tell, mapbox-gl-native already requires C++11 everywhere, and in C++11, TLS is already supported by thread_local keyword.

For instance, one can replace,

mbgl::util::ThreadLocal<mbgl::gfx::BackendScope>& currentScope() {
    static mbgl::util::ThreadLocal<mbgl::gfx::BackendScope> backendScope;
    return backendScope;
}

... = currentScope().get();
currentScope().set(...);

with

mbgl::gfx::BackendScope*& currentScope() {
    thread_local mbgl::gfx::BackendScope* backendScope = nullptr;
    return backendScope;
}

... = currentScope();
currentScope() = ...;

Is there any reason to keep the platform dependent implementation? Or, is it just a legacy? May I make a PR to drop ThreadLocal<T> usage?

bylee20 avatar May 06 '21 17:05 bylee20