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/interfaces/ue_interfaces.h"
#include "ul_harq.h"
#include <condition_variable>
#include <mutex>
namespace srsue {
@ -168,24 +170,25 @@ private:
srslte::timers timers;
// pointer to MAC PCAP object
srslte::mac_pcap* pcap;
bool is_first_ul_grant;
srslte::mac_pcap* pcap = nullptr;
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 pdu_process : public thread {
public:
pdu_process(demux *demux_unit);
explicit pdu_process(demux* demux_unit);
~pdu_process();
void notify();
void stop();
private:
void run_thread();
bool running;
bool have_data;
pthread_mutex_t mutex;
pthread_cond_t cvar;
demux* demux_unit;
void run_thread() final;
bool running = false;
bool have_data = false;
std::mutex mutex;
std::condition_variable cvar;
demux* demux_unit = nullptr;
};
pdu_process pdu_process_thread;
};

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

Loading…
Cancel
Save