gfx/skia/trunk/src/ports/SkAtomics_win.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_win_DEFINED
     9 #define SkAtomics_win_DEFINED
    11 /** Windows Interlocked atomics. */
    13 #include <intrin.h>
    14 #include <stdint.h>
    16 //MSDN says in order to declare an interlocked function for use as an
    17 //intrinsic, include intrin.h and put the function in a #pragma intrinsic
    18 //directive.
    19 //The pragma appears to be unnecessary, but doesn't hurt.
    20 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDecrement)
    21 #pragma intrinsic(_InterlockedCompareExchange)
    23 static inline int32_t sk_atomic_inc(int32_t* addr) {
    24     // InterlockedIncrement returns the new value, we want to return the old.
    25     return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1;
    26 }
    28 static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) {
    29     return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<long>(inc));
    30 }
    32 static inline int32_t sk_atomic_dec(int32_t* addr) {
    33     // InterlockedDecrement returns the new value, we want to return the old.
    34     return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1;
    35 }
    37 static inline void sk_membar_acquire__after_atomic_dec() { }
    39 static inline int32_t sk_atomic_conditional_inc(int32_t* addr) {
    40     long value = *addr;
    41     while (true) {
    42         if (value == 0) {
    43             return 0;
    44         }
    46         long before = _InterlockedCompareExchange(reinterpret_cast<long*>(addr), value + 1, value);
    48         if (before == value) {
    49             return value;
    50         } else {
    51             value = before;
    52         }
    53     }
    54 }
    56 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) {
    57     return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, before) == before;
    58 }
    60 static inline void sk_membar_acquire__after_atomic_conditional_inc() { }
    62 #endif

mercurial