SpatialOps
ThreadPool.h
1 /*
2  * Copyright (c) 2014 The University of Utah
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 
23 #ifndef Field_Expr_ThreadPool_h
24 #define Field_Expr_ThreadPool_h
25 
26 #include <stdio.h>
27 #include <map>
28 #include <spatialops/SpatialOpsConfigure.h>
29 #include <spatialops/threadpool/threadpool.hpp>
30 
31 #include <boost/thread/mutex.hpp>
32 #include <boost/interprocess/sync/scoped_lock.hpp>
33 
34 namespace SpatialOps{
35 
39  class ThreadPool : public boost::threadpool::prio_pool
40  {
41  /* constructor is private because this is implemented as a singleton. */
42  ThreadPool( const int nthreads );
43  ~ThreadPool();
44 
45  public:
47  static ThreadPool& self();
48 
54  static int resize_pool( const int threadCount );
55 
59  static int get_pool_size();
60 
66  static int set_pool_capacity( const int threadCount );
67 
71  static int get_pool_capacity();
72 
73  private:
74  bool init_;
75  };
76 
80  class ThreadPoolFIFO : public boost::threadpool::fifo_pool{
81  ThreadPoolFIFO( const int nthreads );
82  ~ThreadPoolFIFO();
83 
84  public:
85 
87  static ThreadPoolFIFO& self();
88 
94  static int resize_pool( const int threadCount );
95 
99  static int get_pool_size();
100 
106  static int set_pool_capacity( const int threadCount );
107 
111  static int get_pool_capacity();
112 
113  static bool is_thread_parallel();
114 
115  private:
116  bool init_;
117  };
118 } // namespace SpatialOps
119 
120 #endif // Field_Expr_ThreadPool_h
static int get_pool_size()
Definition: ThreadPool.cpp:160
Wrapper for a FIFO thread pool.
Definition: ThreadPool.h:80
static int get_pool_capacity()
Definition: ThreadPool.cpp:167
static int resize_pool(const int threadCount)
set the number of active worker threads in the pool.
Definition: ThreadPool.cpp:157
static int set_pool_capacity(const int threadCount)
set the maximum number of worker threads in the pool.
Definition: ThreadPool.cpp:164
Wrapper for a priority thread pool.
Definition: ThreadPool.h:39