⬢ DragonFlyBSD Kernel Audit
DF-2225 / fix.diff
← back to finding ↓ download raw
--- a/sys/libprop/prop_object_impl.h
+++ b/sys/libprop/prop_object_impl.h
@@ -300,7 +300,17 @@
 #define	_PROP_RWLOCK_DESTROY(x)		mtx_uninit(&(x))
 
 #define _PROP_ONCE_DECL(x)		static int x = 0;
-#define _PROP_ONCE_RUN(x,f)		if (atomic_cmpset_int(&(x), 0, 1)) f()
+#define	_PROP_ONCE_RUN(x,f)						\
+do {									\
+	if (atomic_cmpset_int(&(x), 0, 1)) {				\
+		f();							\
+		atomic_store_rel_int(&(x), 2);				\
+	} else {							\
+		/* f() has been started but not finished: wait */	\
+		while (atomic_load_acq_int(&(x)) != 2)			\
+			cpu_pause();					\
+	}								\
+} while (0)
 
 #elif defined(_STANDALONE)