Ignition Common

API Reference

4.4.0
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 <ignition/common/Export.hh>
25 #include <ignition/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 IGN_DEPRECATED(4) WaitForResults(const Time &_timeout);
63 
68  // the WorkerPool is destructed before all work is completed
69  public: bool WaitForResults(
70  const std::chrono::steady_clock::duration &_timeout =
71  std::chrono::steady_clock::duration::zero());
72 
75  private: std::unique_ptr<WorkerPoolPrivate> dataPtr;
77  };
78  }
79 }
80 
81 #endif
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:33
A pool of worker threads that do stuff in parallel.
Definition: WorkerPool.hh:36
Forward declarations for the common classes.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64