I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 4c19ddde authored by mpc's avatar mpc Committed by zzz
Browse files

a couple locking changes

parent d8f0f1a1
No related branches found
No related tags found
No related merge requests found
...@@ -43,9 +43,9 @@ using namespace Libsockthread; ...@@ -43,9 +43,9 @@ using namespace Libsockthread;
*/ */
void Logger::close(void) void Logger::close(void)
{ {
logger_m.lock(); logf_m.lock();
if (logf == 0) { if (logf == 0) {
logger_m.unlock(); logf_m.unlock();
return; return;
} }
if (fclose(logf) == EOF) { if (fclose(logf) == EOF) {
...@@ -54,7 +54,7 @@ void Logger::close(void) ...@@ -54,7 +54,7 @@ void Logger::close(void)
cerr_m.unlock(); cerr_m.unlock();
} }
logf = 0; logf = 0;
logger_m.unlock(); logf_m.unlock();
} }
/* /*
...@@ -90,7 +90,7 @@ void Logger::log(priority_t priority, const char* format, ...) ...@@ -90,7 +90,7 @@ void Logger::log(priority_t priority, const char* format, ...)
va_start(ap, format); va_start(ap, format);
string s; string s;
Time t; Time t;
logger_m.lock(); logf_m.lock();
if (logf != 0) { if (logf != 0) {
/* /*
...@@ -112,7 +112,7 @@ void Logger::log(priority_t priority, const char* format, ...) ...@@ -112,7 +112,7 @@ void Logger::log(priority_t priority, const char* format, ...)
} }
va_end(ap); va_end(ap);
logger_m.unlock(); logf_m.unlock();
return; return;
} }
...@@ -126,12 +126,13 @@ void Logger::log(priority_t priority, const char* format, ...) ...@@ -126,12 +126,13 @@ void Logger::log(priority_t priority, const char* format, ...)
bool Logger::open(const string& file) bool Logger::open(const string& file)
{ {
close(); close();
logger_m.lock(); logf_m.lock();
logf = fopen(file.c_str(), "a"); logf = fopen(file.c_str(), "a");
logger_m.unlock();
if (logf != NULL) { if (logf != NULL) {
logf_m.unlock();
return true; return true;
} else { } else {
logf_m.unlock();
cerr_m.lock(); cerr_m.lock();
cerr << "fopen() failed (" << file << "): " << strerror(errno) << '\n'; cerr << "fopen() failed (" << file << "): " << strerror(errno) << '\n';
cerr_m.unlock(); cerr_m.unlock();
......
...@@ -79,16 +79,17 @@ namespace Libsockthread { ...@@ -79,16 +79,17 @@ namespace Libsockthread {
void close(void); void close(void);
void log(priority_t priority, const char* format, ...); void log(priority_t priority, const char* format, ...);
priority_t get_loglevel(void) priority_t get_loglevel(void)
{ logger_m.lock(); priority_t ll = loglevel; logger_m.unlock(); { loglevel_m.lock(); priority_t ll = loglevel;
return ll; } loglevel_m.unlock(); return ll; }
bool open(const string& file); bool open(const string& file);
void set_loglevel(priority_t priority) void set_loglevel(priority_t priority)
{ logger_m.lock(); loglevel = priority; logger_m.unlock(); } { loglevel_m.lock(); loglevel = priority; loglevel_m.unlock(); }
private: private:
Mutex cerr_m; Mutex cerr_m;
FILE* logf; FILE* logf;
Mutex logf_m;
priority_t loglevel; priority_t loglevel;
Mutex logger_m; Mutex loglevel_m;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment