diff options
Diffstat (limited to 'meta/recipes-devtools/rpm/rpm/rpm-atomic-ops.patch')
-rw-r--r-- | meta/recipes-devtools/rpm/rpm/rpm-atomic-ops.patch | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rpm/rpm/rpm-atomic-ops.patch b/meta/recipes-devtools/rpm/rpm/rpm-atomic-ops.patch new file mode 100644 index 0000000000..c6327719d9 --- /dev/null +++ b/meta/recipes-devtools/rpm/rpm/rpm-atomic-ops.patch | |||
@@ -0,0 +1,73 @@ | |||
1 | Some architectures do not have __sync_add_and_fetch_8 implemented. | ||
2 | |||
3 | MIPS (32-bit) and some PPC systems do not have sync_add_and_fetch_8. | ||
4 | |||
5 | Provide an alternative. This alternative function is based on code from: | ||
6 | https://github.com/mongodb/libbson/blob/master/src/bson/bson-atomic.c | ||
7 | |||
8 | Code is under an Apache 2.0 License. | ||
9 | |||
10 | Upstream-Status: Pending | ||
11 | |||
12 | Signed-off-by: Mark Hatle <mark.hatle@windriver.com> | ||
13 | |||
14 | Index: rpm-5.4.15/rpmio/bson.h | ||
15 | =================================================================== | ||
16 | --- rpm-5.4.15.orig/rpmio/bson.h | ||
17 | +++ rpm-5.4.15/rpmio/bson.h | ||
18 | @@ -879,10 +879,18 @@ BSON_END_DECLS | ||
19 | |||
20 | BSON_BEGIN_DECLS | ||
21 | |||
22 | +/* Some architectures do not support __sync_add_and_fetch_8 */ | ||
23 | +#if (__mips == 32) || (defined(__PPC__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) | ||
24 | +# define __BSON_NEED_ATOMIC_64 1 | ||
25 | +#endif | ||
26 | |||
27 | #if defined(__GNUC__) | ||
28 | # define bson_atomic_int_add(p, v) (__sync_add_and_fetch(p, v)) | ||
29 | -# define bson_atomic_int64_add(p, v) (__sync_add_and_fetch_8(p, v)) | ||
30 | +#ifndef __BSON_NEED_ATOMIC_64 | ||
31 | +# define bson_atomic_int64_add(p, v) (__sync_add_and_fetch_8(p, v)) | ||
32 | +# else | ||
33 | + int64_t bson_atomic_int64_add (volatile int64_t *p, int64_t n); | ||
34 | +# endif | ||
35 | # define bson_memory_barrier __sync_synchronize | ||
36 | #elif defined(_MSC_VER) || defined(_WIN32) | ||
37 | # define bson_atomic_int_add(p, v) (InterlockedExchangeAdd((long int *)(p), v)) | ||
38 | Index: rpm-5.4.15/rpmio/bson.c | ||
39 | =================================================================== | ||
40 | --- rpm-5.4.15.orig/rpmio/bson.c | ||
41 | +++ rpm-5.4.15/rpmio/bson.c | ||
42 | @@ -3863,13 +3863,30 @@ _bson_context_get_oid_seq64_threadsafe ( | ||
43 | #elif defined BSON_OS_WIN32 | ||
44 | uint64_t seq = InterlockedIncrement64 ((int64_t *)&context->seq64); | ||
45 | #else | ||
46 | - uint64_t seq = __sync_fetch_and_add_8 (&context->seq64, 1); | ||
47 | + uint64_t seq = bson_atomic_int64_add (&context->seq64, 1); | ||
48 | #endif | ||
49 | |||
50 | seq = BSON_UINT64_TO_BE (seq); | ||
51 | memcpy (&oid->bytes[4], &seq, 8); | ||
52 | } | ||
53 | |||
54 | +#ifdef __BSON_NEED_ATOMIC_64 | ||
55 | +#include <pthread.h> | ||
56 | +static pthread_mutex_t gSync64 = PTHREAD_MUTEX_INITIALIZER; | ||
57 | +int64_t | ||
58 | +bson_atomic_int64_add (volatile int64_t *p, | ||
59 | + int64_t n) | ||
60 | +{ | ||
61 | + int64_t ret; | ||
62 | + | ||
63 | + pthread_mutex_lock (&gSync64); | ||
64 | + *p += n; | ||
65 | + ret = *p; | ||
66 | + pthread_mutex_unlock (&gSync64); | ||
67 | + | ||
68 | + return ret; | ||
69 | +} | ||
70 | +#endif | ||
71 | |||
72 | /** | ||
73 | * bson_context_new: | ||