Merge branch 'mainstream'
[sliver-openvswitch.git] / lib / vlog.h
index ff93d30..9576687 100644 (file)
 #ifndef VLOG_H
 #define VLOG_H 1
 
+/* Logging.
+ *
+ *
+ * Thread-safety
+ * =============
+ *
+ * Fully thread safe.
+ */
+
 #include <limits.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -132,7 +141,6 @@ int vlog_reopen_log_file(void);
 
 /* Initialization. */
 void vlog_init(void);
-void vlog_exit(void);
 
 /* Functions for actual logging. */
 void vlog(const struct vlog_module *, enum vlog_level, const char *format, ...)
@@ -232,13 +240,13 @@ void vlog_usage(void);
             vlog_rate_limit(THIS_MODULE, level__, RL, __VA_ARGS__); \
         }                                                           \
     } while (0)
-#define VLOG_ONCE(LEVEL, ...)                       \
-    do {                                            \
-        static bool already_logged;                 \
-        if (!already_logged) {                      \
-            already_logged = true;                  \
-            vlog(THIS_MODULE, LEVEL, __VA_ARGS__);  \
-        }                                           \
+#define VLOG_ONCE(LEVEL, ...)                                           \
+    do {                                                                \
+        static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; \
+        if (ovsthread_once_start(&once)) {                              \
+            vlog(THIS_MODULE, LEVEL, __VA_ARGS__);                      \
+            ovsthread_once_done(&once);                                 \
+        }                                                               \
     } while (0)
 
 #define VLOG_DEFINE_MODULE__(MODULE)                                    \