Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
AuxTaskRT.h
1 /***** AuxTaskRT.h *****/
2 #ifndef __Aux_Task_RT_H_INCLUDED__
3 #define __Aux_Task_RT_H_INCLUDED__
4 
5 #include <Bela.h>
6 #include <string>
7 #include <functional>
8 
9 #ifdef XENOMAI_SKIN_native
10 #include <rtdk.h>
11 #include <native/task.h>
12 #include <native/queue.h>
13 #endif
14 
15 #ifdef XENOMAI_SKIN_posix
16 #include <fcntl.h> /* For O_* constants */
17 #include <sys/stat.h> /* For mode constants */
18 #include <pthread.h>
19 #include <mqueue.h>
20 #endif
21 
22 #define AUX_RT_POOL_SIZE 500000
23 
24 class AuxTaskRT{
25  public:
26  AuxTaskRT(){}
27  AuxTaskRT(std::string _name, std::function<void()> callback){ create(_name, callback); }
28  AuxTaskRT(std::string _name, std::function<void(std::string str)> callback){ create(_name, callback); }
29  AuxTaskRT(std::string _name, std::function<void(void* buf, int size)> callback){ create(_name, callback); }
30  ~AuxTaskRT(){ cleanup(); }
31 
32  void create(std::string _name, std::function<void()> callback, int _priority = BELA_AUDIO_PRIORITY-5);
33  void create(std::string _name, std::function<void(std::string str)> callback, int _priority = BELA_AUDIO_PRIORITY-5);
34  void create(std::string _name, std::function<void(void* buf, int size)> callback, int _priority = BELA_AUDIO_PRIORITY-5);
35 
36  void schedule(void* buf, size_t size);
37  void schedule(const char* str);
38  void schedule();
39 
40  private:
41  bool lShouldStop = false;
42  bool shouldStop();
43  void cleanup();
44 
45 #ifdef XENOMAI_SKIN_native
46  RT_TASK task;
47  RT_QUEUE queue;
48 #endif
49 #ifdef XENOMAI_SKIN_posix
50  pthread_t thread;
51  mqd_t queueDesc;
52  std::string queueName;
53 #endif
54 
55  std::string name;
56  int priority;
57  int mode;
58 
59  void __create();
60 
61  std::function<void()> empty_callback;
62  std::function<void(std::string str)> str_callback;
63  std::function<void(void* buf, int size)> buf_callback;
64 
65  void empty_loop();
66  void str_loop();
67  void buf_loop();
68 
69  static void thread_func(void* ptr);
70 };
71 
72 #endif
#define BELA_AUDIO_PRIORITY
Definition: Bela.h:178
Definition: AuxTaskRT.h:24
Main Bela public API.