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

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

Issue 1894893002: Modernize and trim down SkOnce. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: might as well class Created 4 years, 8 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 2014 Google Inc. 2 * Copyright 2014 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 "SkOnce.h" 8 #include "SkOnce.h"
9 #include "SkSemaphore.h" 9 #include "SkSemaphore.h"
10 #include "SkSpinlock.h" 10 #include "SkSpinlock.h"
11 #include "SkTArray.h" 11 #include "SkTArray.h"
12 #include "SkTDArray.h" 12 #include "SkTDArray.h"
13 #include "SkTaskGroup.h" 13 #include "SkTaskGroup.h"
14 #include "SkThreadUtils.h" 14 #include "SkThreadUtils.h"
15 15
16 #if defined(SK_BUILD_FOR_WIN32) 16 #if defined(SK_BUILD_FOR_WIN32)
17 static void query_num_cores(int* num_cores) { 17 static void query_num_cores(int* num_cores) {
18 SYSTEM_INFO sysinfo; 18 SYSTEM_INFO sysinfo;
19 GetNativeSystemInfo(&sysinfo); 19 GetNativeSystemInfo(&sysinfo);
20 *num_cores = sysinfo.dwNumberOfProcessors; 20 *num_cores = sysinfo.dwNumberOfProcessors;
21 } 21 }
22 #else 22 #else
23 #include <unistd.h> 23 #include <unistd.h>
24 static void query_num_cores(int* num_cores) { 24 static void query_num_cores(int* num_cores) {
25 *num_cores = (int)sysconf(_SC_NPROCESSORS_ONLN); 25 *num_cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
26 } 26 }
27 #endif 27 #endif
28 28
29 // We cache sk_num_cores() so we only query the OS once.
30 SK_DECLARE_STATIC_ONCE(g_query_num_cores_once);
31 int sk_num_cores() { 29 int sk_num_cores() {
30 // We cache sk_num_cores() so we only query the OS once.
32 static int num_cores = 0; 31 static int num_cores = 0;
33 SkOnce(&g_query_num_cores_once, query_num_cores, &num_cores); 32 static SkOnce once;
bungeman-skia 2016/04/18 15:19:00 It is not entirely clear to me how using member in
mtklein 2016/04/18 15:27:44 It makes the default constructor for SkOnce conste
33 once(query_num_cores, &num_cores);
34 SkASSERT(num_cores > 0); 34 SkASSERT(num_cores > 0);
35 return num_cores; 35 return num_cores;
36 } 36 }
37 37
38 namespace { 38 namespace {
39 39
40 class ThreadPool : SkNoncopyable { 40 class ThreadPool : SkNoncopyable {
41 public: 41 public:
42 static void Add(std::function<void(void)> fn, SkAtomic<int32_t>* pending) { 42 static void Add(std::function<void(void)> fn, SkAtomic<int32_t>* pending) {
43 if (!gGlobal) { 43 if (!gGlobal) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 SkTaskGroup::Enabler::~Enabler() { delete ThreadPool::gGlobal; } 201 SkTaskGroup::Enabler::~Enabler() { delete ThreadPool::gGlobal; }
202 202
203 SkTaskGroup::SkTaskGroup() : fPending(0) {} 203 SkTaskGroup::SkTaskGroup() : fPending(0) {}
204 204
205 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending ); } 205 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending ); }
206 void SkTaskGroup::add(std::function<void(void)> fn) { ThreadPool::Add(fn, &fPend ing); } 206 void SkTaskGroup::add(std::function<void(void)> fn) { ThreadPool::Add(fn, &fPend ing); }
207 void SkTaskGroup::batch(int N, std::function<void(int)> fn) { 207 void SkTaskGroup::batch(int N, std::function<void(int)> fn) {
208 ThreadPool::Batch(N, fn, &fPending); 208 ThreadPool::Batch(N, fn, &fPending);
209 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698