RENEWLab  1.1.0
RENEW project
recorder_thread.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2018-2020
3  RENEW OPEN SOURCE LICENSE: http://renew-wireless.org/license
4 
5 ----------------------------------------------------------------------
6 Event based message queue thread class for the recorder worker
7 ---------------------------------------------------------------------
8 */
9 #ifndef SOUNDER_RECORDER_THREAD_H_
10 #define SOUNDER_RECORDER_THREAD_H_
11 
12 #include <condition_variable>
13 #include <mutex>
14 
15 #include "recorder_worker.h"
16 
17 namespace Sounder {
19  public:
20  // enum RecordEventType { kThreadTermination, kTaskRecord };
21  //
22  // struct RecordEvent_data {
23  // RecordEventType event_type;
24  // int data;
25  // SampleBuffer* rx_buffer;
26  // size_t rx_buff_size;
27  // };
28 
29  RecorderThread(Config* in_cfg, size_t thread_id, int core, size_t queue_size,
30  size_t antenna_offset, size_t num_antennas,
31  bool wait_signal = true);
33 
34  void Start(void);
35  void Stop(void);
36  bool DispatchWork(Event_data event);
37 
38  private:
39  /*Main threading loop */
40  void DoRecording(void);
41  void HandleEvent(Event_data event);
42  void Finalize();
43 
44  //1 - Producer (dispatcher), 1 - Consumer
45  moodycamel::ConcurrentQueue<Event_data> event_queue_;
46  moodycamel::ProducerToken producer_token_;
48  std::thread thread_;
49 
50  size_t id_;
52 
53  /* >= 0 to assign a core to the thread
54  * <0 to disable thread core assignment */
56 
57  /* Synchronization for startup and sleeping */
58  /* Setting wait signal to false will disable the thread waiting on new message
59  * may cause excessive CPU load for infrequent messages.
60  * However, when the message processing time ~= queue posting time the mutex could
61  * become unnecessary work
62  */
65  std::condition_variable condition_;
66  bool running_;
67 };
68 }; // namespace Sounder
69 
70 #endif /* SOUNDER_RECORDER_THREAD_H_ */
Sounder::RecorderThread::sync_
std::mutex sync_
Definition: recorder_thread.h:64
Event_data
Definition: macros.h:62
Sounder::RecorderThread::HandleEvent
void HandleEvent(Event_data event)
Definition: recorder_thread.cc:134
Sounder::RecorderThread::event_queue_
moodycamel::ConcurrentQueue< Event_data > event_queue_
Definition: recorder_thread.h:45
Sounder::RecorderThread::DispatchWork
bool DispatchWork(Event_data event)
Definition: recorder_thread.cc:65
recorder_worker.h
Sounder::RecorderThread
Definition: recorder_thread.h:18
Sounder::RecorderThread::running_
bool running_
Definition: recorder_thread.h:66
Sounder::RecorderThread::condition_
std::condition_variable condition_
Definition: recorder_thread.h:65
Sounder::RecorderThread::packet_data_length_
size_t packet_data_length_
Definition: recorder_thread.h:51
mutex
pthread_mutex_t mutex
Definition: receiver.cc:24
Sounder::RecorderThread::worker_
RecorderWorker worker_
Definition: recorder_thread.h:47
Sounder::RecorderWorker
Definition: recorder_worker.h:17
Sounder::RecorderThread::id_
size_t id_
Definition: recorder_thread.h:50
Sounder::RecorderThread::RecorderThread
RecorderThread(Config *in_cfg, size_t thread_id, int core, size_t queue_size, size_t antenna_offset, size_t num_antennas, bool wait_signal=true)
Definition: recorder_thread.cc:17
Sounder
Definition: hdf5_lib.cc:20
Sounder::RecorderThread::~RecorderThread
~RecorderThread()
Definition: recorder_thread.cc:32
Sounder::RecorderThread::producer_token_
moodycamel::ProducerToken producer_token_
Definition: recorder_thread.h:46
Sounder::RecorderThread::thread_
std::thread thread_
Definition: recorder_thread.h:48
Config
Definition: config.h:20
Sounder::RecorderThread::wait_signal_
bool wait_signal_
Definition: recorder_thread.h:63
Sounder::RecorderThread::Finalize
void Finalize()
Definition: recorder_thread.cc:54
Sounder::RecorderThread::DoRecording
void DoRecording(void)
Definition: recorder_thread.cc:86
Sounder::RecorderThread::Stop
void Stop(void)
Definition: recorder_thread.cc:48
Sounder::RecorderThread::Start
void Start(void)
Definition: recorder_thread.cc:36
Sounder::RecorderThread::core_alloc_
int core_alloc_
Definition: recorder_thread.h:55