Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
PeriodicThread.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * PeriodicThread.h
17 * A thread which executes a Callback periodically.
18 * Copyright (C) 2015 Simon Newton
19 */
20
21#ifndef INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
22#define INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
23
24#include <ola/Callback.h>
25#include <ola/base/Macro.h>
26#include <ola/thread/Thread.h>
27#include <ola/Clock.h>
28
29#include <string>
30
31namespace ola {
32namespace thread {
33
37class PeriodicThread : private Thread {
38 public:
45
55 explicit PeriodicThread(const TimeInterval &delay,
56 PeriodicCallback *callback,
57 const Options &options = Options());
58
64 void Stop();
65
66 protected:
67 void *Run();
68
69 private:
70 TimeInterval m_delay;
71 PeriodicCallback *m_callback;
72
73 bool m_terminate;
74 ola::thread::Mutex m_mutex;
76
77 PeriodicThread(const PeriodicThread &) = delete;
78 const PeriodicThread &operator=(const PeriodicThread &) = delete;
79};
80} // namespace thread
81} // namespace ola
82#endif // INCLUDE_OLA_THREAD_PERIODICTHREAD_H_
Helper macros.
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
Definition Clock.h:126
Definition Mutex.h:83
Definition Mutex.h:41
A thread which executes a Callback.
Definition PeriodicThread.h:37
Callback0< bool > PeriodicCallback
The callback to run.
Definition PeriodicThread.h:44
void * Run()
The entry point for the new thread.
Definition PeriodicThread.cpp:52
PeriodicThread(const TimeInterval &delay, PeriodicCallback *callback, const Options &options=Options())
Definition PeriodicThread.cpp:31
void Stop()
Stop the PeriodicThread.
Definition PeriodicThread.cpp:43
Definition Thread.h:52
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
Thread options.
Definition Thread.h:60