X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=accesslog.cpp;h=2d5eb0503e9ac00ab2c0bd7207f31eda61f1fa82;hp=af53872e6ec03c0d68f83b86e4b9c9f83320eb6d;hb=4935d50a97f7391795b7974b40c85003189f117a;hpb=b1b81d8f5492e48a60f0ed2930a098747928e5c4 diff --git a/accesslog.cpp b/accesslog.cpp index af53872..2d5eb05 100644 --- a/accesslog.cpp +++ b/accesslog.cpp @@ -7,25 +7,22 @@ #include "accesslog.h" #include "client.h" #include "log.h" -#include "mutexlock.h" #include "timespec.h" using namespace std; AccessLogThread::AccessLogThread() { - pthread_mutex_init(&mutex, NULL); } AccessLogThread::AccessLogThread(const string &filename) : filename(filename) { - pthread_mutex_init(&mutex, NULL); } void AccessLogThread::write(const ClientStats& client) { { - MutexLock lock(&mutex); + lock_guard lock(mu); pending_writes.push_back(client); } wakeup(); @@ -35,10 +32,10 @@ void AccessLogThread::do_work() { // Open the file. if (filename.empty()) { - logfp = NULL; + logfp = nullptr; } else { logfp = fopen(filename.c_str(), "a+"); - if (logfp == NULL) { + if (logfp == nullptr) { log_perror(filename.c_str()); // Continue as before. } @@ -48,11 +45,11 @@ void AccessLogThread::do_work() // Empty the queue. vector writes; { - MutexLock lock(&mutex); + lock_guard lock(mu); swap(pending_writes, writes); } - if (logfp != NULL) { + if (logfp != nullptr) { // Do the actual writes. timespec now_monotonic; timespec now_realtime; @@ -82,14 +79,14 @@ void AccessLogThread::do_work() // Wait until we are being woken up, either to quit or because // there is material in pending_writes. - wait_for_wakeup(NULL); + wait_for_wakeup(nullptr); } - if (logfp != NULL) { + if (logfp != nullptr) { if (fclose(logfp) == EOF) { log_perror("fclose"); } } - logfp = NULL; + logfp = nullptr; }