Home | History | Annotate | Download | only in core
      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 
     14 class SkExecutor {
     15 public:
     16     virtual ~SkExecutor();
     17 
     18     // Create a thread pool SkExecutor with a fixed thread count, by default the number of cores.
     19     static std::unique_ptr<SkExecutor> MakeFIFOThreadPool(int threads = 0);
     20     static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0);
     21 
     22     // There is always a default SkExecutor available by calling SkExecutor::GetDefault().
     23     static SkExecutor& GetDefault();
     24     static void SetDefault(SkExecutor*);  // Does not take ownership.  Not thread safe.
     25 
     26     // Add work to execute.
     27     virtual void add(std::function<void(void)>) = 0;
     28 
     29     // If it makes sense for this executor, use this thread to execute work for a little while.
     30     virtual void borrow() {}
     31 };
     32 
     33 #endif//SkExecutor_DEFINED
     34