1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_THREADING_WORKER_POOL_H_
6#define BASE_THREADING_WORKER_POOL_H_
7#pragma once
8
9#include "base/base_api.h"
10#include "base/tracked.h"
11
12class Task;
13
14namespace base {
15
16// This is a facility that runs tasks that don't require a specific thread or
17// a message loop.
18//
19// WARNING: This shouldn't be used unless absolutely necessary. We don't wait
20// for the worker pool threads to finish on shutdown, so the tasks running
21// inside the pool must be extremely careful about other objects they access
22// (MessageLoops, Singletons, etc). During shutdown these object may no longer
23// exist.
24class BASE_API WorkerPool {
25 public:
26  // This function posts |task| to run on a worker thread.  |task_is_slow|
27  // should be used for tasks that will take a long time to execute.  Returns
28  // false if |task| could not be posted to a worker thread.  Regardless of
29  // return value, ownership of |task| is transferred to the worker pool.
30  static bool PostTask(const tracked_objects::Location& from_here,
31                       Task* task, bool task_is_slow);
32};
33
34}  // namespace base
35
36#endif  // BASE_THREADING_WORKER_POOL_H_
37