Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: third_party/WebKit/Source/platform/wtf/ThreadSpecific.h

Issue 2919653004: Use LOG() or LOG_IF() instead of IMMEDIATE_CRASH (Closed)
Patch Set: Use LOG() or CHECK()|CHECK_FOO() instead of IMMEDIATE_CRASH Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Jian Li <jianli@chromium.org> 3 * Copyright (C) 2009 Jian Li <jianli@chromium.org>
4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> 4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 T* main_thread_storage_ = nullptr; 118 T* main_thread_storage_ = nullptr;
119 }; 119 };
120 120
121 #if OS(POSIX) 121 #if OS(POSIX)
122 122
123 typedef pthread_key_t ThreadSpecificKey; 123 typedef pthread_key_t ThreadSpecificKey;
124 124
125 inline void ThreadSpecificKeyCreate(ThreadSpecificKey* key, 125 inline void ThreadSpecificKeyCreate(ThreadSpecificKey* key,
126 void (*destructor)(void*)) { 126 void (*destructor)(void*)) {
127 int error = pthread_key_create(key, destructor); 127 int error = pthread_key_create(key, destructor);
128 if (error) 128 CHECK(!error);
129 IMMEDIATE_CRASH();
130 } 129 }
131 130
132 inline void ThreadSpecificKeyDelete(ThreadSpecificKey key) { 131 inline void ThreadSpecificKeyDelete(ThreadSpecificKey key) {
133 int error = pthread_key_delete(key); 132 int error = pthread_key_delete(key);
134 if (error) 133 CHECK(!error);
135 IMMEDIATE_CRASH();
136 } 134 }
137 135
138 inline void ThreadSpecificSet(ThreadSpecificKey key, void* value) { 136 inline void ThreadSpecificSet(ThreadSpecificKey key, void* value) {
139 pthread_setspecific(key, value); 137 pthread_setspecific(key, value);
140 } 138 }
141 139
142 inline void* ThreadSpecificGet(ThreadSpecificKey key) { 140 inline void* ThreadSpecificGet(ThreadSpecificKey key) {
143 return pthread_getspecific(key); 141 return pthread_getspecific(key);
144 } 142 }
145 143
146 template <typename T> 144 template <typename T>
147 inline ThreadSpecific<T>::ThreadSpecific() { 145 inline ThreadSpecific<T>::ThreadSpecific() {
148 int error = pthread_key_create(&key_, Destroy); 146 int error = pthread_key_create(&key_, Destroy);
149 if (error) 147 CHECK(!error);
150 IMMEDIATE_CRASH();
151 } 148 }
152 149
153 template <typename T> 150 template <typename T>
154 inline T* ThreadSpecific<T>::Get() { 151 inline T* ThreadSpecific<T>::Get() {
155 Data* data = static_cast<Data*>(pthread_getspecific(key_)); 152 Data* data = static_cast<Data*>(pthread_getspecific(key_));
156 return data ? data->value : 0; 153 return data ? data->value : 0;
157 } 154 }
158 155
159 template <typename T> 156 template <typename T>
160 inline void ThreadSpecific<T>::Set(T* ptr) { 157 inline void ThreadSpecific<T>::Set(T* ptr) {
(...skipping 23 matching lines...) Expand all
184 typedef PlatformThreadSpecificKey* ThreadSpecificKey; 181 typedef PlatformThreadSpecificKey* ThreadSpecificKey;
185 182
186 WTF_EXPORT void ThreadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void*)); 183 WTF_EXPORT void ThreadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void*));
187 WTF_EXPORT void ThreadSpecificKeyDelete(ThreadSpecificKey); 184 WTF_EXPORT void ThreadSpecificKeyDelete(ThreadSpecificKey);
188 WTF_EXPORT void ThreadSpecificSet(ThreadSpecificKey, void*); 185 WTF_EXPORT void ThreadSpecificSet(ThreadSpecificKey, void*);
189 WTF_EXPORT void* ThreadSpecificGet(ThreadSpecificKey); 186 WTF_EXPORT void* ThreadSpecificGet(ThreadSpecificKey);
190 187
191 template <typename T> 188 template <typename T>
192 inline ThreadSpecific<T>::ThreadSpecific() : index_(-1) { 189 inline ThreadSpecific<T>::ThreadSpecific() : index_(-1) {
193 DWORD tls_key = TlsAlloc(); 190 DWORD tls_key = TlsAlloc();
194 if (tls_key == TLS_OUT_OF_INDEXES) 191 CHECK_NE(tls_key, TLS_OUT_OF_INDEXES);
195 IMMEDIATE_CRASH();
196 192
197 index_ = InterlockedIncrement(&TlsKeyCount()) - 1; 193 index_ = InterlockedIncrement(&TlsKeyCount()) - 1;
198 if (index_ >= kMaxTlsKeySize) 194 CHECK_LE(index_, kMaxTlsKeySize);
199 IMMEDIATE_CRASH();
200 TlsKeys()[index_] = tls_key; 195 TlsKeys()[index_] = tls_key;
201 } 196 }
202 197
203 template <typename T> 198 template <typename T>
204 inline ThreadSpecific<T>::~ThreadSpecific() { 199 inline ThreadSpecific<T>::~ThreadSpecific() {
205 // Does not invoke destructor functions. They will be called from 200 // Does not invoke destructor functions. They will be called from
206 // ThreadSpecificThreadExit when the thread is detached. 201 // ThreadSpecificThreadExit when the thread is detached.
207 TlsFree(tlsKeys()[m_index]); 202 TlsFree(tlsKeys()[m_index]);
208 } 203 }
209 204
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 template <typename T> 302 template <typename T>
308 inline T& ThreadSpecific<T>::operator*() { 303 inline T& ThreadSpecific<T>::operator*() {
309 return *operator T*(); 304 return *operator T*();
310 } 305 }
311 306
312 } // namespace WTF 307 } // namespace WTF
313 308
314 using WTF::ThreadSpecific; 309 using WTF::ThreadSpecific;
315 310
316 #endif // WTF_ThreadSpecific_h 311 #endif // WTF_ThreadSpecific_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698