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

Side by Side Diff: third_party/WebKit/Source/wtf/ThreadingPthreads.cpp

Issue 2394683005: Remove ASSERT_UNUSED (Closed)
Patch Set: Created 4 years, 2 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) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #endif 98 #endif
99 } 99 }
100 100
101 MutexBase::MutexBase(bool recursive) { 101 MutexBase::MutexBase(bool recursive) {
102 pthread_mutexattr_t attr; 102 pthread_mutexattr_t attr;
103 pthread_mutexattr_init(&attr); 103 pthread_mutexattr_init(&attr);
104 pthread_mutexattr_settype( 104 pthread_mutexattr_settype(
105 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); 105 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
106 106
107 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); 107 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr);
108 ASSERT_UNUSED(result, !result); 108 DCHECK_EQ(result, 0);
109 #if ENABLE(ASSERT) 109 #if ENABLE(ASSERT)
110 m_mutex.m_recursionCount = 0; 110 m_mutex.m_recursionCount = 0;
111 #endif 111 #endif
112 112
113 pthread_mutexattr_destroy(&attr); 113 pthread_mutexattr_destroy(&attr);
114 } 114 }
115 115
116 MutexBase::~MutexBase() { 116 MutexBase::~MutexBase() {
117 int result = pthread_mutex_destroy(&m_mutex.m_internalMutex); 117 int result = pthread_mutex_destroy(&m_mutex.m_internalMutex);
118 ASSERT_UNUSED(result, !result); 118 DCHECK_EQ(result, 0);
119 } 119 }
120 120
121 void MutexBase::lock() { 121 void MutexBase::lock() {
122 int result = pthread_mutex_lock(&m_mutex.m_internalMutex); 122 int result = pthread_mutex_lock(&m_mutex.m_internalMutex);
123 ASSERT_UNUSED(result, !result); 123 DCHECK_EQ(result, 0);
124 #if ENABLE(ASSERT) 124 #if ENABLE(ASSERT)
125 ++m_mutex.m_recursionCount; 125 ++m_mutex.m_recursionCount;
126 #endif 126 #endif
127 } 127 }
128 128
129 void MutexBase::unlock() { 129 void MutexBase::unlock() {
130 #if ENABLE(ASSERT) 130 #if ENABLE(ASSERT)
131 ASSERT(m_mutex.m_recursionCount); 131 ASSERT(m_mutex.m_recursionCount);
132 --m_mutex.m_recursionCount; 132 --m_mutex.m_recursionCount;
133 #endif 133 #endif
134 int result = pthread_mutex_unlock(&m_mutex.m_internalMutex); 134 int result = pthread_mutex_unlock(&m_mutex.m_internalMutex);
135 ASSERT_UNUSED(result, !result); 135 DCHECK_EQ(result, 0);
136 } 136 }
137 137
138 // There is a separate tryLock implementation for the Mutex and the 138 // There is a separate tryLock implementation for the Mutex and the
139 // RecursiveMutex since on Windows we need to manually check if tryLock should 139 // RecursiveMutex since on Windows we need to manually check if tryLock should
140 // succeed or not for the non-recursive mutex. On Linux the two implementations 140 // succeed or not for the non-recursive mutex. On Linux the two implementations
141 // are equal except we can assert the recursion count is always zero for the 141 // are equal except we can assert the recursion count is always zero for the
142 // non-recursive mutex. 142 // non-recursive mutex.
143 bool Mutex::tryLock() { 143 bool Mutex::tryLock() {
144 int result = pthread_mutex_trylock(&m_mutex.m_internalMutex); 144 int result = pthread_mutex_trylock(&m_mutex.m_internalMutex);
145 if (result == 0) { 145 if (result == 0) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 pthread_cond_init(&m_condition, nullptr); 177 pthread_cond_init(&m_condition, nullptr);
178 } 178 }
179 179
180 ThreadCondition::~ThreadCondition() { 180 ThreadCondition::~ThreadCondition() {
181 pthread_cond_destroy(&m_condition); 181 pthread_cond_destroy(&m_condition);
182 } 182 }
183 183
184 void ThreadCondition::wait(MutexBase& mutex) { 184 void ThreadCondition::wait(MutexBase& mutex) {
185 PlatformMutex& platformMutex = mutex.impl(); 185 PlatformMutex& platformMutex = mutex.impl();
186 int result = pthread_cond_wait(&m_condition, &platformMutex.m_internalMutex); 186 int result = pthread_cond_wait(&m_condition, &platformMutex.m_internalMutex);
187 ASSERT_UNUSED(result, !result); 187 DCHECK_EQ(result, 0);
188 #if ENABLE(ASSERT) 188 #if ENABLE(ASSERT)
189 ++platformMutex.m_recursionCount; 189 ++platformMutex.m_recursionCount;
190 #endif 190 #endif
191 } 191 }
192 192
193 bool ThreadCondition::timedWait(MutexBase& mutex, double absoluteTime) { 193 bool ThreadCondition::timedWait(MutexBase& mutex, double absoluteTime) {
194 if (absoluteTime < currentTime()) 194 if (absoluteTime < currentTime())
195 return false; 195 return false;
196 196
197 if (absoluteTime > INT_MAX) { 197 if (absoluteTime > INT_MAX) {
(...skipping 12 matching lines...) Expand all
210 int result = pthread_cond_timedwait( 210 int result = pthread_cond_timedwait(
211 &m_condition, &platformMutex.m_internalMutex, &targetTime); 211 &m_condition, &platformMutex.m_internalMutex, &targetTime);
212 #if ENABLE(ASSERT) 212 #if ENABLE(ASSERT)
213 ++platformMutex.m_recursionCount; 213 ++platformMutex.m_recursionCount;
214 #endif 214 #endif
215 return result == 0; 215 return result == 0;
216 } 216 }
217 217
218 void ThreadCondition::signal() { 218 void ThreadCondition::signal() {
219 int result = pthread_cond_signal(&m_condition); 219 int result = pthread_cond_signal(&m_condition);
220 ASSERT_UNUSED(result, !result); 220 DCHECK_EQ(result, 0);
221 } 221 }
222 222
223 void ThreadCondition::broadcast() { 223 void ThreadCondition::broadcast() {
224 int result = pthread_cond_broadcast(&m_condition); 224 int result = pthread_cond_broadcast(&m_condition);
225 ASSERT_UNUSED(result, !result); 225 DCHECK_EQ(result, 0);
226 } 226 }
227 227
228 #if ENABLE(ASSERT) 228 #if ENABLE(ASSERT)
229 static bool s_threadCreated = false; 229 static bool s_threadCreated = false;
230 230
231 bool isAtomicallyInitializedStaticMutexLockHeld() { 231 bool isAtomicallyInitializedStaticMutexLockHeld() {
232 return atomicallyInitializedStaticMutex && 232 return atomicallyInitializedStaticMutex &&
233 atomicallyInitializedStaticMutex->locked(); 233 atomicallyInitializedStaticMutex->locked();
234 } 234 }
235 235
236 bool isBeforeThreadCreated() { 236 bool isBeforeThreadCreated() {
237 return !s_threadCreated; 237 return !s_threadCreated;
238 } 238 }
239 239
240 void willCreateThread() { 240 void willCreateThread() {
241 s_threadCreated = true; 241 s_threadCreated = true;
242 } 242 }
243 #endif 243 #endif
244 244
245 } // namespace WTF 245 } // namespace WTF
246 246
247 #endif // OS(POSIX) 247 #endif // OS(POSIX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698