Chromium Code Reviews| Index: src/assert-scope.h |
| diff --git a/src/assert-scope.h b/src/assert-scope.h |
| index e2ec542a7708230af2bee1fc4f4840218afd967e..501859182eee10c21b22f59608fbb6bcab875ef7 100644 |
| --- a/src/assert-scope.h |
| +++ b/src/assert-scope.h |
| @@ -78,8 +78,14 @@ class PerThreadAssertScopeBase { |
| #ifdef DEBUG |
| protected: |
| + enum AcquireAssertDataMode { CREATE_IF_ABSENT, NULL_IF_ABSENT }; |
|
Sven Panne
2013/06/12 09:41:17
Nuke this.
|
| + |
| PerThreadAssertScopeBase() { |
| - data_ = AssertData(); |
| + data_ = GetAssertData(); |
| + if (data_ == NULL) { |
| + data_ = new PerThreadAssertData(); |
| + Thread::SetThreadLocal(thread_local_key, data_); |
|
Sven Panne
2013/06/12 09:41:17
Put the TLS write into a private method and use it
|
| + } |
| data_->increment_level(); |
| } |
| @@ -92,14 +98,9 @@ class PerThreadAssertScopeBase { |
| Thread::SetThreadLocal(thread_local_key, NULL); |
|
Sven Panne
2013/06/12 09:41:17
... and here.
|
| } |
| - static PerThreadAssertData* AssertData() { |
| - PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>( |
| - Thread::GetThreadLocal(thread_local_key)); |
| - if (data == NULL) { |
| - data = new PerThreadAssertData(); |
| - Thread::SetThreadLocal(thread_local_key, data); |
| - } |
| - return data; |
| + static PerThreadAssertData* GetAssertData() { |
| + return reinterpret_cast<PerThreadAssertData*>( |
| + Thread::GetThreadLocal(thread_local_key)); |
| } |
| static Thread::LocalStorageKey thread_local_key; |
| @@ -124,7 +125,10 @@ class PerThreadAssertScope : public PerThreadAssertScopeBase { |
| ~PerThreadAssertScope() { data_->set(type, old_state_); } |
| - static bool IsAllowed() { return AssertData()->get(type); } |
| + static bool IsAllowed() { |
| + PerThreadAssertData* data = GetAssertData(); |
| + return data == NULL || data->get(type); |
| + } |
| private: |
| bool old_state_; |