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

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

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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 | « src/core/SkScalerContext.cpp ('k') | src/core/SkShader.cpp » ('j') | 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 "SkSemaphore.h" 8 #include "SkSemaphore.h"
9 9
10 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 10 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 ~OSSemaphore() { sem_destroy(&fSemaphore); } 48 ~OSSemaphore() { sem_destroy(&fSemaphore); }
49 49
50 void signal(int n) { while (n --> 0) { sem_post(&fSemaphore); } } 50 void signal(int n) { while (n --> 0) { sem_post(&fSemaphore); } }
51 void wait() { 51 void wait() {
52 // Try until we're not interrupted. 52 // Try until we're not interrupted.
53 while(sem_wait(&fSemaphore) == -1 && errno == EINTR); 53 while(sem_wait(&fSemaphore) == -1 && errno == EINTR);
54 } 54 }
55 }; 55 };
56 #endif 56 #endif
57 57
58 SkSemaphore::SkSemaphore() : fCount(0), fOSSemaphore(SkNEW(OSSemaphore)) {} 58 SkSemaphore::SkSemaphore() : fCount(0), fOSSemaphore(new OSSemaphore) {}
59 SkSemaphore::~SkSemaphore() { SkDELETE(fOSSemaphore); } 59 SkSemaphore::~SkSemaphore() { delete fOSSemaphore; }
60 60
61 void SkSemaphore::signal(int n) { 61 void SkSemaphore::signal(int n) {
62 SkASSERT(n >= 0); 62 SkASSERT(n >= 0);
63 63
64 // We only want to call the OS semaphore when our logical count crosses 64 // We only want to call the OS semaphore when our logical count crosses
65 // from <= 0 to >0 (when we need to wake sleeping threads). 65 // from <= 0 to >0 (when we need to wake sleeping threads).
66 // 66 //
67 // This is easiest to think about with specific examples of prev and n. 67 // This is easiest to think about with specific examples of prev and n.
68 // If n == 5 and prev == -3, there are 3 threads sleeping and we signal 68 // If n == 5 and prev == -3, there are 3 threads sleeping and we signal
69 // SkTMin(-(-3), 5) == 3 times on the OS semaphore, leaving the count at 2. 69 // SkTMin(-(-3), 5) == 3 times on the OS semaphore, leaving the count at 2.
70 // 70 //
71 // If prev >= 0, no threads are waiting, SkTMin(-prev, n) is always <= 0, 71 // If prev >= 0, no threads are waiting, SkTMin(-prev, n) is always <= 0,
72 // so we don't call the OS semaphore, leaving the count at (prev + n). 72 // so we don't call the OS semaphore, leaving the count at (prev + n).
73 int prev = fCount.fetch_add(n, sk_memory_order_release); 73 int prev = fCount.fetch_add(n, sk_memory_order_release);
74 int toSignal = SkTMin(-prev, n); 74 int toSignal = SkTMin(-prev, n);
75 if (toSignal > 0) { 75 if (toSignal > 0) {
76 fOSSemaphore->signal(toSignal); 76 fOSSemaphore->signal(toSignal);
77 } 77 }
78 } 78 }
79 79
80 void SkSemaphore::wait() { 80 void SkSemaphore::wait() {
81 // We only wait() on the OS semaphore if the count drops <= 0, 81 // We only wait() on the OS semaphore if the count drops <= 0,
82 // i.e. when we need to make this thread sleep to wait for it to go back up. 82 // i.e. when we need to make this thread sleep to wait for it to go back up.
83 if (fCount.fetch_add(-1, sk_memory_order_acquire) <= 0) { 83 if (fCount.fetch_add(-1, sk_memory_order_acquire) <= 0) {
84 fOSSemaphore->wait(); 84 fOSSemaphore->wait();
85 } 85 }
86 } 86 }
OLDNEW
« no previous file with comments | « src/core/SkScalerContext.cpp ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698