diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-01-26 18:32:46 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-01-26 18:32:46 +0900 |
| commit | 6ca9cfe313bafd3f2ef8278140d2a8fe3ee67de3 (patch) | |
| tree | e48e83a79df7038ffaa9e118dde7da0c04311759 | |
| parent | c8154bde8758d1ffdd0ffdbdeac7ac9daa1a09ff (diff) | |
| download | platform_build_kati-6ca9cfe313bafd3f2ef8278140d2a8fe3ee67de3.tar.gz platform_build_kati-6ca9cfe313bafd3f2ef8278140d2a8fe3ee67de3.tar.bz2 platform_build_kati-6ca9cfe313bafd3f2ef8278140d2a8fe3ee67de3.zip | |
[C++] Use thraed_local keyword on linux again
The previous code crashed in Android tree.
| -rw-r--r-- | stats.cc | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -29,7 +29,13 @@ namespace { mutex g_mu; vector<Stats*>* g_stats; +#ifdef __linux__ +thread_local double g_start_time; +#define REF(x) x +#else DEFINE_THREAD_LOCAL(double, g_start_time); +#define REF(x) x.Ref() +#endif } // namespace @@ -47,16 +53,16 @@ string Stats::String() const { } void Stats::Start() { - CHECK(!g_start_time.Ref()); - g_start_time.Ref() = GetTime(); + CHECK(!REF(g_start_time)); + REF(g_start_time) = GetTime(); unique_lock<mutex> lock(mu_); cnt_++; } double Stats::End() { - CHECK(g_start_time.Ref()); - double e = GetTime() - g_start_time.Ref(); - g_start_time.Ref() = 0; + CHECK(REF(g_start_time)); + double e = GetTime() - REF(g_start_time); + REF(g_start_time) = 0; unique_lock<mutex> lock(mu_); elapsed_ += e; return e; |
