gfx/skia/trunk/src/ports/SkAtomics_android.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2013 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef SkAtomics_android_DEFINED
     9 #define SkAtomics_android_DEFINED
    11 /** Android framework atomics. */
    13 #include <cutils/atomic.h>
    14 #include <stdint.h>
    16 static inline __attribute__((always_inline)) int32_t sk_atomic_inc(int32_t* addr) {
    17     return android_atomic_inc(addr);
    18 }
    20 static inline __attribute__((always_inline)) int32_t sk_atomic_add(int32_t* addr, int32_t inc) {
    21     return android_atomic_add(inc, addr);
    22 }
    24 static inline __attribute__((always_inline)) int32_t sk_atomic_dec(int32_t* addr) {
    25     return android_atomic_dec(addr);
    26 }
    28 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomic_dec() {
    29     //HACK: Android is actually using full memory barriers.
    30     //      Should this change, uncomment below.
    31     //int dummy;
    32     //android_atomic_acquire_store(0, &dummy);
    33 }
    35 static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(int32_t* addr) {
    36     while (true) {
    37         int32_t value = *addr;
    38         if (value == 0) {
    39             return 0;
    40         }
    41         if (0 == android_atomic_release_cas(value, value + 1, addr)) {
    42             return value;
    43         }
    44     }
    45 }
    47 static inline __attribute__((always_inline)) bool sk_atomic_cas(int32_t* addr,
    48                                                                  int32_t before,
    49                                                                  int32_t after) {
    50     // android_atomic_release_cas returns 0 for success (if *addr == before and it wrote after).
    51     return android_atomic_release_cas(before, after, addr) == 0;
    52 }
    54 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomic_conditional_inc() {
    55     //HACK: Android is actually using full memory barriers.
    56     //      Should this change, uncomment below.
    57     //int dummy;
    58     //android_atomic_acquire_store(0, &dummy);
    59 }
    61 #endif

mercurial