| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // The purpose of this file is to supply the macro definintions necessary | 5 // The purpose of this file is to supply the macro definintions necessary |
| 6 // to make third_party/dmg_fp/dtoa.cc threadsafe. | 6 // to make third_party/dmg_fp/dtoa.cc threadsafe. |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 | 10 |
| 11 // We need two locks because they're sometimes grabbed at the same time. | 11 // We need two locks because they're sometimes grabbed at the same time. |
| 12 // A single lock would lead to an attempted recursive grab. | 12 // A single lock would lead to an attempted recursive grab. |
| 13 static base::LazyInstance<base::Lock, | 13 static base::LazyInstance<base::Lock, |
| 14 base::LeakyLazyInstanceTraits<base::Lock> > | 14 base::LeakyLazyInstanceTraits<base::Lock> > |
| 15 dtoa_lock_0(base::LINKER_INITIALIZED); | 15 dtoa_lock_0 = LAZY_INSTANCE_INITIALIZER; |
| 16 static base::LazyInstance<base::Lock, | 16 static base::LazyInstance<base::Lock, |
| 17 base::LeakyLazyInstanceTraits<base::Lock> > | 17 base::LeakyLazyInstanceTraits<base::Lock> > |
| 18 dtoa_lock_1(base::LINKER_INITIALIZED); | 18 dtoa_lock_1 = LAZY_INSTANCE_INITIALIZER; |
| 19 | 19 |
| 20 /* | 20 /* |
| 21 * This define and the code below is to trigger thread-safe behavior | 21 * This define and the code below is to trigger thread-safe behavior |
| 22 * in dtoa.cc, per this comment from the file: | 22 * in dtoa.cc, per this comment from the file: |
| 23 * | 23 * |
| 24 * #define MULTIPLE_THREADS if the system offers preemptively scheduled | 24 * #define MULTIPLE_THREADS if the system offers preemptively scheduled |
| 25 * multiple threads. In this case, you must provide (or suitably | 25 * multiple threads. In this case, you must provide (or suitably |
| 26 * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed | 26 * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed |
| 27 * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed | 27 * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed |
| 28 * in pow5mult, ensures lazy evaluation of only one copy of high | 28 * in pow5mult, ensures lazy evaluation of only one copy of high |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 lock->Acquire(); | 39 lock->Acquire(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 inline static void FREE_DTOA_LOCK(size_t n) { | 42 inline static void FREE_DTOA_LOCK(size_t n) { |
| 43 DCHECK(n < 2); | 43 DCHECK(n < 2); |
| 44 base::Lock* lock = n == 0 ? dtoa_lock_0.Pointer() : dtoa_lock_1.Pointer(); | 44 base::Lock* lock = n == 0 ? dtoa_lock_0.Pointer() : dtoa_lock_1.Pointer(); |
| 45 lock->Release(); | 45 lock->Release(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 #include "base/third_party/dmg_fp/dtoa.cc" | 48 #include "base/third_party/dmg_fp/dtoa.cc" |
| OLD | NEW |