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

Side by Side Diff: src/utils/SkThreadUtils_pthread.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 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/utils/SkThreadUtils.h ('k') | src/utils/SkThreadUtils_win.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 2012 Google Inc. 2 * Copyright 2012 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 "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #include "SkThreadUtils.h" 10 #include "SkThreadUtils.h"
11 #include "SkThreadUtils_pthread.h" 11 #include "SkThreadUtils_pthread.h"
12 12
13 #include <pthread.h> 13 #include <pthread.h>
14 #include <signal.h> 14 #include <signal.h>
15 15
16 PThreadEvent::PThreadEvent() : fConditionFlag(false) { 16 PThreadEvent::PThreadEvent() : fConditionFlag(false) {
17 pthread_cond_init(&fCondition, NULL); 17 pthread_cond_init(&fCondition, nullptr);
18 pthread_mutex_init(&fConditionMutex, NULL); 18 pthread_mutex_init(&fConditionMutex, nullptr);
19 } 19 }
20 PThreadEvent::~PThreadEvent() { 20 PThreadEvent::~PThreadEvent() {
21 pthread_mutex_destroy(&fConditionMutex); 21 pthread_mutex_destroy(&fConditionMutex);
22 pthread_cond_destroy(&fCondition); 22 pthread_cond_destroy(&fCondition);
23 } 23 }
24 void PThreadEvent::trigger() { 24 void PThreadEvent::trigger() {
25 pthread_mutex_lock(&fConditionMutex); 25 pthread_mutex_lock(&fConditionMutex);
26 fConditionFlag = true; 26 fConditionFlag = true;
27 pthread_cond_signal(&fCondition); 27 pthread_cond_signal(&fCondition);
28 pthread_mutex_unlock(&fConditionMutex); 28 pthread_mutex_unlock(&fConditionMutex);
(...skipping 29 matching lines...) Expand all
58 58
59 static void* thread_start(void* arg) { 59 static void* thread_start(void* arg) {
60 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(arg); 60 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(arg);
61 // Wait for start signal 61 // Wait for start signal
62 pthreadData->fStarted.wait(); 62 pthreadData->fStarted.wait();
63 63
64 // Call entry point only if thread was not canceled before starting. 64 // Call entry point only if thread was not canceled before starting.
65 if (!pthreadData->fCanceled.isTriggered()) { 65 if (!pthreadData->fCanceled.isTriggered()) {
66 pthreadData->fEntryPoint(pthreadData->fParam); 66 pthreadData->fEntryPoint(pthreadData->fParam);
67 } 67 }
68 return NULL; 68 return nullptr;
69 } 69 }
70 70
71 SkThread::SkThread(entryPointProc entryPoint, void* data) { 71 SkThread::SkThread(entryPointProc entryPoint, void* data) {
72 SkThread_PThreadData* pthreadData = new SkThread_PThreadData(entryPoint, dat a); 72 SkThread_PThreadData* pthreadData = new SkThread_PThreadData(entryPoint, dat a);
73 fData = pthreadData; 73 fData = pthreadData;
74 74
75 int ret = pthread_create(&(pthreadData->fPThread), 75 int ret = pthread_create(&(pthreadData->fPThread),
76 &(pthreadData->fAttr), 76 &(pthreadData->fAttr),
77 thread_start, 77 thread_start,
78 pthreadData); 78 pthreadData);
79 79
80 pthreadData->fValidPThread = (0 == ret); 80 pthreadData->fValidPThread = (0 == ret);
81 } 81 }
82 82
83 SkThread::~SkThread() { 83 SkThread::~SkThread() {
84 if (fData != NULL) { 84 if (fData != nullptr) {
85 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(f Data); 85 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(f Data);
86 // If created thread but start was never called, kill the thread. 86 // If created thread but start was never called, kill the thread.
87 if (pthreadData->fValidPThread && !pthreadData->fStarted.isTriggered()) { 87 if (pthreadData->fValidPThread && !pthreadData->fStarted.isTriggered()) {
88 pthreadData->fCanceled.trigger(); 88 pthreadData->fCanceled.trigger();
89 if (this->start()) { 89 if (this->start()) {
90 this->join(); 90 this->join();
91 } 91 }
92 } 92 }
93 delete pthreadData; 93 delete pthreadData;
94 } 94 }
(...skipping 11 matching lines...) Expand all
106 pthreadData->fStarted.trigger(); 106 pthreadData->fStarted.trigger();
107 return true; 107 return true;
108 } 108 }
109 109
110 void SkThread::join() { 110 void SkThread::join() {
111 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData ); 111 SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData );
112 if (!pthreadData->fValidPThread || !pthreadData->fStarted.isTriggered()) { 112 if (!pthreadData->fValidPThread || !pthreadData->fStarted.isTriggered()) {
113 return; 113 return;
114 } 114 }
115 115
116 pthread_join(pthreadData->fPThread, NULL); 116 pthread_join(pthreadData->fPThread, nullptr);
117 } 117 }
OLDNEW
« no previous file with comments | « src/utils/SkThreadUtils.h ('k') | src/utils/SkThreadUtils_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698