Chromium Code Reviews| Index: src/assert-scope.h |
| diff --git a/src/assert-scope.h b/src/assert-scope.h |
| index e2ec542a7708230af2bee1fc4f4840218afd967e..6f264a04c3af9bc8873bdd5fb7441297e329faa4 100644 |
| --- a/src/assert-scope.h |
| +++ b/src/assert-scope.h |
| @@ -78,8 +78,10 @@ class PerThreadAssertScopeBase { |
| #ifdef DEBUG |
| protected: |
| + enum AcquireAssertDataMode { CREATE_IF_ABSENT, NULL_IF_ABSENT }; |
|
Sven Panne
2013/06/12 06:57:37
This is getting a little bit confusing... I think
|
| + |
| PerThreadAssertScopeBase() { |
| - data_ = AssertData(); |
| + data_ = AssertData(CREATE_IF_ABSENT); |
| data_->increment_level(); |
| } |
| @@ -92,10 +94,10 @@ class PerThreadAssertScopeBase { |
| Thread::SetThreadLocal(thread_local_key, NULL); |
| } |
| - static PerThreadAssertData* AssertData() { |
| + static PerThreadAssertData* AssertData(AcquireAssertDataMode mode) { |
| PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>( |
| Thread::GetThreadLocal(thread_local_key)); |
| - if (data == NULL) { |
| + if (data == NULL && mode == CREATE_IF_ABSENT) { |
| data = new PerThreadAssertData(); |
| Thread::SetThreadLocal(thread_local_key, data); |
| } |
| @@ -124,7 +126,10 @@ class PerThreadAssertScope : public PerThreadAssertScopeBase { |
| ~PerThreadAssertScope() { data_->set(type, old_state_); } |
| - static bool IsAllowed() { return AssertData()->get(type); } |
| + static bool IsAllowed() { |
| + PerThreadAssertData* data = AssertData(NULL_IF_ABSENT); |
| + return data == NULL || data->get(type); |
| + } |
| private: |
| bool old_state_; |