X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=accesslog.cpp;h=f10621f52c5055f17dd01ac0cd7391efa7bc204f;hp=4a54fdb8692b63c72ec6f85b8d37e37db5f7f125;hb=6d34c5b6d8e5bec5d1421eadc103f38d206f34f1;hpb=a0fe013448d188b324c00383cfd91695d9d3d076 diff --git a/accesslog.cpp b/accesslog.cpp index 4a54fdb..f10621f 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, nullptr); } AccessLogThread::AccessLogThread(const string &filename) : filename(filename) { - pthread_mutex_init(&mutex, nullptr); } void AccessLogThread::write(const ClientStats& client) { { - MutexLock lock(&mutex); + lock_guard lock(mu); pending_writes.push_back(client); } wakeup(); @@ -37,7 +34,7 @@ void AccessLogThread::do_work() if (filename.empty()) { logfp = nullptr; } else { - logfp = fopen(filename.c_str(), "a+"); + logfp = fopen(filename.c_str(), "a+e"); if (logfp == nullptr) { log_perror(filename.c_str()); // Continue as before. @@ -48,7 +45,7 @@ void AccessLogThread::do_work() // Empty the queue. vector writes; { - MutexLock lock(&mutex); + lock_guard lock(mu); swap(pending_writes, writes); }