#ifdef MUTEX_DEBUGGING
pthread_mutex_t thread_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+pthread_mutex_t static_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
inline void dump_stacktrace(void)
{
}
#else
pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
inline void dump_stacktrace(void) {;}
#endif
unlock_mutex(&thread_mutex);
}
+/* Protects static const values inside the lxc_global_config_value funtion */
+void static_lock(void)
+{
+ lock_mutex(&static_mutex);
+}
+
+void static_unlock(void)
+{
+ unlock_mutex(&static_mutex);
+}
+
int container_mem_lock(struct lxc_container *c)
{
return lxclock(c->privlock, 0);
*/
extern void process_unlock(void);
+/*!
+ * \brief Lock global data.
+ */
+extern void static_lock(void);
+
+/*!
+ * \brief Unlock global data.
+ */
+extern void static_unlock(void);
+
struct lxc_container;
/*!
{ NULL, NULL },
};
+ /* Protected by a mutex to eliminate conflicting load and store operations */
+ static const char *values[sizeof(options) / sizeof(options[0])] = { 0 };
+
char *user_config_path = NULL;
char *user_lxc_path = NULL;
char *user_home = NULL;
user_lxc_path = strdup(LXCPATH);
}
- /* placed in the thread local storage pool */
- static __thread const char *values[sizeof(options) / sizeof(options[0])] = { 0 };
const char *(*ptr)[2];
const char *value;
size_t i;
return NULL;
}
+ static_lock();
if (values[i]) {
free(user_config_path);
free(user_lxc_path);
value = values[i];
-
+ static_unlock();
return value;
}
+ static_unlock();
process_lock();
fin = fopen_cloexec(user_config_path, "r");
while (*p && (*p == ' ' || *p == '\t')) p++;
if (!*p)
continue;
+ static_lock();
values[i] = copy_global_config_value(p);
+ static_unlock();
free(user_lxc_path);
goto out;
}
}
/* could not find value, use default */
+ static_lock();
if (strcmp(option_name, "lxcpath") == 0)
values[i] = user_lxc_path;
else {
* as an error... */
if (!values[i])
errno = 0;
+ static_unlock();
out:
process_lock();
fclose(fin);
process_unlock();
- return values[i];
+ static_lock();
+ value = values[i];
+ static_unlock();
+ return value;
}
const char *default_lvm_vg(void)