From: Christian Brauner Date: Wed, 22 Nov 2017 13:25:10 +0000 (+0100) Subject: commands: don't lock atomic operations X-Git-Tag: lxc-3.0.0.beta1~130^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e533be71c8a397ebc6d72c867ff8627d0a87260e;p=thirdparty%2Flxc.git commands: don't lock atomic operations We're dealing with an integer (lxc_state_t which is an enum). Any POSIX implementation makes those operations atomic so there's not need in locking this. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 874a6f791..a896a47c2 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -904,44 +904,35 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath, }, }; - /* Lock the whole lxc_cmd_add_state_client_callback() call to ensure - * that lxc_set_state() doesn't cause us to miss a state. - */ - process_lock(); /* Check if already in requested state. */ state = lxc_getstate(name, lxcpath); if (state < 0) { - process_unlock(); TRACE("%s - Failed to retrieve state of container", strerror(errno)); return -1; } else if (states[state]) { - process_unlock(); TRACE("Container is %s state", lxc_state2str(state)); return state; } if ((state == STARTING) && !states[RUNNING] && !states[STOPPING] && !states[STOPPED]) { - process_unlock(); TRACE("Container is in %s state and caller requested to be " "informed about a previous state", lxc_state2str(state)); return state; } else if ((state == RUNNING) && !states[STOPPING] && !states[STOPPED]) { - process_unlock(); TRACE("Container is in %s state and caller requested to be " "informed about a previous state", lxc_state2str(state)); return state; } else if ((state == STOPPING) && !states[STOPPED]) { - process_unlock(); TRACE("Container is in %s state and caller requested to be " "informed about a previous state", lxc_state2str(state)); return state; } else if ((state == STOPPED) || (state == ABORTING)) { - process_unlock(); TRACE("Container is in %s state and caller requested to be " "informed about a previous state", lxc_state2str(state)); return state; } + process_lock(); ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL); process_unlock(); if (ret < 0) {