Debian Codegraph @

include/core/SkExecutor.h

raw
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
15 class SK_API SkExecutor {
16 public:
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 bool allowBorrowing = true);
22 static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0,
23 bool allowBorrowing = true);
24
25 // A work list is the queue or stack to which work is added and removed. The above two
26 // factory functions create an executor with only one list while the following two factories
27 // can create executors with multiple work lists. Having multiple work lists allows for
28 // prioritization with work being pulled from the lower indexed work lists first - with
29 // work list '0' being the highest priority.
30 static std::unique_ptr<SkExecutor> MakeMultiListFIFOThreadPool(int numWorkLists,
31 int threads = 0,
32 bool allowBorrowing = true);
33 static std::unique_ptr<SkExecutor> MakeMultiListLIFOThreadPool(int numWorkLists,
34 int threads = 0,
35 bool allowBorrowing = true);
36
37 // There is always a default SkExecutor available by calling SkExecutor::GetDefault().
38 static SkExecutor& GetDefault();
39 static void SetDefault(SkExecutor*); // Does not take ownership. Not thread safe.
40
41 // Add work to execute.
42 virtual void add(std::function<void(void)> fn, int /* workList */) { this->add(std::move(fn)); }
43
44 // deprecated
45 virtual void add(std::function<void(void)>) = 0;
46
47 // Returns the number of discarded work units
48 virtual int discardAllPendingWork() { return 0; }
49
50 // If it makes sense for this executor, use this thread to execute work for a little while.
51 virtual void borrow() {}
52
53 protected:
54 SkExecutor() = default;
55 SkExecutor(const SkExecutor&) = delete;
56 SkExecutor& operator=(const SkExecutor&) = delete;
57 };
58
59 #endif//SkExecutor_DEFINED