Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkAtomics_win_DEFINED |
michael@0 | 9 | #define SkAtomics_win_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | /** Windows Interlocked atomics. */ |
michael@0 | 12 | |
michael@0 | 13 | #include <intrin.h> |
michael@0 | 14 | #include <stdint.h> |
michael@0 | 15 | |
michael@0 | 16 | //MSDN says in order to declare an interlocked function for use as an |
michael@0 | 17 | //intrinsic, include intrin.h and put the function in a #pragma intrinsic |
michael@0 | 18 | //directive. |
michael@0 | 19 | //The pragma appears to be unnecessary, but doesn't hurt. |
michael@0 | 20 | #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDecrement) |
michael@0 | 21 | #pragma intrinsic(_InterlockedCompareExchange) |
michael@0 | 22 | |
michael@0 | 23 | static inline int32_t sk_atomic_inc(int32_t* addr) { |
michael@0 | 24 | // InterlockedIncrement returns the new value, we want to return the old. |
michael@0 | 25 | return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) { |
michael@0 | 29 | return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<long>(inc)); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | static inline int32_t sk_atomic_dec(int32_t* addr) { |
michael@0 | 33 | // InterlockedDecrement returns the new value, we want to return the old. |
michael@0 | 34 | return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | static inline void sk_membar_acquire__after_atomic_dec() { } |
michael@0 | 38 | |
michael@0 | 39 | static inline int32_t sk_atomic_conditional_inc(int32_t* addr) { |
michael@0 | 40 | long value = *addr; |
michael@0 | 41 | while (true) { |
michael@0 | 42 | if (value == 0) { |
michael@0 | 43 | return 0; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | long before = _InterlockedCompareExchange(reinterpret_cast<long*>(addr), value + 1, value); |
michael@0 | 47 | |
michael@0 | 48 | if (before == value) { |
michael@0 | 49 | return value; |
michael@0 | 50 | } else { |
michael@0 | 51 | value = before; |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { |
michael@0 | 57 | return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, before) == before; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | static inline void sk_membar_acquire__after_atomic_conditional_inc() { } |
michael@0 | 61 | |
michael@0 | 62 | #endif |