MEDIUM: lua: don't call the GC as often when dealing with outgoing connections

In order to properly close connections established from Lua in case
a Lua context dies, the context currently automatically gets a flag
HLUA_MUST_GC set whenever an outgoing connection is used. This causes
the GC to be enforced on the context's death as well as on yield. First,
it does not appear necessary to do it when yielding, since if the
connections die they are already cleaned up. Second, the problem with
the flag is that even if a connection gets properly closed, the flag is
not removed and the GC continues to be called on the Lua context.

The impact on performance looks quite significant, as noticed and
diagnosed by Sadasiva Gujjarlapudi in the following thread:

  https://www.mail-archive.com/haproxy@formilux.org/msg35810.html

This patch changes the flag for a counter so that each created
connection increments it and each cleanly closed connection decrements
it. That way we know we have to call the GC on the context's death only
if the count is non-null. As reported in the thread above, the Lua
performance gain is now over 20% by doing this.

Thanks to Sada and Thierry for the design discussion and tests that
led to this solution.
diff --git a/include/types/hlua.h b/include/types/hlua.h
index fb1796c..6febee2 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -37,7 +37,7 @@
 #define HLUA_WAKERESWR 0x00000004
 #define HLUA_WAKEREQWR 0x00000008
 #define HLUA_EXIT      0x00000010
-#define HLUA_MUST_GC   0x00000020
+/* unused:   0x00000020 */
 #define HLUA_STOP      0x00000040
 
 #define HLUA_F_AS_STRING    0x01
@@ -93,6 +93,7 @@
 	struct list com; /* The list head of the signals attached to this task. */
 	struct ebpt_node node;
 	struct hlua_consistency cons; /* Store data consistency check. */
+	int gc_count;  /* number of items which need a GC */
 };
 
 /* This is a part of the list containing references to functions