Home | History | Annotate | Download | only in dmg_fp
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 //
      5 // The purpose of this file is to supply the macro definintions necessary
      6 // to make third_party/dmg_fp/dtoa.cc threadsafe.
      7 #include "base/synchronization/lock.h"
      8 #include "base/logging.h"
      9 
     10 // We need two locks because they're sometimes grabbed at the same time.
     11 // A single lock would lead to an attempted recursive grab.
     12 static base::Lock dtoa_locks[2];
     13 
     14 /*
     15  * This define and the code below is to trigger thread-safe behavior
     16  * in dtoa.cc, per this comment from the file:
     17  *
     18  * #define MULTIPLE_THREADS if the system offers preemptively scheduled
     19  *	multiple threads.  In this case, you must provide (or suitably
     20  *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
     21  *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
     22  *	in pow5mult, ensures lazy evaluation of only one copy of high
     23  *	powers of 5; omitting this lock would introduce a small
     24  *	probability of wasting memory, but would otherwise be harmless.)
     25  *	You must also invoke freedtoa(s) to free the value s returned by
     26  *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
     27  */
     28 #define MULTIPLE_THREADS
     29 
     30 inline static void ACQUIRE_DTOA_LOCK(size_t n) {
     31   DCHECK(n < arraysize(dtoa_locks));
     32   dtoa_locks[n].Acquire();
     33 }
     34 
     35 inline static void FREE_DTOA_LOCK(size_t n) {
     36   DCHECK(n < arraysize(dtoa_locks));
     37   dtoa_locks[n].Release();
     38 }
     39 
     40 #include "base/third_party/dmg_fp/dtoa.cc"
     41