diff --git a/chrome/updater/configurator.h b/chrome/updater/configurator.h index 9478dc709ec5..fac34279496f 100644 --- a/chrome/updater/configurator.h +++ b/chrome/updater/configurator.h @@ -20,6 +20,10 @@ #include "components/update_client/configurator.h" #include "components/update_client/persisted_data.h" +#if defined(STARBOARD) +#include "starboard/atomic.h" +#endif + class GURL; class PrefService; diff --git a/starboard/atomic.h b/starboard/atomic.h index 036eb3492dd8..f5f1632a1965 100644 --- a/starboard/atomic.h +++ b/starboard/atomic.h @@ -26,6 +26,10 @@ #include "starboard/configuration.h" #include "starboard/types.h" +#ifndef __cplusplus +#error "This header should not be included in C source code" +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/starboard/nplb/include_all.c b/starboard/nplb/include_all.c index 6f576ef72662..d5ae969fa402 100644 --- a/starboard/nplb/include_all.c +++ b/starboard/nplb/include_all.c @@ -14,7 +14,6 @@ // Includes all headers in a C context to make sure they compile as C files. -#include "starboard/atomic.h" #include "starboard/audio_sink.h" #include "starboard/configuration.h" #include "starboard/cpu_features.h" diff --git a/third_party/boringssl/src/crypto/internal.h b/third_party/boringssl/src/crypto/internal.h index 52787aa882f4..057927543650 100644 --- a/third_party/boringssl/src/crypto/internal.h +++ b/third_party/boringssl/src/crypto/internal.h @@ -121,7 +121,6 @@ #ifdef STARBOARD #include -#include "starboard/atomic.h" #include "starboard/thread.h" #endif @@ -606,7 +605,7 @@ OPENSSL_EXPORT int CRYPTO_refcount_dec_and_test_zero(CRYPTO_refcount_t *count); #if defined(STARBOARD) struct CRYPTO_STATIC_MUTEX { - SbAtomic32 initialized; + uint32_t initialized; CRYPTO_MUTEX mutex; }; #define CRYPTO_STATIC_MUTEX_INIT { 0 } diff --git a/third_party/boringssl/src/crypto/refcount_starboard.c b/third_party/boringssl/src/crypto/refcount_starboard.c index 27c5e54bce57..869fcf1b0bb2 100644 --- a/third_party/boringssl/src/crypto/refcount_starboard.c +++ b/third_party/boringssl/src/crypto/refcount_starboard.c @@ -18,24 +18,20 @@ #if defined(STARBOARD) -#include "starboard/atomic.h" - void CRYPTO_refcount_inc(CRYPTO_refcount_t *count) { - CRYPTO_refcount_t expected = SbAtomicNoBarrier_Load(count); + CRYPTO_refcount_t expected = __atomic_load_n(count, __ATOMIC_RELAXED); while (expected != CRYPTO_REFCOUNT_MAX) { CRYPTO_refcount_t new_value = expected + 1; - CRYPTO_refcount_t old_value = SbAtomicNoBarrier_CompareAndSwap( - count, expected, new_value); - if (old_value == expected) { + if (__atomic_compare_exchange_n(count, &expected, new_value, false, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { break; } - expected = old_value; } } int CRYPTO_refcount_dec_and_test_zero(CRYPTO_refcount_t *count) { - CRYPTO_refcount_t expected = SbAtomicNoBarrier_Load(count); + CRYPTO_refcount_t expected = __atomic_load_n(count, __ATOMIC_RELAXED); for (;;) { if (expected == 0) { @@ -44,12 +40,10 @@ int CRYPTO_refcount_dec_and_test_zero(CRYPTO_refcount_t *count) { return 0; } else { CRYPTO_refcount_t new_value = expected - 1; - CRYPTO_refcount_t old_value = SbAtomicNoBarrier_CompareAndSwap( - count, expected, new_value); - if (old_value == expected) { + if (__atomic_compare_exchange_n(count, &expected, new_value, false, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { return new_value == 0; } - expected = old_value; } } } diff --git a/third_party/boringssl/src/crypto/thread_starboard.cc b/third_party/boringssl/src/crypto/thread_starboard.cc index 413615d5d9f9..0820a6506bb7 100644 --- a/third_party/boringssl/src/crypto/thread_starboard.cc +++ b/third_party/boringssl/src/crypto/thread_starboard.cc @@ -62,16 +62,18 @@ void EnsureInitialized(struct CRYPTO_STATIC_MUTEX* lock) { kInitialized }; - if (SbAtomicNoBarrier_Load(&lock->initialized) == kInitialized) { + if (__atomic_load_n(&lock->initialized, __ATOMIC_RELAXED) == kInitialized) { return; } - if (SbAtomicNoBarrier_CompareAndSwap(&lock->initialized, - kUninitialized, kInitializing) == kUninitialized) { + + uint32_t expected = kUninitialized; + if (__atomic_compare_exchange_n(&lock->initialized, &expected, kInitializing, + false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { CRYPTO_MUTEX_init(&lock->mutex); - SbAtomicNoBarrier_Store(&lock->initialized, kInitialized); + __atomic_store_n(&lock->initialized, kInitialized, __ATOMIC_RELAXED); return; } - while (SbAtomicNoBarrier_Load(&lock->initialized) != kInitialized) { + while (__atomic_load_n(&lock->initialized, __ATOMIC_RELAXED) != kInitialized) { usleep(1000); // 1ms } } diff --git a/third_party/boringssl/src/include/openssl/thread.h b/third_party/boringssl/src/include/openssl/thread.h index 6e4b72ff1e07..738bfa38f12d 100644 --- a/third_party/boringssl/src/include/openssl/thread.h +++ b/third_party/boringssl/src/include/openssl/thread.h @@ -61,10 +61,6 @@ #include -#ifdef STARBOARD -#include "starboard/atomic.h" -#endif - #if defined(__cplusplus) extern "C" { #endif @@ -114,11 +110,7 @@ typedef union crypto_mutex_st { // as C code that might not set -std=c11. So, in practice, it's not possible to // do that. Instead we statically assert that the size and native alignment of // a plain uint32_t and an _Atomic uint32_t are equal in refcount_c11.c. -#if defined(STARBOARD) -typedef SbAtomic32 CRYPTO_refcount_t; -#else typedef uint32_t CRYPTO_refcount_t; -#endif // Deprecated functions.