nghttpx: Use std::atomic for Config::cached_time

This commit is contained in:
Tatsuhiro Tsujikawa 2014-07-05 23:50:32 +09:00
parent fe2843f9d6
commit 933e24d412
3 changed files with 6 additions and 4 deletions

View File

@ -569,7 +569,8 @@ void fill_default_config()
(mod_config()->http2_option, 1); (mod_config()->http2_option, 1);
mod_config()->tls_proto_mask = 0; mod_config()->tls_proto_mask = 0;
mod_config()->cached_time = cache_time(time_cache_buf_idx); mod_config()->cached_time.store(cache_time(time_cache_buf_idx),
std::memory_order_release);
} }
} // namespace } // namespace

View File

@ -35,6 +35,7 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <atomic>
#include <event.h> #include <event.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
@ -199,7 +200,7 @@ struct Config {
FILE *http2_upstream_dump_request_header; FILE *http2_upstream_dump_request_header;
FILE *http2_upstream_dump_response_header; FILE *http2_upstream_dump_response_header;
nghttp2_option *http2_option; nghttp2_option *http2_option;
volatile const char *cached_time; std::atomic<const char*> cached_time;
size_t downstream_addrlen; size_t downstream_addrlen;
size_t num_worker; size_t num_worker;
size_t http2_max_concurrent_streams; size_t http2_max_concurrent_streams;

View File

@ -119,7 +119,7 @@ Log::~Log()
rv = snprintf(buf, sizeof(buf), rv = snprintf(buf, sizeof(buf),
"%s PID%d [%s%s%s] %s\n %s(%s:%d)%s\n", "%s PID%d [%s%s%s] %s\n %s(%s:%d)%s\n",
get_config()->cached_time, get_config()->cached_time.load(std::memory_order_acquire),
getpid(), getpid(),
tty ? SEVERITY_COLOR[severity_] : "", tty ? SEVERITY_COLOR[severity_] : "",
SEVERITY_STR[severity_], SEVERITY_STR[severity_],
@ -183,7 +183,7 @@ void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
rv = snprintf(buf, sizeof(buf), fmt, rv = snprintf(buf, sizeof(buf), fmt,
client_ip.c_str(), client_ip.c_str(),
get_config()->cached_time, get_config()->cached_time.load(std::memory_order_acquire),
method, method,
path, path,
major, major,