#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<mutex> lock(mu);
pending_writes.push_back(client);
}
wakeup();
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.
// Empty the queue.
vector<ClientStats> writes;
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
swap(pending_writes, writes);
}