#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<mutex> lock(mu);
pending_writes.push_back(client);
}
wakeup();
{
// 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.
}
// Empty the queue.
vector<ClientStats> writes;
{
- MutexLock lock(&mutex);
+ lock_guard<mutex> lock(mu);
swap(pending_writes, writes);
}
- if (logfp != NULL) {
+ if (logfp != nullptr) {
// Do the actual writes.
timespec now_monotonic;
timespec now_realtime;
// 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;
}