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

Side by Side Diff: src/core/SkSharedMutex.cpp

Issue 1232003008: Fix undefined behavior. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSharedMutex.h" 8 #include "SkSharedMutex.h"
9 9
10 #include "SkAtomics.h" 10 #include "SkAtomics.h"
11 #include "SkSemaphore.h" 11 #include "SkSemaphore.h"
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14
15 #if defined(THREAD_SANITIZER) 14 #if defined(THREAD_SANITIZER)
16 15
17 /* Report that a lock has been created at address "lock". */ 16 /* Report that a lock has been created at address "lock". */
18 #define ANNOTATE_RWLOCK_CREATE(lock) \ 17 #define ANNOTATE_RWLOCK_CREATE(lock) \
19 AnnotateRWLockCreate(__FILE__, __LINE__, lock) 18 AnnotateRWLockCreate(__FILE__, __LINE__, lock)
20 19
21 /* Report that the lock at address "lock" is about to be destroyed. */ 20 /* Report that the lock at address "lock" is about to be destroyed. */
22 #define ANNOTATE_RWLOCK_DESTROY(lock) \ 21 #define ANNOTATE_RWLOCK_DESTROY(lock) \
23 AnnotateRWLockDestroy(__FILE__, __LINE__, lock) 22 AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
24 23
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 fSharedQueue.wait(); 160 fSharedQueue.wait();
162 } 161 }
163 ANNOTATE_RWLOCK_ACQUIRED(this, 0); 162 ANNOTATE_RWLOCK_ACQUIRED(this, 0);
164 163
165 } 164 }
166 165
167 void SkSharedMutex::releaseShared() { 166 void SkSharedMutex::releaseShared() {
168 ANNOTATE_RWLOCK_RELEASED(this, 0); 167 ANNOTATE_RWLOCK_RELEASED(this, 0);
169 168
170 // Decrement the shared count. 169 // Decrement the shared count.
171 int32_t oldQueueCounts = fQueueCounts.fetch_add(-1 << kSharedOffset, 170 int32_t oldQueueCounts = fQueueCounts.fetch_add(~0U << kSharedOffset,
172 sk_memory_order_release); 171 sk_memory_order_release);
173 172
174 // If shared count is going to zero (because the old count == 1) and there a re exclusive 173 // If shared count is going to zero (because the old count == 1) and there a re exclusive
175 // waiters, then run a single exclusive waiter. 174 // waiters, then run a single exclusive waiter.
176 if (((oldQueueCounts & kSharedMask) >> kSharedOffset) == 1 175 if (((oldQueueCounts & kSharedMask) >> kSharedOffset) == 1
177 && (oldQueueCounts & kWaitingExclusiveMask) > 0) { 176 && (oldQueueCounts & kWaitingExclusiveMask) > 0) {
178 fExclusiveQueue.signal(); 177 fExclusiveQueue.signal();
179 } 178 }
180 } 179 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698