SRSUE: mac.h/.cc mutexes changed to C++11 and set initial values

master
Xavier Arteaga 6 years ago committed by Xavier Arteaga
parent 9068280896
commit 5d87aece0f

@ -37,6 +37,8 @@
#include "srslte/common/tti_sync_cv.h" #include "srslte/common/tti_sync_cv.h"
#include "srslte/interfaces/ue_interfaces.h" #include "srslte/interfaces/ue_interfaces.h"
#include "ul_harq.h" #include "ul_harq.h"
#include <condition_variable>
#include <mutex>
namespace srsue { namespace srsue {
@ -168,24 +170,25 @@ private:
srslte::timers timers; srslte::timers timers;
// pointer to MAC PCAP object // pointer to MAC PCAP object
srslte::mac_pcap* pcap; srslte::mac_pcap* pcap = nullptr;
bool is_first_ul_grant; bool is_first_ul_grant = false;
mac_metrics_t metrics[SRSLTE_MAX_CARRIERS]; mac_metrics_t metrics[SRSLTE_MAX_CARRIERS] = {};
/* Class to process MAC PDUs from DEMUX unit */ /* Class to process MAC PDUs from DEMUX unit */
class pdu_process : public thread { class pdu_process : public thread {
public: public:
pdu_process(demux *demux_unit); explicit pdu_process(demux* demux_unit);
~pdu_process();
void notify(); void notify();
void stop(); void stop();
private: private:
void run_thread(); void run_thread() final;
bool running; bool running = false;
bool have_data; bool have_data = false;
pthread_mutex_t mutex; std::mutex mutex;
pthread_cond_t cvar; std::condition_variable cvar;
demux* demux_unit; demux* demux_unit = nullptr;
}; };
pdu_process pdu_process_thread; pdu_process pdu_process_thread;
}; };

@ -651,44 +651,45 @@ uint32_t mac::timer_get_unique_id()
* DEMUX unit * DEMUX unit
* *
*******************************************************/ *******************************************************/
mac::pdu_process::pdu_process(demux* demux_unit_) : thread("MAC_PDU_PROCESS") mac::pdu_process::pdu_process(demux* demux_unit_) : thread("MAC_PDU_PROCESS"), demux_unit(demux_unit_)
{ {
demux_unit = demux_unit_; running = true;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cvar, NULL);
have_data = false;
start(MAC_PDU_THREAD_PRIO); start(MAC_PDU_THREAD_PRIO);
} }
mac::pdu_process::~pdu_process()
{
if (running) {
stop();
}
}
void mac::pdu_process::stop() void mac::pdu_process::stop()
{ {
pthread_mutex_lock(&mutex); mutex.lock();
running = false; running = false;
pthread_cond_signal(&cvar); cvar.notify_all();
pthread_mutex_unlock(&mutex); mutex.unlock();
wait_thread_finish(); wait_thread_finish();
} }
void mac::pdu_process::notify() void mac::pdu_process::notify()
{ {
pthread_mutex_lock(&mutex); std::unique_lock<std::mutex> ul(mutex);
have_data = true; have_data = true;
pthread_cond_signal(&cvar); cvar.notify_all();
pthread_mutex_unlock(&mutex);
} }
void mac::pdu_process::run_thread() void mac::pdu_process::run_thread()
{ {
running = true;
while(running) { while(running) {
have_data = demux_unit->process_pdus(); have_data = demux_unit->process_pdus();
if (!have_data) { if (!have_data) {
pthread_mutex_lock(&mutex); std::unique_lock<std::mutex> ul(mutex);
while(!have_data && running) { while(!have_data && running) {
pthread_cond_wait(&cvar, &mutex); cvar.wait(ul);
} }
pthread_mutex_unlock(&mutex);
} }
} }
} }

Loading…
Cancel
Save