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

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

Issue 25371003: Fix race between ~SkThreadPool and SkThreadPool::Loop on fDone. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | 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 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 "SkRunnable.h" 8 #include "SkRunnable.h"
9 #include "SkThreadPool.h" 9 #include "SkThreadPool.h"
10 #include "SkThreadUtils.h" 10 #include "SkThreadUtils.h"
(...skipping 21 matching lines...) Expand all
32 if (count < 0) count = num_cores(); 32 if (count < 0) count = num_cores();
33 // Create count threads, all running SkThreadPool::Loop. 33 // Create count threads, all running SkThreadPool::Loop.
34 for (int i = 0; i < count; i++) { 34 for (int i = 0; i < count; i++) {
35 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); 35 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this));
36 *fThreads.append() = thread; 36 *fThreads.append() = thread;
37 thread->start(); 37 thread->start();
38 } 38 }
39 } 39 }
40 40
41 SkThreadPool::~SkThreadPool() { 41 SkThreadPool::~SkThreadPool() {
42 fReady.lock();
42 fDone = true; 43 fDone = true;
43 fReady.lock();
44 fReady.broadcast(); 44 fReady.broadcast();
45 fReady.unlock(); 45 fReady.unlock();
46 46
47 // Wait for all threads to stop. 47 // Wait for all threads to stop.
48 for (int i = 0; i < fThreads.count(); i++) { 48 for (int i = 0; i < fThreads.count(); i++) {
49 fThreads[i]->join(); 49 fThreads[i]->join();
50 SkDELETE(fThreads[i]); 50 SkDELETE(fThreads[i]);
51 } 51 }
52 } 52 }
53 53
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 // We have some threads. Queue it up! 100 // We have some threads. Queue it up!
101 fReady.lock(); 101 fReady.lock();
102 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable); 102 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable);
103 linkedRunnable->fRunnable = r; 103 linkedRunnable->fRunnable = r;
104 fQueue.addToHead(linkedRunnable); 104 fQueue.addToHead(linkedRunnable);
105 fReady.signal(); 105 fReady.signal();
106 fReady.unlock(); 106 fReady.unlock();
107 } 107 }
OLDNEW
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698