mirror of https://github.com/PentHertz/srsLTE.git
remove duplicate run-state variable in logger_file
This commit is contained in:
parent
58823b1611
commit
4deb251071
|
@ -64,8 +64,7 @@ private:
|
||||||
int64_t max_length;
|
int64_t max_length;
|
||||||
int64_t cur_length;
|
int64_t cur_length;
|
||||||
FILE* logfile;
|
FILE* logfile;
|
||||||
bool inited;
|
bool is_running;
|
||||||
bool not_done;
|
|
||||||
std::string filename;
|
std::string filename;
|
||||||
pthread_cond_t not_empty;
|
pthread_cond_t not_empty;
|
||||||
pthread_cond_t not_full;
|
pthread_cond_t not_full;
|
||||||
|
|
|
@ -34,18 +34,17 @@ using namespace std;
|
||||||
namespace srslte{
|
namespace srslte{
|
||||||
|
|
||||||
logger_file::logger_file()
|
logger_file::logger_file()
|
||||||
:inited(false)
|
:logfile(NULL)
|
||||||
,logfile(NULL)
|
,is_running(false)
|
||||||
,not_done(true)
|
|
||||||
,cur_length(0)
|
,cur_length(0)
|
||||||
,max_length(0)
|
,max_length(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
logger_file::~logger_file() {
|
logger_file::~logger_file() {
|
||||||
not_done = false;
|
if(is_running) {
|
||||||
if(inited) {
|
|
||||||
log(new std::string("Closing log\n"));
|
log(new std::string("Closing log\n"));
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
|
is_running = false;
|
||||||
pthread_cond_signal(¬_empty); // wakeup thread and let it terminate
|
pthread_cond_signal(¬_empty); // wakeup thread and let it terminate
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
wait_thread_finish();
|
wait_thread_finish();
|
||||||
|
@ -67,11 +66,11 @@ void logger_file::init(std::string file, int max_length_) {
|
||||||
name_idx = 0;
|
name_idx = 0;
|
||||||
filename = file;
|
filename = file;
|
||||||
logfile = fopen(filename.c_str(), "w");
|
logfile = fopen(filename.c_str(), "w");
|
||||||
if(logfile==NULL) {
|
if(logfile == NULL) {
|
||||||
printf("Error: could not create log file, no messages will be logged!\n");
|
printf("Error: could not create log file, no messages will be logged!\n");
|
||||||
}
|
}
|
||||||
|
is_running = true;
|
||||||
start(-2);
|
start(-2);
|
||||||
inited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger_file::log(const char *msg) {
|
void logger_file::log(const char *msg) {
|
||||||
|
@ -86,14 +85,11 @@ void logger_file::log(str_ptr msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger_file::run_thread() {
|
void logger_file::run_thread() {
|
||||||
while(not_done) {
|
while(is_running) {
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
while(buffer.empty()) {
|
while(buffer.empty()) {
|
||||||
pthread_cond_wait(¬_empty, &mutex);
|
pthread_cond_wait(¬_empty, &mutex);
|
||||||
if(not_done == false) // Thread done. Messages in buffer will be handled in flush.
|
if(!is_running) return; // Thread done. Messages in buffer will be handled in flush.
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
str_ptr s = buffer.front();
|
str_ptr s = buffer.front();
|
||||||
pthread_cond_signal(¬_full);
|
pthread_cond_signal(¬_full);
|
||||||
|
|
Loading…
Reference in New Issue