Open Lighting Architecture: include/ola/thread/PeriodicThread.h Source File

| 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
37 class PeriodicThread : private Thread {
38 public:
44 typedef Callback0<bool> PeriodicCallback;
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;
75 ola::thread::ConditionVariable m_condition;
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_
Callback.h
Macro.h
Helper macros.
ola::Callback0
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
ola::TimeInterval
Definition Clock.h:126
ola::thread::ConditionVariable
Definition Mutex.h:83
ola::thread::Mutex
Definition Mutex.h:41
ola::thread::PeriodicThread::Run
void * Run()
The entry point for the new thread.
Definition PeriodicThread.cpp:52
ola::thread::PeriodicThread::PeriodicThread
PeriodicThread(const TimeInterval &delay, PeriodicCallback *callback, const Options &options=Options())
Definition PeriodicThread.cpp:31
ola::thread::PeriodicThread::PeriodicCallback
Callback0< bool > PeriodicCallback
The callback to run.
Definition PeriodicThread.h:44
ola::thread::PeriodicThread::Stop
void Stop()
Stop the PeriodicThread.
Definition PeriodicThread.cpp:43
ola::thread::Thread::Thread
Thread(const Options &options=Options())
Create a new thread with the specified thread options.
Definition Thread.cpp:75
ola::thread
Threads and synchronization mechanisms.
Definition ConsumerThread.cpp:25
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::thread::Thread::Options
Thread options.
Definition Thread.h:60