libqi-api  2.0.6.8
/home/opennao/work/master/sdk/libqi/qi/threadpool.hpp
Go to the documentation of this file.
00001 #pragma once
00002 /*
00003  * Copyright (c) 2012 Aldebaran Robotics. All rights reserved.
00004  * Use of this source code is governed by a BSD-style license that can be
00005  * found in the COPYING file.
00006  */
00007 
00008 
00009 #ifndef _QI_THREADPOOL_HPP_
00010 #define _QI_THREADPOOL_HPP_
00011 
00012 # include <boost/function.hpp>
00013 # include <qi/api.hpp>
00014 
00015 namespace qi
00016 {
00017   class ThreadPoolPrivate;
00018 
00020   class QI_API ThreadPool
00021   {
00022     public:
00024       ThreadPool(unsigned int minWorkers = 2, unsigned int maxWorkers = 100,
00025                  unsigned int minIdleWorkers = 1, unsigned int maxIdleWorkers = 0);
00027       ~ThreadPool();
00028 
00030       unsigned int size() const;
00032       unsigned int active() const;
00033 
00035       void setMaxWorkers(unsigned int n);
00037       unsigned int getMaxWorkers() const;
00039       void setMinWorkers(unsigned int n);
00041       unsigned int getMinWorkers() const;
00043       void setMinIdleWorkers(unsigned int n);
00045       unsigned int getMinIdleWorkers() const;
00047       void setMaxIdleWorkers(unsigned int n);
00049       unsigned int getMaxIdleWorkers() const;
00050 
00052       void stop();
00053 
00055       void reset();
00056 
00058       void waitForAll();
00059 
00061       bool schedule(const boost::function<void(void)>& f);
00062 
00063     private:
00064       ThreadPoolPrivate* _p;
00065   };
00066 }
00067 
00068 #endif  // _QI_THREADPOOL_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines