2012-10-31 15:52:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkThreadPool_DEFINED
|
|
|
|
#define SkThreadPool_DEFINED
|
|
|
|
|
|
|
|
#include "SkCondVar.h"
|
|
|
|
#include "SkTDArray.h"
|
2012-12-03 14:54:59 +00:00
|
|
|
#include "SkTInternalLList.h"
|
2012-10-31 15:52:16 +00:00
|
|
|
|
|
|
|
class SkRunnable;
|
|
|
|
class SkThread;
|
|
|
|
|
|
|
|
class SkThreadPool {
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-04-22 15:23:14 +00:00
|
|
|
* Create a threadpool with count threads, or one thread per core if kThreadPerCore.
|
2012-10-31 15:52:16 +00:00
|
|
|
*/
|
2013-04-22 15:23:14 +00:00
|
|
|
static const int kThreadPerCore = -1;
|
2012-10-31 15:52:16 +00:00
|
|
|
explicit SkThreadPool(int count);
|
|
|
|
~SkThreadPool();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queues up an SkRunnable to run when a thread is available, or immediately if
|
|
|
|
* count is 0. NULL is a safe no-op. Does not take ownership.
|
|
|
|
*/
|
|
|
|
void add(SkRunnable*);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct LinkedRunnable {
|
|
|
|
// Unowned pointer.
|
|
|
|
SkRunnable* fRunnable;
|
|
|
|
|
|
|
|
private:
|
2012-12-03 14:54:59 +00:00
|
|
|
SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable);
|
2012-10-31 15:52:16 +00:00
|
|
|
};
|
|
|
|
|
2012-12-03 14:54:59 +00:00
|
|
|
SkTInternalLList<LinkedRunnable> fQueue;
|
|
|
|
SkCondVar fReady;
|
|
|
|
SkTDArray<SkThread*> fThreads;
|
2013-10-01 18:44:18 +00:00
|
|
|
bool fDone;
|
2012-10-31 15:52:16 +00:00
|
|
|
|
|
|
|
static void Loop(void*); // Static because we pass in this.
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|