Browse Source

libobs/util: Add atomic bool load functions

jp9000 10 years ago
parent
commit
598ae383bc
3 changed files with 11 additions and 0 deletions
  1. 5 0
      libobs/util/threading-posix.c
  2. 5 0
      libobs/util/threading-windows.c
  3. 1 0
      libobs/util/threading.h

+ 5 - 0
libobs/util/threading-posix.c

@@ -266,6 +266,11 @@ bool os_atomic_set_bool(volatile bool *ptr, bool val)
 	return __sync_lock_test_and_set(ptr, val);
 }
 
+bool os_atomic_load_bool(const volatile bool *ptr)
+{
+	return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
+}
+
 void os_set_thread_name(const char *name)
 {
 #if defined(__APPLE__)

+ 5 - 0
libobs/util/threading-windows.c

@@ -169,6 +169,11 @@ bool os_atomic_set_bool(volatile bool *ptr, bool val)
 	return (bool)InterlockedExchange8((volatile char*)ptr, (char)val);
 }
 
+bool os_atomic_load_bool(const volatile bool *ptr)
+{
+	return (bool)InterlockedOr8((volatile char*)ptr, 0);
+}
+
 #define VC_EXCEPTION 0x406D1388
 
 #pragma pack(push,8)

+ 1 - 0
libobs/util/threading.h

@@ -77,6 +77,7 @@ EXPORT bool os_atomic_compare_swap_long(volatile long *val,
 		long old_val, long new_val);
 
 EXPORT bool os_atomic_set_bool(volatile bool *ptr, bool val);
+EXPORT bool os_atomic_load_bool(const volatile bool *ptr);
 
 EXPORT void os_set_thread_name(const char *name);