Gazebo Common

API Reference

4.7.0
gz/common/WorkerPool.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef IGNITION_COMMON_WORKER_POOL_HH_
19 #define IGNITION_COMMON_WORKER_POOL_HH_
20 
21 #include <functional>
22 #include <memory>
23 
24 #include <gz/common/config.hh>
25 #include <gz/common/Export.hh>
26 #include <gz/common/Time.hh>
28 
29 namespace ignition
30 {
31  namespace common
32  {
34  class WorkerPoolPrivate;
35 
37  class IGNITION_COMMON_VISIBLE WorkerPool
38  {
45  public: explicit WorkerPool(const unsigned int _minThreadCount = 1u);
46 
48  public: ~WorkerPool();
49 
54  // return within a finite amount of time.
55  public: void AddWork(std::function<void()> _work,
56  std::function<void()> _cb = std::function<void()>());
57 
62  // the WorkerPool is destructed before all work is completed
63  public: bool IGN_DEPRECATED(4) WaitForResults(const Time &_timeout);
64 
69  // the WorkerPool is destructed before all work is completed
70  public: bool WaitForResults(
71  const std::chrono::steady_clock::duration &_timeout =
72  std::chrono::steady_clock::duration::zero());
73 
76  private: std::unique_ptr<WorkerPoolPrivate> dataPtr;
78  };
79  }
80 }
81 
82 #endif
Forward declarations for the common classes.
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: gz/common/Time.hh:34
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
bool WaitForResults(const Time &_timeout)
Waits until all work is done and threads are idle.
WorkerPool(const unsigned int _minThreadCount=1u)
Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concu...
void AddWork(std::function< void()> _work, std::function< void()> _cb=std::function< void()>())
Adds work to the worker pool with optional callback.
A pool of worker threads that do stuff in parallel.
Definition: gz/common/WorkerPool.hh:37
~WorkerPool()
closes worker threads
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68