Gazebo Common

API Reference

3.17.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 GZ_COMMON_WORKER_POOL_HH_
19 #define GZ_COMMON_WORKER_POOL_HH_
20 
21 #include <functional>
22 #include <memory>
23 
24 #include <gz/common/Export.hh>
25 #include <gz/common/Time.hh>
27 
28 namespace ignition
29 {
30  namespace common
31  {
33  class WorkerPoolPrivate;
34 
36  class IGNITION_COMMON_VISIBLE WorkerPool
37  {
44  public: explicit WorkerPool(const unsigned int _minThreadCount = 1u);
45 
47  public: ~WorkerPool();
48 
53  // return within a finite amount of time.
54  public: void AddWork(std::function<void()> _work,
55  std::function<void()> _cb = std::function<void()>());
56 
61  // the WorkerPool is destructed before all work is completed
62  public: bool WaitForResults(const Time &_timeout = Time::Zero);
63 
66  private: std::unique_ptr<WorkerPoolPrivate> dataPtr;
68  };
69  }
70 }
71 
72 #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:33
#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
WorkerPool(const unsigned int _minThreadCount=1u)
Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concu...
bool WaitForResults(const Time &_timeout=Time::Zero)
Waits until all work is done and threads are idle.
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:36
~WorkerPool()
closes worker threads
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: gz/common/Time.hh:36
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68