RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   27-Feb-2016 22:14:40
  Branch: rpm-5_4                          Handle: 2016022721144000

  Modified files:           (Branch: rpm-5_4)
    rpm/rpmio               bson.c bson.h

  Log:
    Some architectures do not have __sync_add_and_fetch_8 implemented.
    
    MIPS (32-bit) and some PPC systems do not have sync_add_and_fetch_8.
    
    Provide an alternative.  This alternative function is based on code from:
      https://github.com/mongodb/libbson/blob/master/src/bson/bson-atomic.c
    
    Code is under an Apache 2.0 License.
    
    Upstream-Status: Pending
    
    Signed-off-by: Mark Hatle <mark.ha...@windriver.com>

  Summary:
    Revision    Changes     Path
    2.4.4.14    +19 -2      rpm/rpmio/bson.c
    2.3.4.13    +9  -1      rpm/rpmio/bson.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/bson.c
  ============================================================================
  $ cvs diff -u -r2.4.4.13 -r2.4.4.14 bson.c
  --- rpm/rpmio/bson.c  16 May 2015 20:17:12 -0000      2.4.4.13
  +++ rpm/rpmio/bson.c  27 Feb 2016 21:14:40 -0000      2.4.4.14
  @@ -3863,13 +3863,30 @@
   #elif defined BSON_OS_WIN32
      uint64_t seq = InterlockedIncrement64 ((int64_t *)&context->seq64);
   #else
  -   uint64_t seq = __sync_fetch_and_add_8 (&context->seq64, 1);
  +   uint64_t seq = bson_atomic_int64_add (&context->seq64, 1);
   #endif
   
      seq = BSON_UINT64_TO_BE (seq);
      memcpy (&oid->bytes[4], &seq, 8);
   }
   
  +#ifdef __BSON_NEED_ATOMIC_64
  +#include <pthread.h>
  +static pthread_mutex_t gSync64 = PTHREAD_MUTEX_INITIALIZER;
  +int64_t
  +bson_atomic_int64_add (volatile int64_t *p,
  +                       int64_t           n)
  +{
  +   int64_t ret;
  +
  +   pthread_mutex_lock (&gSync64);
  +   *p += n;
  +   ret = *p;
  +   pthread_mutex_unlock (&gSync64);
  +
  +   return ret;
  +}
  +#endif
   
   /**
    * bson_context_new:
  @@ -7805,7 +7822,7 @@
     gh...@aladdin.com
   
    */
  -/* $Id: bson.c,v 2.4.4.13 2015/05/16 20:17:12 jbj Exp $ */
  +/* $Id: bson.c,v 2.4.4.14 2016/02/27 21:14:40 jbj Exp $ */
   /*
     Independent implementation of MD5 (RFC 1321).
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/bson.h
  ============================================================================
  $ cvs diff -u -r2.3.4.12 -r2.3.4.13 bson.h
  --- rpm/rpmio/bson.h  6 Oct 2014 19:43:58 -0000       2.3.4.12
  +++ rpm/rpmio/bson.h  27 Feb 2016 21:14:40 -0000      2.3.4.13
  @@ -879,10 +879,18 @@
   
   BSON_BEGIN_DECLS
   
  +/* Some architectures do not support __sync_add_and_fetch_8 */
  +#if (__mips == 32) || (defined(__PPC__) && 
!defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8))
  +# define __BSON_NEED_ATOMIC_64 1
  +#endif
   
   #if defined(__GNUC__)
   # define bson_atomic_int_add(p, v)   (__sync_add_and_fetch(p, v))
  -# define bson_atomic_int64_add(p, v) (__sync_add_and_fetch_8(p, v))
  +#ifndef __BSON_NEED_ATOMIC_64
  +#  define bson_atomic_int64_add(p, v) (__sync_add_and_fetch_8(p, v))
  +# else
  +   int64_t bson_atomic_int64_add (volatile int64_t *p, int64_t n);
  +# endif
   # define bson_memory_barrier         __sync_synchronize
   #elif defined(_MSC_VER) || defined(_WIN32)
   # define bson_atomic_int_add(p, v)   (InterlockedExchangeAdd((long int 
*)(p), v))
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to