MINOR: pattern: store a generation number in the reference patterns

Right now it's not possible to perform a safe reload because we don't
know what patterns were recently added or were already present. This
patch adds a generation counter to the reference patterns so that it
is possible to know what generation of the reference they were loaded
with. A reference now has two generations, the current one, used for
all additions, and the next one, allocated to those wishing to update
the contents. The generation wraps at 2^32 so comparisons must be made
relative to the current position.

The idea will be that upon full reload, the caller will first get a new
generation ID, will insert all new patterns using it, will then switch
the current ID to the new one, and will delete all entries older than
the current ID. This has the benefit of supporting chunked updates that
remain consistent and that won't block the whole process for ages like
pat_ref_reload() currently does.
diff --git a/include/haproxy/pattern-t.h b/include/haproxy/pattern-t.h
index 477b2bb..30ff999 100644
--- a/include/haproxy/pattern-t.h
+++ b/include/haproxy/pattern-t.h
@@ -106,6 +106,8 @@
 	struct list head; /* The head of the list of struct pat_ref_elt. */
 	struct list pat; /* The head of the list of struct pattern_expr. */
 	unsigned int flags; /* flags PAT_REF_*. */
+	unsigned int curr_gen; /* current generation number (anything below can be removed) */
+	unsigned int next_gen; /* next generation number (insertions use this one) */
 	int unique_id; /* Each pattern reference have unique id. */
 	unsigned long long revision; /* updated for each update */
 	__decl_thread(HA_SPINLOCK_T lock); /* Lock used to protect pat ref elements */
@@ -122,6 +124,7 @@
 	struct list tree_head; /* all pattern_tree derived from this reference */
 	char *pattern;
 	char *sample;
+	unsigned int gen_id; /* generation of pat_ref this was made for */
 	int line;
 };
 
diff --git a/src/pattern.c b/src/pattern.c
index 7f4f449..7b4d876 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -1756,6 +1756,8 @@
 
 	ref->reference = NULL;
 	ref->flags = flags;
+	ref->curr_gen = 0;
+	ref->next_gen = 0;
 	ref->unique_id = unique_id;
 	LIST_INIT(&ref->head);
 	LIST_INIT(&ref->pat);
@@ -1767,7 +1769,8 @@
 
 /* This function adds entry to <ref>. It can fail on memory error. It returns
  * the newly added element on success, or NULL on failure. The PATREF_LOCK on
- * <ref> must be held.
+ * <ref> must be held. It sets the newly created pattern's generation number
+ * to the same value as the reference's.
  */
 struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, const char *sample, int line)
 {
@@ -1777,6 +1780,7 @@
 	if (!elt)
 		goto fail;
 
+	elt->gen_id = ref->curr_gen;
 	elt->line = line;
 
 	elt->pattern = strdup(pattern);