Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/memory/singleton.h" |
michael@0 | 6 | #include "base/threading/platform_thread.h" |
michael@0 | 7 | |
michael@0 | 8 | namespace base { |
michael@0 | 9 | namespace internal { |
michael@0 | 10 | |
michael@0 | 11 | subtle::AtomicWord WaitForInstance(subtle::AtomicWord* instance) { |
michael@0 | 12 | // Handle the race. Another thread beat us and either: |
michael@0 | 13 | // - Has the object in BeingCreated state |
michael@0 | 14 | // - Already has the object created... |
michael@0 | 15 | // We know value != NULL. It could be kBeingCreatedMarker, or a valid ptr. |
michael@0 | 16 | // Unless your constructor can be very time consuming, it is very unlikely |
michael@0 | 17 | // to hit this race. When it does, we just spin and yield the thread until |
michael@0 | 18 | // the object has been created. |
michael@0 | 19 | subtle::AtomicWord value; |
michael@0 | 20 | while (true) { |
michael@0 | 21 | value = subtle::NoBarrier_Load(instance); |
michael@0 | 22 | if (value != kBeingCreatedMarker) |
michael@0 | 23 | break; |
michael@0 | 24 | PlatformThread::YieldCurrentThread(); |
michael@0 | 25 | } |
michael@0 | 26 | return value; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | } // namespace internal |
michael@0 | 30 | } // namespace base |
michael@0 | 31 |