浏览代码

Add atomic increment/decrement platform funcs

jp9000 11 年之前
父节点
当前提交
bb92d582bf
共有 3 个文件被更改,包括 23 次插入1 次删除
  1. 10 0
      libobs/util/platform-nix.c
  2. 10 1
      libobs/util/platform-windows.c
  3. 3 0
      libobs/util/platform.h

+ 10 - 0
libobs/util/platform-nix.c

@@ -116,3 +116,13 @@ int os_mkdir(const char *path)
 
 	return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR;
 }
+
+long atomic_inc_long(volatile long *val)
+{
+	return __sync_fetch_and_add(val, 1);
+}
+
+long atomic_dec_long(volatile long *val)
+{
+	return __sync_fetch_and_sub(val, 1);
+}

+ 10 - 1
libobs/util/platform-windows.c

@@ -185,6 +185,16 @@ int os_mkdir(const char *path)
 	return MKDIR_SUCCESS;
 }
 
+long atomic_inc_long(volatile long *val)
+{
+	return InterlockedIncrement(val);
+}
+
+long atomic_dec_long(volatile long *val)
+{
+	return InterlockedDecrement(val);
+}
+
 
 BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
 {
@@ -219,4 +229,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
 
 	return true;
 }
-

+ 3 - 0
libobs/util/platform.h

@@ -76,6 +76,9 @@ EXPORT char *os_get_config_path(const char *name);
 
 EXPORT bool os_file_exists(const char *path);
 
+EXPORT long atomic_inc_long(volatile long *val);
+EXPORT long atomic_dec_long(volatile long *val);
+
 #define MKDIR_EXISTS   1
 #define MKDIR_SUCCESS  0
 #define MKDIR_ERROR   -1