summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 17:37:47 +0000
committersiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 17:37:47 +0000
commite9bb5b26b9d6308f4098a6b6b379c564a3b1f4be (patch)
treea9331b57a6bc71fd0d89830b6433a050a68a2317
parent5ae85c7ee970a6ae0dcf3f827931a3de6a0986ba (diff)
downloadchromium_src-e9bb5b26b9d6308f4098a6b6b379c564a3b1f4be.zip
chromium_src-e9bb5b26b9d6308f4098a6b6b379c564a3b1f4be.tar.gz
chromium_src-e9bb5b26b9d6308f4098a6b6b379c564a3b1f4be.tar.bz2
Make sure third_party/dmg_fp/dtoa.cc is compiled threadsafe.
BUG=64353 TEST=none Review URL: http://codereview.chromium.org/5321008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67414 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gypi2
-rw-r--r--base/third_party/dmg_fp/dtoa_wrapper.cc40
2 files changed, 41 insertions, 1 deletions
diff --git a/base/base.gypi b/base/base.gypi
index a7d1986..a71ccf4 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -14,8 +14,8 @@
'sources': [
'../build/build_config.h',
'third_party/dmg_fp/dmg_fp.h',
- 'third_party/dmg_fp/dtoa.cc',
'third_party/dmg_fp/g_fmt.cc',
+ 'third_party/dmg_fp/dtoa_wrapper.cc',
'third_party/icu/icu_utf.cc',
'third_party/icu/icu_utf.h',
'third_party/nspr/prtime.cc',
diff --git a/base/third_party/dmg_fp/dtoa_wrapper.cc b/base/third_party/dmg_fp/dtoa_wrapper.cc
new file mode 100644
index 0000000..fbbaf80
--- /dev/null
+++ b/base/third_party/dmg_fp/dtoa_wrapper.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// The purpose of this file is to supply the macro definintions necessary
+// to make third_party/dmg_fp/dtoa.cc threadsafe.
+#include "base/lock.h"
+#include "base/logging.h"
+
+// We need two locks because they're sometimes grabbed at the same time.
+// A single lock would lead to an attempted recursive grab.
+static Lock dtoa_locks[2];
+
+/*
+ * This define and the code below is to trigger thread-safe behavior
+ * in dtoa.cc, per this comment from the file:
+ *
+ * #define MULTIPLE_THREADS if the system offers preemptively scheduled
+ * multiple threads. In this case, you must provide (or suitably
+ * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
+ * in pow5mult, ensures lazy evaluation of only one copy of high
+ * powers of 5; omitting this lock would introduce a small
+ * probability of wasting memory, but would otherwise be harmless.)
+ * You must also invoke freedtoa(s) to free the value s returned by
+ * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
+ */
+#define MULTIPLE_THREADS
+
+inline static void ACQUIRE_DTOA_LOCK(size_t n) {
+ DCHECK(n < arraysize(dtoa_locks));
+ dtoa_locks[n].Acquire();
+}
+
+inline static void FREE_DTOA_LOCK(size_t n) {
+ DCHECK(n < arraysize(dtoa_locks));
+ dtoa_locks[n].Release();
+}
+
+#include "base/third_party/dmg_fp/dtoa.cc"