Instrument Neutral Distributed Interface INDI  2.0.2
indisinglethreadpool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #pragma once
19 
20 #include "indimacros.h"
21 #include <memory>
22 #include <functional>
23 #include <atomic>
24 
25 namespace INDI
26 {
27 
28 class SingleThreadPoolPrivate;
30 {
31  DECLARE_PRIVATE(SingleThreadPool)
32  public:
35 
36  public:
39  void start(const std::function<void(const std::atomic_bool &isAboutToClose)> &functionToRun);
40 
43  bool tryStart(const std::function<void(const std::atomic_bool &isAboutToClose)> &functionToRun);
44 
45  public:
47  void quit();
48 
49  protected:
50  std::shared_ptr<SingleThreadPoolPrivate> d_ptr;
51 };
52 
53 }
void quit()
Sets the 'isAboutToClose' flag to 'true' and waits for the end of running function.
bool tryStart(const std::function< void(const std::atomic_bool &isAboutToClose)> &functionToRun)
If thread isn't available at the time of calling, then this function does nothing and returns false....
void start(const std::function< void(const std::atomic_bool &isAboutToClose)> &functionToRun)
Reserves a thread and uses it to run functionToRun. A running function can check the 'isAboutToClose'...
std::shared_ptr< SingleThreadPoolPrivate > d_ptr
Namespace to encapsulate INDI client, drivers, and mediator classes.