[core] Make log.timestamp creation/destruction threadsafe

personal/stbuehler/wip
Thomas Porzelt 13 years ago
parent 8892840298
commit 14d48527af

@ -101,6 +101,8 @@ struct liServer {
GArray *optionptr_def_values;/** array of liOptionPtrValue* */
liAction *mainaction;
GMutex *action_mutex; /** used to synchronize action creation/destruction */
gboolean exiting; /** atomic access */
struct {
@ -129,7 +131,6 @@ struct liServer {
gdouble io_timeout;
GArray *throttle_pools;
GStaticMutex throttle_pools_mutex;
gdouble stat_cache_ttl;
gint tasklet_pool_threads;

@ -494,11 +494,13 @@ liLogTimestamp *li_log_timestamp_new(liServer *srv, GString *format) {
liLogTimestamp *ts;
/* check if there already exists a timestamp entry with the same format */
g_mutex_lock(srv->action_mutex);
for (guint i = 0; i < srv->logs.timestamps->len; i++) {
ts = g_array_index(srv->logs.timestamps, liLogTimestamp*, i);
if (g_string_equal(ts->format, format)) {
g_atomic_int_inc(&(ts->refcount));
g_string_free(format, TRUE);
g_mutex_unlock(srv->action_mutex);
return ts;
}
}
@ -511,18 +513,23 @@ liLogTimestamp *li_log_timestamp_new(liServer *srv, GString *format) {
ts->format = format;
g_array_append_val(srv->logs.timestamps, ts);
g_mutex_unlock(srv->action_mutex);
return ts;
}
gboolean li_log_timestamp_free(liServer *srv, liLogTimestamp *ts) {
if (g_atomic_int_dec_and_test(&(ts->refcount))) {
g_mutex_lock(srv->action_mutex);
for (guint i = 0; i < srv->logs.timestamps->len; i++) {
if (g_string_equal(g_array_index(srv->logs.timestamps, liLogTimestamp*, i)->format, ts->format)) {
g_array_remove_index_fast(srv->logs.timestamps, i);
break;
}
}
g_mutex_unlock(srv->action_mutex);
g_string_free(ts->cached, TRUE);
g_string_free(ts->format, TRUE);
g_slice_free(liLogTimestamp, ts);

@ -1868,7 +1868,7 @@ static void plugin_core_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk
UNUSED(p);
/* initialize throttle pools that have not been yet */
g_static_mutex_lock(&srv->throttle_pools_mutex);
g_mutex_lock(srv->action_mutex);
for (i = 0; i < srv->throttle_pools->len; i++) {
liThrottlePool *pool = g_array_index(srv->throttle_pools, liThrottlePool*, i);
@ -1884,7 +1884,7 @@ static void plugin_core_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk
}
}
}
g_static_mutex_unlock(&srv->throttle_pools_mutex);
g_mutex_unlock(srv->action_mutex);
#if defined(LIGHTY_OS_LINUX)
/* sched_setaffinity is only available on linux */

@ -131,6 +131,8 @@ liServer* li_server_new(const gchar *module_dir, gboolean module_resident) {
srv->mainaction = NULL;
srv->action_mutex = g_mutex_new();
srv->exiting = FALSE;
srv->ts_formats = g_array_new(FALSE, TRUE, sizeof(GString*));
@ -140,7 +142,6 @@ liServer* li_server_new(const gchar *module_dir, gboolean module_resident) {
li_server_ts_format_add(srv, g_string_new("%a, %d %b %Y %H:%M:%S GMT"));
srv->throttle_pools = g_array_new(FALSE, TRUE, sizeof(liThrottlePool*));
g_static_mutex_init(&srv->throttle_pools_mutex);
li_log_init(srv);
@ -220,7 +221,6 @@ void li_server_free(liServer* srv) {
li_throttle_pool_free(srv, g_array_index(srv->throttle_pools, liThrottlePool*, i));
}
g_array_free(srv->throttle_pools, TRUE);
g_static_mutex_free(&srv->throttle_pools_mutex);
}
if (srv->acon) {
@ -281,6 +281,8 @@ void li_server_free(liServer* srv) {
g_array_free(srv->li_plugins_handle_close, TRUE);
g_array_free(srv->li_plugins_handle_vrclose, TRUE);
g_mutex_free(srv->action_mutex);
#ifdef LIGHTY_OS_LINUX
li_value_free(srv->workers_cpu_affinity);
#endif

@ -10,7 +10,7 @@ liThrottlePool *li_throttle_pool_new(liServer *srv, GString *name, guint rate) {
liThrottlePool *pool;
guint i;
g_static_mutex_lock(&srv->throttle_pools_mutex);
g_mutex_lock(srv->action_mutex);
/* check if we already have a pool with that name */
for (i = 0; i < srv->throttle_pools->len; i++) {
@ -18,14 +18,14 @@ liThrottlePool *li_throttle_pool_new(liServer *srv, GString *name, guint rate) {
if (g_string_equal(pool->name, name)) {
g_atomic_int_inc(&pool->refcount);
g_static_mutex_unlock(&srv->throttle_pools_mutex);
g_mutex_unlock(srv->action_mutex);
g_string_free(name, TRUE);
return pool;
}
}
if (rate == 0) {
g_static_mutex_unlock(&srv->throttle_pools_mutex);
g_mutex_unlock(srv->action_mutex);
return NULL;
}
@ -53,7 +53,7 @@ liThrottlePool *li_throttle_pool_new(liServer *srv, GString *name, guint rate) {
g_array_append_val(srv->throttle_pools, pool);
g_static_mutex_unlock(&srv->throttle_pools_mutex);
g_mutex_unlock(srv->action_mutex);
return pool;
}
@ -64,14 +64,14 @@ void li_throttle_pool_free(liServer *srv, liThrottlePool *pool) {
if (!g_atomic_int_dec_and_test(&pool->refcount))
return;
g_static_mutex_lock(&srv->throttle_pools_mutex);
g_mutex_lock(srv->action_mutex);
for (i = 0; i < srv->throttle_pools->len; i++) {
if (pool == g_array_index(srv->throttle_pools, liThrottlePool*, i)) {
g_array_remove_index_fast(srv->throttle_pools, i);
break;
}
}
g_static_mutex_unlock(&srv->throttle_pools_mutex);
g_mutex_unlock(srv->action_mutex);
if (pool->worker_queues) {
for (i = 0; i < srv->worker_count; i++) {

Loading…
Cancel
Save