components/desktop/thunderbird/patches/firefox-51-atomicops.patch
changeset 7018 fdf447a07aff
parent 7017 25872950aa80
child 7020 58ca1f0fa3a7
equal deleted inserted replaced
7017:25872950aa80 7018:fdf447a07aff
     1 Fixes issues in atomic operations. 
       
     2 Will not send upstream. 
       
     3  
       
     4 --- a/toolkit/components/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h	2015-11-03 11:34:16.000000000 +0100
       
     5 +++ b/toolkit/components/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h	2015-11-10 04:19:53.044083000 +0100
       
     6 @@ -1,5 +1,4 @@
       
     7 -// Copyright 2014 Google Inc. All rights reserved.
       
     8 -// https://developers.google.com/protocol-buffers/
       
     9 +// Copyright 2013 Red Hat Inc.  All rights reserved.
       
    10  //
       
    11  // Redistribution and use in source and binary forms, with or without
       
    12  // modification, are permitted provided that the following conditions are
       
    13 @@ -11,7 +10,7 @@
       
    14  // copyright notice, this list of conditions and the following disclaimer
       
    15  // in the documentation and/or other materials provided with the
       
    16  // distribution.
       
    17 -//     * Neither the name of Google Inc. nor the names of its
       
    18 +//     * Neither the name of Red Hat Inc. nor the names of its
       
    19  // contributors may be used to endorse or promote products derived from
       
    20  // this software without specific prior written permission.
       
    21  //
       
    22 @@ -29,10 +28,8 @@
       
    23  
       
    24  // This file is an internal atomic implementation, use atomicops.h instead.
       
    25  
       
    26 -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_
       
    27 -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_
       
    28 -
       
    29 -#include <atomic.h>
       
    30 +#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_
       
    31 +#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_
       
    32  
       
    33  namespace google {
       
    34  namespace protobuf {
       
    35 @@ -41,148 +38,100 @@
       
    36  inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
       
    37                                           Atomic32 old_value,
       
    38                                           Atomic32 new_value) {
       
    39 -  return (Atomic32)atomic_cas_32((volatile uint32_t*)ptr, (uint32_t)old_value, (uint32_t)new_value);
       
    40 +  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
       
    41 +                              __ATOMIC_RELAXED, __ATOMIC_RELAXED);
       
    42 +  return old_value;
       
    43  }
       
    44  
       
    45  inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
       
    46                                           Atomic32 new_value) {
       
    47 -  return (Atomic32)atomic_swap_32((volatile uint32_t*)ptr, (uint32_t)new_value);
       
    48 +  return __atomic_exchange_n(ptr, new_value, __ATOMIC_RELAXED);
       
    49  }
       
    50  
       
    51  inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
       
    52                                            Atomic32 increment) {
       
    53 -  return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment);
       
    54 -}
       
    55 -
       
    56 -inline void MemoryBarrier(void) {
       
    57 -	membar_producer();
       
    58 -	membar_consumer();
       
    59 +  return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED);
       
    60  }
       
    61  
       
    62  inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
       
    63                                          Atomic32 increment) {
       
    64 -  MemoryBarrier();
       
    65 -  Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment);
       
    66 -  MemoryBarrier();
       
    67 -
       
    68 -  return ret;
       
    69 +  return __atomic_add_fetch(ptr, increment, __ATOMIC_SEQ_CST);
       
    70  }
       
    71  
       
    72  inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
       
    73                                         Atomic32 old_value,
       
    74                                         Atomic32 new_value) {
       
    75 -  Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
       
    76 -  MemoryBarrier();
       
    77 -
       
    78 -  return ret;
       
    79 +  __atomic_compare_exchange(ptr, &old_value, &new_value, true,
       
    80 +                            __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
       
    81 +  return old_value;
       
    82  }
       
    83  
       
    84  inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
       
    85                                         Atomic32 old_value,
       
    86                                         Atomic32 new_value) {
       
    87 -  MemoryBarrier();
       
    88 -  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
       
    89 +  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
       
    90 +                              __ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
       
    91 +  return old_value;
       
    92  }
       
    93  
       
    94  inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
       
    95 -  *ptr = value;
       
    96 +  __atomic_store_n(ptr, value, __ATOMIC_RELAXED);
       
    97 +}
       
    98 +
       
    99 +inline void MemoryBarrier() {
       
   100 +  __sync_synchronize();
       
   101  }
       
   102  
       
   103  inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
       
   104 -  *ptr = value;
       
   105 -  membar_producer();
       
   106 +  __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST);
       
   107  }
       
   108  
       
   109  inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
       
   110 -  membar_consumer();
       
   111 -  *ptr = value;
       
   112 +  __atomic_store_n(ptr, value, __ATOMIC_RELEASE);
       
   113  }
       
   114  
       
   115  inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
       
   116 -  return *ptr;
       
   117 +  return __atomic_load_n(ptr, __ATOMIC_RELAXED);
       
   118  }
       
   119  
       
   120  inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
       
   121 -  Atomic32 val = *ptr;
       
   122 -  membar_consumer();
       
   123 -  return val;
       
   124 +  return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
       
   125  }
       
   126  
       
   127  inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
       
   128 -  membar_producer();
       
   129 -  return *ptr;
       
   130 +  return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
       
   131  }
       
   132  
       
   133 -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT
       
   134 -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
       
   135 -                                         Atomic64 old_value,
       
   136 -                                         Atomic64 new_value) {
       
   137 -  return atomic_cas_64((volatile uint64_t*)ptr, (uint64_t)old_value, (uint64_t)new_value);
       
   138 -}
       
   139 +#ifdef __LP64__
       
   140  
       
   141 -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value) {
       
   142 -  return atomic_swap_64((volatile uint64_t*)ptr, (uint64_t)new_value);
       
   143 -}
       
   144 -
       
   145 -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
       
   146 -  return atomic_add_64_nv((volatile uint64_t*)ptr, increment);
       
   147 +inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
       
   148 +  __atomic_store_n(ptr, value, __ATOMIC_RELEASE);
       
   149  }
       
   150  
       
   151 -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
       
   152 -  MemoryBarrier();
       
   153 -  Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment);
       
   154 -  MemoryBarrier();
       
   155 -  return ret;
       
   156 +inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
       
   157 +  return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
       
   158  }
       
   159  
       
   160  inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
       
   161                                         Atomic64 old_value,
       
   162                                         Atomic64 new_value) {
       
   163 -  Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
       
   164 -  MemoryBarrier();
       
   165 -  return ret;
       
   166 +  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
       
   167 +                              __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
       
   168 +  return old_value;
       
   169  }
       
   170  
       
   171 -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
       
   172 +inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
       
   173                                         Atomic64 old_value,
       
   174                                         Atomic64 new_value) {
       
   175 -  MemoryBarrier();
       
   176 -  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
       
   177 -}
       
   178 -
       
   179 -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
       
   180 -  *ptr = value;
       
   181 -}
       
   182 -
       
   183 -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
       
   184 -  *ptr = value;
       
   185 -  membar_producer();
       
   186 +  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
       
   187 +                              __ATOMIC_RELAXED, __ATOMIC_RELAXED);
       
   188 +  return old_value;
       
   189  }
       
   190  
       
   191 -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
       
   192 -  membar_consumer();
       
   193 -  *ptr = value;
       
   194 -}
       
   195 -
       
   196 -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
       
   197 -  return *ptr;
       
   198 -}
       
   199 -
       
   200 -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
       
   201 -  Atomic64 ret = *ptr;
       
   202 -  membar_consumer();
       
   203 -  return ret;
       
   204 -}
       
   205 -
       
   206 -inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
       
   207 -  membar_producer();
       
   208 -  return *ptr;
       
   209 -}
       
   210 -#endif
       
   211 +#endif // defined(__LP64__)
       
   212  
       
   213  }  // namespace internal
       
   214  }  // namespace protobuf
       
   215  }  // namespace google
       
   216  
       
   217 -#endif  // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_
       
   218 -
       
   219 +#endif  // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_