1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkExecutor_DEFINED
9#define SkExecutor_DEFINED
10
11#include <functional>
12#include <memory>
13#include "include/core/SkTypes.h"
14
15class SK_API SkExecutor {
16public:
17 virtual ~SkExecutor();
18
19 // Create a thread pool SkExecutor with a fixed thread count, by default the number of cores.
20 static std::unique_ptr<SkExecutor> MakeFIFOThreadPool(int threads = 0);
21 static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0);
22
23 // There is always a default SkExecutor available by calling SkExecutor::GetDefault().
24 static SkExecutor& GetDefault();
25 static void SetDefault(SkExecutor*); // Does not take ownership. Not thread safe.
26
27 // Add work to execute.
28 virtual void add(std::function<void(void)>) = 0;
29
30 // If it makes sense for this executor, use this thread to execute work for a little while.
31 virtual void borrow() {}
32};
33
34#endif//SkExecutor_DEFINED
35