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

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

Issue 2919443002: Use IMMEDIATE_CRASH() instead of CRASH() directly (Closed)
Patch Set: Use IMMEDIATE_CRASH() instead of CRASH() directly 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (error)
129 CRASH(); 129 IMMEDIATE_CRASH();
130 } 130 }
131 131
132 inline void ThreadSpecificKeyDelete(ThreadSpecificKey key) { 132 inline void ThreadSpecificKeyDelete(ThreadSpecificKey key) {
133 int error = pthread_key_delete(key); 133 int error = pthread_key_delete(key);
134 if (error) 134 if (error)
135 CRASH(); 135 IMMEDIATE_CRASH();
136 } 136 }
137 137
138 inline void ThreadSpecificSet(ThreadSpecificKey key, void* value) { 138 inline void ThreadSpecificSet(ThreadSpecificKey key, void* value) {
139 pthread_setspecific(key, value); 139 pthread_setspecific(key, value);
140 } 140 }
141 141
142 inline void* ThreadSpecificGet(ThreadSpecificKey key) { 142 inline void* ThreadSpecificGet(ThreadSpecificKey key) {
143 return pthread_getspecific(key); 143 return pthread_getspecific(key);
144 } 144 }
145 145
146 template <typename T> 146 template <typename T>
147 inline ThreadSpecific<T>::ThreadSpecific() { 147 inline ThreadSpecific<T>::ThreadSpecific() {
148 int error = pthread_key_create(&key_, Destroy); 148 int error = pthread_key_create(&key_, Destroy);
149 if (error) 149 if (error)
150 CRASH(); 150 IMMEDIATE_CRASH();
151 } 151 }
152 152
153 template <typename T> 153 template <typename T>
154 inline T* ThreadSpecific<T>::Get() { 154 inline T* ThreadSpecific<T>::Get() {
155 Data* data = static_cast<Data*>(pthread_getspecific(key_)); 155 Data* data = static_cast<Data*>(pthread_getspecific(key_));
156 return data ? data->value : 0; 156 return data ? data->value : 0;
157 } 157 }
158 158
159 template <typename T> 159 template <typename T>
160 inline void ThreadSpecific<T>::Set(T* ptr) { 160 inline void ThreadSpecific<T>::Set(T* ptr) {
(...skipping 24 matching lines...) Expand all
185 185
186 WTF_EXPORT void ThreadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void*)); 186 WTF_EXPORT void ThreadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void*));
187 WTF_EXPORT void ThreadSpecificKeyDelete(ThreadSpecificKey); 187 WTF_EXPORT void ThreadSpecificKeyDelete(ThreadSpecificKey);
188 WTF_EXPORT void ThreadSpecificSet(ThreadSpecificKey, void*); 188 WTF_EXPORT void ThreadSpecificSet(ThreadSpecificKey, void*);
189 WTF_EXPORT void* ThreadSpecificGet(ThreadSpecificKey); 189 WTF_EXPORT void* ThreadSpecificGet(ThreadSpecificKey);
190 190
191 template <typename T> 191 template <typename T>
192 inline ThreadSpecific<T>::ThreadSpecific() : index_(-1) { 192 inline ThreadSpecific<T>::ThreadSpecific() : index_(-1) {
193 DWORD tls_key = TlsAlloc(); 193 DWORD tls_key = TlsAlloc();
194 if (tls_key == TLS_OUT_OF_INDEXES) 194 if (tls_key == TLS_OUT_OF_INDEXES)
195 CRASH(); 195 IMMEDIATE_CRASH();
196 196
197 index_ = InterlockedIncrement(&TlsKeyCount()) - 1; 197 index_ = InterlockedIncrement(&TlsKeyCount()) - 1;
198 if (index_ >= kMaxTlsKeySize) 198 if (index_ >= kMaxTlsKeySize)
199 CRASH(); 199 IMMEDIATE_CRASH();
200 TlsKeys()[index_] = tls_key; 200 TlsKeys()[index_] = tls_key;
201 } 201 }
202 202
203 template <typename T> 203 template <typename T>
204 inline ThreadSpecific<T>::~ThreadSpecific() { 204 inline ThreadSpecific<T>::~ThreadSpecific() {
205 // Does not invoke destructor functions. They will be called from 205 // Does not invoke destructor functions. They will be called from
206 // ThreadSpecificThreadExit when the thread is detached. 206 // ThreadSpecificThreadExit when the thread is detached.
207 TlsFree(tlsKeys()[m_index]); 207 TlsFree(tlsKeys()[m_index]);
208 } 208 }
209 209
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 template <typename T> 307 template <typename T>
308 inline T& ThreadSpecific<T>::operator*() { 308 inline T& ThreadSpecific<T>::operator*() {
309 return *operator T*(); 309 return *operator T*();
310 } 310 }
311 311
312 } // namespace WTF 312 } // namespace WTF
313 313
314 using WTF::ThreadSpecific; 314 using WTF::ThreadSpecific;
315 315
316 #endif // WTF_ThreadSpecific_h 316 #endif // WTF_ThreadSpecific_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698