MEDIUM: thread/vars: Make vars thread-safe
A RW lock has been added to the vars structure to protect each list of
variables. And a global RW lock is used to protect registered names.
When a varibable is fetched, we duplicate sample data because the variable could
be modified by another thread.
diff --git a/include/common/hathreads.h b/include/common/hathreads.h
index 1a14a62..df5b9ed 100644
--- a/include/common/hathreads.h
+++ b/include/common/hathreads.h
@@ -163,6 +163,7 @@
PATREF_LOCK,
PATEXP_LOCK,
PATLRU_LOCK,
+ VARS_LOCK,
LOCK_LABELS
};
struct lock_stat {
@@ -250,7 +251,7 @@
"LISTENER", "LISTENER_QUEUE", "PROXY", "SERVER",
"UPDATED_SERVERS", "LBPRM", "SIGNALS", "STK_TABLE", "STK_SESS",
"APPLETS", "PEER", "BUF_WQ", "STREAMS", "SSL", "SSL_GEN_CERTS",
- "PATREF", "PATEXP", "PATLRU" };
+ "PATREF", "PATEXP", "PATLRU", "VARS" };
int lbl;
for (lbl = 0; lbl < LOCK_LABELS; lbl++) {
diff --git a/include/types/vars.h b/include/types/vars.h
index cd1620c..8a4f7aa 100644
--- a/include/types/vars.h
+++ b/include/types/vars.h
@@ -2,6 +2,7 @@
#define _TYPES_VARS_H
#include <common/mini-clist.h>
+#include <common/hathreads.h>
#include <types/sample.h>
@@ -17,6 +18,9 @@
struct list head;
enum vars_scope scope;
unsigned int size;
+#ifdef USE_THREAD
+ HA_RWLOCK_T rwlock;
+#endif
};
/* This struct describes a variable. */