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

Side by Side Diff: native_client_sdk/src/libraries/sdk_util/thread_pool.cc

Issue 16325024: Move thread_pool.h into utils so it can be shared by more than one example. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "threadpool.h" 5 #include "sdk_util/thread_pool.h"
6 6
7 #include <pthread.h> 7 #include <pthread.h>
8 #include <semaphore.h> 8 #include <semaphore.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 11
12 #include "utils/auto_lock.h" 12 #include "sdk_util/auto_lock.h"
13 13
14 // Initializes mutex, semaphores and a pool of threads. If 0 is passed for 14 // Initializes mutex, semaphores and a pool of threads. If 0 is passed for
15 // num_threads, all work will be performed on the dispatch thread. 15 // num_threads, all work will be performed on the dispatch thread.
16 ThreadPool::ThreadPool(int num_threads) 16 ThreadPool::ThreadPool(int num_threads)
17 : threads_(NULL), counter_(0), num_threads_(num_threads), exiting_(false), 17 : threads_(NULL), counter_(0), num_threads_(num_threads), exiting_(false),
18 user_data_(NULL), user_work_function_(NULL) { 18 user_data_(NULL), user_work_function_(NULL) {
19 if (num_threads_ > 0) { 19 if (num_threads_ > 0) {
20 int status; 20 int status;
21 status = sem_init(&work_sem_, 0, 0); 21 status = sem_init(&work_sem_, 0, 0);
22 if (-1 == status) { 22 if (-1 == status) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Dispatch() will invoke the user supplied work function across 135 // Dispatch() will invoke the user supplied work function across
136 // one or more threads for each task. 136 // one or more threads for each task.
137 // Note: This function will block until all work has completed. 137 // Note: This function will block until all work has completed.
138 void ThreadPool::Dispatch(int num_tasks, WorkFunction work, void* data) { 138 void ThreadPool::Dispatch(int num_tasks, WorkFunction work, void* data) {
139 if (num_threads_ > 0) 139 if (num_threads_ > 0)
140 DispatchMany(num_tasks, work, data); 140 DispatchMany(num_tasks, work, data);
141 else 141 else
142 DispatchHere(num_tasks, work, data); 142 DispatchHere(num_tasks, work, data);
143 } 143 }
144 144
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698