Developer World
Spresense SDK Library v3.3.0-375c679
al_thread.h
1#ifndef __INCLUDE_AUDIOLITE_THREAD_H
2#define __INCLUDE_AUDIOLITE_THREAD_H
3
4/****************************************************************************
5 * Included Files
6 ****************************************************************************/
7
8#include <mossfw/mossfw_component.h>
9
10/****************************************************************************
11 * Pre-processor Definitions
12 ****************************************************************************/
13
14#define AL_THREAD_NAMEMAX (32)
15
16/****************************************************************************
17 * Class Definitions
18 ****************************************************************************/
19
21{
22 public:
23
24 /* Override before_start() method if there is any conditions before
25 * start run the thread.
26 * Retrun true if all conditions are good enough,
27 * return false if it is not.
28 */
29
30 virtual bool before_start(void *arg)
31 {
32 return true;
33 };
34
35 /* runnable returns 0 when it wants to finish the thread loop.
36 * Returning othre value makes keep continue the loop.
37 */
38
39 virtual int run(void *arg) = 0;
40
41 /* Override before_stop() method to do some before thread is stopped. */
42
43 virtual void before_stop(void *arg) {};
44};
45
47{
48 protected:
49 audiolite_runnable_if *_runnable;
50 void *_runnable_arg;
51
52 mossfw_thread_t _tid;
53 int _prio;
54 int _stacksz;
55 char _tname[AL_THREAD_NAMEMAX];
56 volatile bool _is_thrdrun;
57
58 static void *running_thread(void *arg);
59
60 public:
61 audiolite_thread(audiolite_runnable_if *runnable, void *runnable_arg,
62 int prio, int stacksz, const char *thdname=NULL);
63
65
66 bool set_runnable(audiolite_runnable_if *runnable, void *runnable_arg);
67 bool start();
68 void stop();
69
70 bool is_running() { return _is_thrdrun; };
71};
72
73#endif // __INCLUDE_AUDIOLITE_THREAD_H
Definition: al_thread.h:21
Definition: al_thread.h:47