summaryrefslogtreecommitdiff
path: root/src/mbgl/util/thread_context.cpp
blob: 6742d5e75eca02f699f2ad60a91b713e8aea9b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <mbgl/util/thread_context.hpp>

namespace mbgl {
namespace util {

class MainThreadContextRegistrar {
public:
    MainThreadContextRegistrar() : context("Main", ThreadType::Main, ThreadPriority::Regular) {
        ThreadContext::current.set(&context);
    }

    ~MainThreadContextRegistrar() {
        ThreadContext::current.set(nullptr);
    }

private:
    ThreadContext context;
};

ThreadContext::ThreadContext(const std::string& name_, ThreadType type_, ThreadPriority priority_)
    : name(name_),
      type(type_),
      priority(priority_) {
}

uv::tls<ThreadContext> ThreadContext::current;

// Will auto register the main thread context
// at startup. Must be instantiated after the
// ThreadContext::current object.
MainThreadContextRegistrar registrar;

}
}