SkExecutor.h 1002 B

123456789101112131415161718192021222324252627282930313233
  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. #ifndef SkExecutor_DEFINED
  8. #define SkExecutor_DEFINED
  9. #include <functional>
  10. #include <memory>
  11. class SkExecutor {
  12. public:
  13. virtual ~SkExecutor();
  14. // Create a thread pool SkExecutor with a fixed thread count, by default the number of cores.
  15. static std::unique_ptr<SkExecutor> MakeFIFOThreadPool(int threads = 0);
  16. static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0);
  17. // There is always a default SkExecutor available by calling SkExecutor::GetDefault().
  18. static SkExecutor& GetDefault();
  19. static void SetDefault(SkExecutor*); // Does not take ownership. Not thread safe.
  20. // Add work to execute.
  21. virtual void add(std::function<void(void)>) = 0;
  22. // If it makes sense for this executor, use this thread to execute work for a little while.
  23. virtual void borrow() {}
  24. };
  25. #endif//SkExecutor_DEFINED