Gazebo Common

API Reference

5.6.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 <chrono>
22 #include <functional>
23 
24 #include <gz/common/Export.hh>
25 
26 #include <gz/utils/ImplPtr.hh>
27 
28 namespace gz
29 {
30  namespace common
31  {
33  class WorkerPoolPrivate;
34 
36  class GZ_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(
63  const std::chrono::steady_clock::duration &_timeout =
64  std::chrono::steady_clock::duration::zero());
65 
66  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
67  };
68  }
69 }
70 
71 #endif