a couple locking changes

This commit is contained in:
mpc
2004-07-03 22:03:49 +00:00
committed by zzz
parent d8f0f1a1d3
commit 4c19ddde69
2 changed files with 13 additions and 11 deletions

View File

@ -43,9 +43,9 @@ using namespace Libsockthread;
*/
void Logger::close(void)
{
logger_m.lock();
logf_m.lock();
if (logf == 0) {
logger_m.unlock();
logf_m.unlock();
return;
}
if (fclose(logf) == EOF) {
@ -54,7 +54,7 @@ void Logger::close(void)
cerr_m.unlock();
}
logf = 0;
logger_m.unlock();
logf_m.unlock();
}
/*
@ -90,7 +90,7 @@ void Logger::log(priority_t priority, const char* format, ...)
va_start(ap, format);
string s;
Time t;
logger_m.lock();
logf_m.lock();
if (logf != 0) {
/*
@ -112,7 +112,7 @@ void Logger::log(priority_t priority, const char* format, ...)
}
va_end(ap);
logger_m.unlock();
logf_m.unlock();
return;
}
@ -126,12 +126,13 @@ void Logger::log(priority_t priority, const char* format, ...)
bool Logger::open(const string& file)
{
close();
logger_m.lock();
logf_m.lock();
logf = fopen(file.c_str(), "a");
logger_m.unlock();
if (logf != NULL) {
logf_m.unlock();
return true;
} else {
logf_m.unlock();
cerr_m.lock();
cerr << "fopen() failed (" << file << "): " << strerror(errno) << '\n';
cerr_m.unlock();

View File

@ -79,16 +79,17 @@ namespace Libsockthread {
void close(void);
void log(priority_t priority, const char* format, ...);
priority_t get_loglevel(void)
{ logger_m.lock(); priority_t ll = loglevel; logger_m.unlock();
return ll; }
{ loglevel_m.lock(); priority_t ll = loglevel;
loglevel_m.unlock(); return ll; }
bool open(const string& file);
void set_loglevel(priority_t priority)
{ logger_m.lock(); loglevel = priority; logger_m.unlock(); }
{ loglevel_m.lock(); loglevel = priority; loglevel_m.unlock(); }
private:
Mutex cerr_m;
FILE* logf;
Mutex logf_m;
priority_t loglevel;
Mutex logger_m;
Mutex loglevel_m;
};
}