123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #ifndef BASE_TASK_THREAD_POOL_H_
- #define BASE_TASK_THREAD_POOL_H_
- #include <memory>
- #include <utility>
- namespace base {
- enum class TaskPriority : uint8_t;
- enum class TaskShutdownBehavior : uint8_t;
- enum class ThreadPolicy : uint8_t;
- struct MayBlock;
- struct WithBaseSyncPrimitives;
- class TaskTraits;
- class UpdateableSequencedTaskRunner;
- }
- #include "base/base_export.h"
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/callback_helpers.h"
- #include "base/location.h"
- #include "base/memory/scoped_refptr.h"
- #include "base/post_task_and_reply_with_result_internal.h"
- #include "base/sequenced_task_runner.h"
- #include "base/single_thread_task_runner.h"
- #include "base/task/single_thread_task_runner_thread_mode.h"
- #include "base/task_runner.h"
- #include "base/time/time.h"
- #include "build/build_config.h"
- namespace base {
- class BASE_EXPORT ThreadPool {
- public:
-
-
-
-
-
-
- ThreadPool() = default;
-
- static bool PostTask(const Location& from_here, OnceClosure task);
- inline static bool PostTask(OnceClosure task,
- const Location& from_here = Location::Current()) {
- return PostTask(from_here, std::move(task));
- }
-
-
-
-
- static bool PostDelayedTask(const Location& from_here,
- OnceClosure task,
- TimeDelta delay);
-
- static bool PostTaskAndReply(const Location& from_here,
- OnceClosure task,
- OnceClosure reply);
-
-
-
-
-
-
-
- template <template <typename> class CallbackType,
- typename TaskReturnType,
- typename ReplyArgType,
- typename = EnableIfIsBaseCallback<CallbackType>>
- static bool PostTaskAndReplyWithResult(
- const Location& from_here,
- CallbackType<TaskReturnType()> task,
- CallbackType<void(ReplyArgType)> reply) {
- return ThreadPool::PostTaskAndReplyWithResult(
- from_here, {}, std::move(task), std::move(reply));
- }
-
-
- static bool PostTask(const Location& from_here,
- const TaskTraits& traits,
- OnceClosure task);
-
-
-
-
-
-
- static bool PostDelayedTask(const Location& from_here,
- const TaskTraits& traits,
- OnceClosure task,
- TimeDelta delay);
-
-
-
-
-
- static bool PostTaskAndReply(const Location& from_here,
- const TaskTraits& traits,
- OnceClosure task,
- OnceClosure reply);
-
-
-
-
-
-
-
-
-
-
-
- template <template <typename> class CallbackType,
- typename TaskReturnType,
- typename ReplyArgType,
- typename = EnableIfIsBaseCallback<CallbackType>>
- static bool PostTaskAndReplyWithResult(
- const Location& from_here,
- const TaskTraits& traits,
- CallbackType<TaskReturnType()> task,
- CallbackType<void(ReplyArgType)> reply) {
- auto* result = new std::unique_ptr<TaskReturnType>();
- return PostTaskAndReply(
- from_here, traits,
- BindOnce(&internal::ReturnAsParamAdapter<TaskReturnType>,
- std::move(task), result),
- BindOnce(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
- std::move(reply), Owned(result)));
- }
-
-
- static scoped_refptr<TaskRunner> CreateTaskRunner(const TaskTraits& traits);
-
-
- static scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunner(
- const TaskTraits& traits);
-
-
-
-
-
-
-
-
-
- static scoped_refptr<UpdateableSequencedTaskRunner>
- CreateUpdateableSequencedTaskRunner(const TaskTraits& traits);
-
-
-
-
-
-
-
-
-
-
-
-
-
- static scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunner(
- const TaskTraits& traits,
- SingleThreadTaskRunnerThreadMode thread_mode =
- SingleThreadTaskRunnerThreadMode::SHARED);
- #if defined(OS_WIN)
-
-
-
-
-
-
-
-
-
-
-
-
- static scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunner(
- const TaskTraits& traits,
- SingleThreadTaskRunnerThreadMode thread_mode =
- SingleThreadTaskRunnerThreadMode::SHARED);
- #endif
- };
- }
- #endif
|