forked from nihui/opencv-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv-4.5.3-unsafe-xadd.patch
38 lines (35 loc) · 2.08 KB
/
opencv-4.5.3-unsafe-xadd.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
diff -Nuarp opencv-4.5.3/modules/core/include/opencv2/core/cvdef.h opencv-4.5.3.unsafe_xadd/modules/core/include/opencv2/core/cvdef.h
--- opencv-4.5.3/modules/core/include/opencv2/core/cvdef.h 2021-07-05 05:03:22.000000000 +0800
+++ opencv-4.5.3.unsafe_xadd/modules/core/include/opencv2/core/cvdef.h 2021-07-11 15:00:01.863669223 +0800
@@ -662,33 +662,7 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumTy
* exchange-add operation for atomic operations on reference counters *
\****************************************************************************************/
-#ifdef CV_XADD
- // allow to use user-defined macro
-#elif defined __GNUC__ || defined __clang__
-# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER
-# ifdef __ATOMIC_ACQ_REL
-# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
-# else
-# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
-# endif
-# else
-# if defined __ATOMIC_ACQ_REL && !defined __clang__
- // version for gcc >= 4.7
-# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
-# else
-# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
-# endif
-# endif
-#elif defined _MSC_VER && !defined RC_INVOKED
-# include <intrin.h>
-# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
-#else
- #ifdef OPENCV_FORCE_UNSAFE_XADD
- CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
- #else
- #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)"
- #endif
-#endif
+CV_INLINE int CV_XADD(void* addr, int delta) { int tmp = *(int*)addr; *(int*)addr += delta; return tmp; }
/****************************************************************************************\