Reland: Move files in wtf/ to platform/wtf/ (Part 12).
This relands the following patch with a fix:
http://crrev.com/2767153004#ps100001
> This patch moves all the remaining files (except tests) in wtf/:
>
> BloomFilter.h, ByteOrder.h, DateMath.{h,cpp}, FilePrintStream.cpp,
> InstanceCounter.cpp, PrintStream.cpp, RefVector.h,
> SaturatedArithmetic.h, SizeLimits.cpp, StackUtil.cpp,
> TerminatedArrayBuilder.h, TerminatedArray.h,
> ThreadingPthreads.cpp, ThreadingWin.cpp, ThreadSpecificWin.cpp,
> WTF.cpp, WTFThreadData.cpp, debug/Alias.h, debug/CrashLogging.h
>
> Additionally, miscellaneous documents are moved to the new location, and
> debug/DEPS is copied, too. UniquePtrTransitionGuide.md isn't moved, because
> the content is now mostly obsolete and it can be removed.
BUG=691465
Review-Url: https://codereview.chromium.org/2776933005
Cr-Original-Commit-Position: refs/heads/master@{#460699}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: ebab42ba798f9ca51aa9ff6e84884ded2799f632
diff --git a/Allocator.md b/Allocator.md
deleted file mode 100644
index a08e00d..0000000
--- a/Allocator.md
+++ /dev/null
@@ -1,186 +0,0 @@
-# Memory management in Blink
-
-This document gives a high-level overview of the memory management in Blink.
-
-[TOC]
-
-## Memory allocators
-
-Blink objects are allocated by one of the following four memory allocators.
-
-### Oilpan
-
-Oilpan is a garbage collection system in Blink.
-The lifetime of objects allocated by Oilpan is automatically managed.
-The following objects are allocated by Oilpan:
-
-* Objects that inherit from GarbageCollected<T> or GarbageCollectedFinalized<T>.
-
-* HeapVector<T>, HeapHashSet<T>, HeapHashMap<T, U> etc
-
-The implementation is in platform/heap/.
-See [BlinkGCDesign.md](../platform/heap/BlinkGCDesign.md) to learn the design.
-
-### PartitionAlloc
-
-PartitionAlloc is Blink's default memory allocator.
-PartitionAlloc is highly optimized for performance and security requirements
-in Blink. All Blink objects that don't need a GC or discardable memory should be
-allocated by PartitionAlloc (instead of malloc).
-The following objects are allocated by PartitionAlloc:
-
-* Objects that have a USING_FAST_MALLOC macro.
-
-* Nodes (which will be moved to Oilpan in the near future)
-
-* LayoutObjects
-
-* Strings, Vectors, HashTables, ArrayBuffers and other primitive containers.
-
-The implementation is in /base/allocator/partition_allocator.
-See [PartitionAlloc.md](/base/allocator/partition_allocator/PartitionAlloc.md)
-to learn the design.
-
-### Discardable memory
-
-Discardable memory is a memory allocator that automatically discards
-(not-locked) objects under memory pressure. Currently SharedBuffers
-(which are mainly used as backing storage of Resource objects) are the only
-user of the discardable memory.
-
-The implementation is in src/base/memory/discardable_memory.*.
-See [this document](https://docs.google.com/document/d/1aNdOF_72_eG2KUM_z9kHdbT_fEupWhaDALaZs5D8IAg/edit)
-to learn the design.
-
-### malloc
-
-When you simply call 'new' or 'malloc', the object is allocated by malloc.
-As mentioned above, malloc is discouraged and should be replaced with
-PartitionAlloc. PartitionAlloc is faster, securer and more instrumentable
-than malloc.
-
-The actual implementation of malloc is platform-dependent.
-As of 2015 Dec, Linux uses tcmalloc. Mac and Windows use their system allocator.
-Android uses device-dependent allocators such as dlmalloc.
-
-## Basic allocation rules
-
-In summary, Blink objects (except several special objects) should be allocated
-using Oilpan or PartitionAlloc. malloc is discouraged.
-
-The following is a basic rule to determine which of Oilpan or PartitionAlloc
-you should use when allocating a new object:
-
-* Use Oilpan if you want a GC to manage the lifetime of the object.
-You need to make the object inherit from GarbageCollected<T> or
-GarbageCollectedFinalized<T>. See
-[BlinkGCAPIReference.md](../platform/heap/BlinkGCAPIReference.md) to learn
-programming with Oilpan.
-
-```c++
-class X : public GarbageCollected<X> {
- ...;
-};
-
-void func() {
- X* x = new X; // This is allocated by Oilpan.
-}
-```
-
-* Use PartitionAlloc if you don't need a GC to manage the lifetime of
-the object (i.e., if RefPtr or OwnPtr is enough to manage the lifetime
-of the object). You need to add a USING_FAST_MALLOC macro to the object.
-
-```c++
-class X {
- USING_FAST_MALLOC(X);
- ...;
-};
-
-void func() {
- RefPtr<X> x = adoptRefPtr(new X); // This is allocated by PartitionAlloc.
-}
-```
-
-It is not a good idea to unnecessarily increase the number of objects
-managed by Oilpan. Although Oilpan implements an efficient GC, the more objects
-you allocate on Oilpan, the more pressure you put on Oilpan, leading to
-a longer pause time.
-
-Here is a guideline for when you ought to allocate an object using Oilpan,
-and when you probably shouldn't:
-
-* Use Oilpan for all script exposed objects (i.e., derives from
-ScriptWrappable).
-
-* Use Oilpan if managing its lifetime is usually simpler with Oilpan.
-But see the next bullet.
-
-* If the allocation rate of the object is very high, that may put unnecessary
-strain on the Oilpan's GC infrastructure as a whole. If so and the object can be
-allocated not using Oilpan without creating cyclic references or complex
-lifetime handling, then use PartitionAlloc. For example, we allocate Strings
-and LayoutObjects on PartitionAlloc.
-
-For objects that don't need an operator new, you need to use either of the
-following macros:
-
-* If the object is only stack allocated, use STACK_ALLOCATED().
-
-```c++
-class X {
- STACK_ALLOCATED();
- ...;
-};
-
-void func() {
- X x; // This is allowed.
- X* x2 = new X; // This is forbidden.
-}
-```
-
-* If the object can be allocated only as a part of object, use DISALLOW_NEW().
-
-```c++
-class X {
- DISALLOW_NEW();
- ...;
-};
-
-class Y {
- USING_FAST_MALLOC(Y);
- X m_x; // This is allowed.
-};
-
-void func() {
- X x; // This is allowed.
- X* x = new X; // This is forbidden.
-}
-```
-
-* If the object can be allocated only as a part of object or by a placement new
-(e.g., the object is used as a value object in a container),
-use DISALLOW_NEW_EXCEPT_PLACEMENT_NEW().
-
-```c++
-class X {
- DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
- ...;
-};
-
-class Y {
- USING_FAST_MALLOC(Y);
- X m_x; // This is allowed.
- Vector<X> m_vector; // This is allowed.
-};
-
-void func() {
- X x; // This is allowed.
- X* x = new X; // This is forbidden.
-}
-```
-
-Note that these macros are inherited. See a comment in wtf/Allocator.h
-for more details about the relationship between the macros and Oilpan.
-
-If you have any question, ask oilpan-reviews@chromium.org.
diff --git a/BUILD.gn b/BUILD.gn
index fa2463b..da03f59 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -38,12 +38,11 @@
"CryptographicallyRandomNumber.h",
"CurrentTime.h",
"DataLog.h",
- "DateMath.cpp",
"DateMath.h",
"Deque.h",
+ "Dummy.cpp",
"DoublyLinkedList.h",
"DynamicAnnotations.h",
- "FilePrintStream.cpp",
"FilePrintStream.h",
"Forward.h",
"Functional.h",
@@ -57,7 +56,6 @@
"HashTableDeletedValueType.h",
"HashTraits.h",
"HexNumber.h",
- "InstanceCounter.cpp",
"InstanceCounter.h",
"LeakAnnotations.h",
"ListHashSet.h",
@@ -68,7 +66,6 @@
"NotFound.h",
"Optional.h",
"PassRefPtr.h",
- "PrintStream.cpp",
"PrintStream.h",
"PtrUtil.h",
"RefCounted.h",
@@ -77,9 +74,7 @@
"RetainPtr.h",
"SaturatedArithmetic.h",
"SizeAssertions.h",
- "SizeLimits.cpp",
"SpinLock.h",
- "StackUtil.cpp",
"StackUtil.h",
"StaticConstructors.h",
"StdLibExtras.h",
@@ -90,20 +85,15 @@
"ThreadRestrictionVerifier.h",
"ThreadSafeRefCounted.h",
"ThreadSpecific.h",
- "ThreadSpecificWin.cpp",
"Threading.h",
"ThreadingPrimitives.h",
- "ThreadingPthreads.cpp",
- "ThreadingWin.cpp",
"Time.h",
"TreeNode.h",
"TypeTraits.h",
"Vector.h",
"VectorTraits.h",
- "WTF.cpp",
"WTF.h",
"WTFExport.h",
- "WTFThreadData.cpp",
"WTFThreadData.h",
"WeakPtr.h",
"allocator/PartitionAllocator.h",
@@ -195,18 +185,6 @@
"//third_party/icu",
]
- if (is_win) {
- sources -= [ "ThreadingPthreads.cpp" ]
-
- cflags = [ "/wd4068" ] # Unknown pragma.
- } else {
- # Non-Windows.
- sources -= [
- "ThreadSpecificWin.cpp",
- "ThreadingWin.cpp",
- ]
- }
-
if (is_android) {
libs = [ "log" ]
}
diff --git a/BloomFilter.h b/BloomFilter.h
index 4618304..b37327e 100644
--- a/BloomFilter.h
+++ b/BloomFilter.h
@@ -1,149 +1,9 @@
-/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
+// Copyright 2017 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.
-#ifndef BloomFilter_h
-#define BloomFilter_h
+#include "platform/wtf/BloomFilter.h"
-#include "wtf/Allocator.h"
-#include "wtf/Compiler.h"
-#include "wtf/text/AtomicString.h"
-
-namespace WTF {
-
-// Counting bloom filter with k=2 and 8 bit counters. Uses 2^keyBits bytes of
-// memory. False positive rate is approximately (1-e^(-2n/m))^2, where n is
-// the number of unique keys and m is the table size (==2^keyBits).
-template <unsigned keyBits>
-class BloomFilter {
- USING_FAST_MALLOC(BloomFilter);
-
- public:
- static_assert(keyBits <= 16, "bloom filter key size check");
-
- static const size_t tableSize = 1 << keyBits;
- static const unsigned keyMask = (1 << keyBits) - 1;
- static uint8_t maximumCount() { return std::numeric_limits<uint8_t>::max(); }
-
- BloomFilter() { clear(); }
-
- void add(unsigned hash);
- void remove(unsigned hash);
-
- // The filter may give false positives (claim it may contain a key it doesn't)
- // but never false negatives (claim it doesn't contain a key it does).
- bool mayContain(unsigned hash) const {
- return firstSlot(hash) && secondSlot(hash);
- }
-
- // The filter must be cleared before reuse even if all keys are removed.
- // Otherwise overflowed keys will stick around.
- void clear();
-
- void add(const AtomicString& string) { add(string.impl()->existingHash()); }
- void add(const String& string) { add(string.impl()->hash()); }
- void remove(const AtomicString& string) {
- remove(string.impl()->existingHash());
- }
- void remove(const String& string) { remove(string.impl()->hash()); }
-
- bool mayContain(const AtomicString& string) const {
- return mayContain(string.impl()->existingHash());
- }
- bool mayContain(const String& string) const {
- return mayContain(string.impl()->hash());
- }
-
-#if DCHECK_IS_ON()
- // Slow.
- bool likelyEmpty() const;
- bool isClear() const;
-#endif
-
- private:
- uint8_t& firstSlot(unsigned hash) { return m_table[hash & keyMask]; }
- uint8_t& secondSlot(unsigned hash) { return m_table[(hash >> 16) & keyMask]; }
- const uint8_t& firstSlot(unsigned hash) const {
- return m_table[hash & keyMask];
- }
- const uint8_t& secondSlot(unsigned hash) const {
- return m_table[(hash >> 16) & keyMask];
- }
-
- uint8_t m_table[tableSize];
-};
-
-template <unsigned keyBits>
-inline void BloomFilter<keyBits>::add(unsigned hash) {
- uint8_t& first = firstSlot(hash);
- uint8_t& second = secondSlot(hash);
- if (LIKELY(first < maximumCount()))
- ++first;
- if (LIKELY(second < maximumCount()))
- ++second;
-}
-
-template <unsigned keyBits>
-inline void BloomFilter<keyBits>::remove(unsigned hash) {
- uint8_t& first = firstSlot(hash);
- uint8_t& second = secondSlot(hash);
- DCHECK(first);
- DCHECK(second);
- // In case of an overflow, the slot sticks in the table until clear().
- if (LIKELY(first < maximumCount()))
- --first;
- if (LIKELY(second < maximumCount()))
- --second;
-}
-
-template <unsigned keyBits>
-inline void BloomFilter<keyBits>::clear() {
- memset(m_table, 0, tableSize);
-}
-
-#if DCHECK_IS_ON()
-template <unsigned keyBits>
-bool BloomFilter<keyBits>::likelyEmpty() const {
- for (size_t n = 0; n < tableSize; ++n) {
- if (m_table[n] && m_table[n] != maximumCount())
- return false;
- }
- return true;
-}
-
-template <unsigned keyBits>
-bool BloomFilter<keyBits>::isClear() const {
- for (size_t n = 0; n < tableSize; ++n) {
- if (m_table[n])
- return false;
- }
- return true;
-}
-#endif
-
-} // namespace WTF
-
-using WTF::BloomFilter;
-
-#endif
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/ByteOrder.h b/ByteOrder.h
index 35456a8..4ba9cd8 100644
--- a/ByteOrder.h
+++ b/ByteOrder.h
@@ -1,86 +1,9 @@
-/*
-* Copyright (C) 2012 Google Inc. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are
-* met:
-*
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above
-* copyright notice, this list of conditions and the following disclaimer
-* in the documentation and/or other materials provided with the
-* distribution.
-* * Neither the name of Google Inc. nor the names of its
-* contributors may be used to endorse or promote products derived from
-* this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+// Copyright 2017 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.
-#ifndef WTF_ByteOrder_h
-#define WTF_ByteOrder_h
+#include "platform/wtf/ByteOrder.h"
-#if OS(POSIX)
-#include <arpa/inet.h>
-#endif
-
-#if OS(WIN)
-
-#include "wtf/ByteSwap.h"
-#include "wtf/CPU.h"
-
-#if CPU(BIG_ENDIAN)
-inline uint16_t ntohs(uint16_t x) {
- return x;
-}
-inline uint16_t htons(uint16_t x) {
- return x;
-}
-inline uint32_t ntohl(uint32_t x) {
- return x;
-}
-inline uint32_t htonl(uint32_t x) {
- return x;
-}
-#elif CPU(MIDDLE_ENDIAN)
-inline uint16_t ntohs(uint16_t x) {
- return x;
-}
-inline uint16_t htons(uint16_t x) {
- return x;
-}
-inline uint32_t ntohl(uint32_t x) {
- return WTF::wswap32(x);
-}
-inline uint32_t htonl(uint32_t x) {
- return WTF::wswap32(x);
-}
-#else
-inline uint16_t ntohs(uint16_t x) {
- return WTF::bswap16(x);
-}
-inline uint16_t htons(uint16_t x) {
- return WTF::bswap16(x);
-}
-inline uint32_t ntohl(uint32_t x) {
- return WTF::bswap32(x);
-}
-inline uint32_t htonl(uint32_t x) {
- return WTF::bswap32(x);
-}
-#endif
-
-#endif // OS(WIN)
-
-#endif // WTF_ByteOrder_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/CONTRIBUTORS.pthreads-win32 b/CONTRIBUTORS.pthreads-win32
deleted file mode 100644
index 7de0f26..0000000
--- a/CONTRIBUTORS.pthreads-win32
+++ /dev/null
@@ -1,137 +0,0 @@
-This is a copy of CONTRIBUTORS file for the Pthreads-win32 library, downloaded
-from http://sourceware.org/cgi-bin/cvsweb.cgi/~checkout~/pthreads/CONTRIBUTORS?rev=1.32&cvsroot=pthreads-win32
-
-Included here to compliment the Pthreads-win32 license header in wtf/ThreadingWin.cpp file.
-WebKit is using derived sources of ThreadCondition code from Pthreads-win32.
-
--------------------------------------------------------------------------------
-
-Contributors (in approximate order of appearance)
-
-[See also the ChangeLog file where individuals are
-attributed in log entries. Likewise in the FAQ file.]
-
-Ben Elliston bje at cygnus dot com
- Initiated the project;
- setup the project infrastructure (CVS, web page, etc.);
- early prototype routines.
-Ross Johnson rpj at callisto dot canberra dot edu dot au
- early prototype routines;
- ongoing project coordination/maintenance;
- implementation of spin locks and barriers;
- various enhancements;
- bug fixes;
- documentation;
- testsuite.
-Robert Colquhoun rjc at trump dot net dot au
- Early bug fixes.
-John E. Bossom John dot Bossom at cognos dot com
- Contributed substantial original working implementation;
- bug fixes;
- ongoing guidance and standards interpretation.
-Anders Norlander anorland at hem2 dot passagen dot se
- Early enhancements and runtime checking for supported
- Win32 routines.
-Tor Lillqvist tml at iki dot fi
- General enhancements;
- early bug fixes to condition variables.
-Scott Lightner scott at curriculum dot com
- Bug fix.
-Kevin Ruland Kevin dot Ruland at anheuser-busch dot com
- Various bug fixes.
-Mike Russo miker at eai dot com
- Bug fix.
-Mark E. Armstrong avail at pacbell dot net
- Bug fixes.
-Lorin Hochstein lmh at xiphos dot ca
- general bug fixes; bug fixes to condition variables.
-Peter Slacik Peter dot Slacik at tatramed dot sk
- Bug fixes.
-Mumit Khan khan at xraylith dot wisc dot edu
- Fixes to work with Mingw32.
-Milan Gardian mg at tatramed dot sk
- Bug fixes and reports/analyses of obscure problems.
-Aurelio Medina aureliom at crt dot com
- First implementation of read-write locks.
-Graham Dumpleton Graham dot Dumpleton at ra dot pad dot otc dot telstra dot com dot au
- Bug fix in condition variables.
-Tristan Savatier tristan at mpegtv dot com
- WinCE port.
-Erik Hensema erik at hensema dot xs4all dot nl
- Bug fixes.
-Rich Peters rpeters at micro-magic dot com
-Todd Owen towen at lucidcalm dot dropbear dot id dot au
- Bug fixes to dll loading.
-Jason Nye jnye at nbnet dot nb dot ca
- Implementation of async cancelation.
-Fred Forester fforest at eticomm dot net
-Kevin D. Clark kclark at cabletron dot com
-David Baggett dmb at itasoftware dot com
- Bug fixes.
-Paul Redondo paul at matchvision dot com
-Scott McCaskill scott at 3dfx dot com
- Bug fixes.
-Jef Gearhart jgearhart at tpssys dot com
- Bug fix.
-Arthur Kantor akantor at bexusa dot com
- Mutex enhancements.
-Steven Reddie smr at essemer dot com dot au
- Bug fix.
-Alexander Terekhov TEREKHOV at de dot ibm dot com
- Re-implemented and improved read-write locks;
- (with Louis Thomas) re-implemented and improved
- condition variables;
- enhancements to semaphores;
- enhancements to mutexes;
- new mutex implementation in 'futex' style;
- suggested a robust implementation of pthread_once
- similar to that implemented by V.Kliathcko;
- system clock change handling re CV timeouts;
- bug fixes.
-Thomas Pfaff tpfaff at gmx dot net
- Changes to make C version usable with C++ applications;
- re-implemented mutex routines to avoid Win32 mutexes
- and TryEnterCriticalSection;
- procedure to fix Mingw32 thread-safety issues.
-Franco Bez franco dot bez at gmx dot de
- procedure to fix Mingw32 thread-safety issues.
-Louis Thomas lthomas at arbitrade dot com
- (with Alexander Terekhov) re-implemented and improved
- condition variables.
-David Korn dgk at research dot att dot com
- Ported to UWIN.
-Phil Frisbie, Jr. phil at hawksoft dot com
- Bug fix.
-Ralf Brese Ralf dot Brese at pdb4 dot siemens dot de
- Bug fix.
-prionx at juno dot com prionx at juno dot com
- Bug fixes.
-Max Woodbury mtew at cds dot duke dot edu
- POSIX versioning conditionals;
- reduced namespace pollution;
- idea to separate routines to reduce statically
- linked image sizes.
-Rob Fanner rfanner at stonethree dot com
- Bug fix.
-Michael Johnson michaelj at maine dot rr dot com
- Bug fix.
-Nicolas Barry boozai at yahoo dot com
- Bug fixes.
-Piet van Bruggen pietvb at newbridges dot nl
- Bug fix.
-Makoto Kato raven at oldskool dot jp
- AMD64 port.
-Panagiotis E. Hadjidoukas peh at hpclab dot ceid dot upatras dot gr
- Contributed the QueueUserAPCEx package which
- makes preemptive async cancelation possible.
-Will Bryant will dot bryant at ecosm dot com
- Borland compiler patch and makefile.
-Anuj Goyal anuj dot goyal at gmail dot com
- Port to Digital Mars compiler.
-Gottlob Frege gottlobfrege at gmail dot com
- re-implemented pthread_once (version 2)
- (pthread_once cancellation added by rpj).
-Vladimir Kliatchko vladimir at kliatchko dot com
- reimplemented pthread_once with the same form
- as described by A.Terekhov (later version 2);
- implementation of MCS (Mellor-Crummey/Scott) locks.
\ No newline at end of file
diff --git a/DateMath.cpp b/DateMath.cpp
deleted file mode 100644
index 9fc692c..0000000
--- a/DateMath.cpp
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
- * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2007-2009 Torch Mobile, Inc.
- * Copyright (C) 2010 &yet, LLC. (nate@andyet.net)
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Alternatively, the contents of this file may be used under the terms
- * of either the Mozilla Public License Version 1.1, found at
- * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
- * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
- * (the "GPL"), in which case the provisions of the MPL or the GPL are
- * applicable instead of those above. If you wish to allow use of your
- * version of this file only under the terms of one of those two
- * licenses (the MPL or the GPL) and not to allow others to use your
- * version of this file under the LGPL, indicate your decision by
- * deletingthe provisions above and replace them with the notice and
- * other provisions required by the MPL or the GPL, as the case may be.
- * If you do not delete the provisions above, a recipient may use your
- * version of this file under any of the LGPL, the MPL or the GPL.
-
- * Copyright 2006-2008 the V8 project authors. All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/DateMath.h"
-
-#include "wtf/ASCIICType.h"
-#include "wtf/Assertions.h"
-#include "wtf/CurrentTime.h"
-#include "wtf/MathExtras.h"
-#include "wtf/StdLibExtras.h"
-#include "wtf/StringExtras.h"
-#include "wtf/text/StringBuilder.h"
-#include <algorithm>
-#include <limits.h>
-#include <limits>
-#include <math.h>
-#include <stdlib.h>
-#include <time.h>
-
-#if OS(WIN)
-#include <windows.h>
-#else
-#include <sys/time.h>
-#endif
-
-namespace WTF {
-
-/* Constants */
-
-static const double hoursPerDay = 24.0;
-static const double secondsPerDay = 24.0 * 60.0 * 60.0;
-
-static const double maxUnixTime = 2145859200.0; // 12/31/2037
-static const double kMinimumECMADateInMs = -8640000000000000.0;
-static const double kMaximumECMADateInMs = 8640000000000000.0;
-
-// Day of year for the first day of each month, where index 0 is January, and
-// day 0 is January 1. First for non-leap years, then for leap years.
-static const int firstDayOfMonth[2][12] = {
- {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
- {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}};
-
-static inline void getLocalTime(const time_t* localTime, struct tm* localTM) {
-#if COMPILER(MSVC)
- localtime_s(localTM, localTime);
-#else
- localtime_r(localTime, localTM);
-#endif
-}
-
-bool isLeapYear(int year) {
- if (year % 4 != 0)
- return false;
- if (year % 400 == 0)
- return true;
- if (year % 100 == 0)
- return false;
- return true;
-}
-
-static inline int daysInYear(int year) {
- return 365 + isLeapYear(year);
-}
-
-static inline double daysFrom1970ToYear(int year) {
- // The Gregorian Calendar rules for leap years:
- // Every fourth year is a leap year. 2004, 2008, and 2012 are leap years.
- // However, every hundredth year is not a leap year. 1900 and 2100 are not
- // leap years.
- // Every four hundred years, there's a leap year after all. 2000 and 2400 are
- // leap years.
-
- static const int leapDaysBefore1971By4Rule = 1970 / 4;
- static const int excludedLeapDaysBefore1971By100Rule = 1970 / 100;
- static const int leapDaysBefore1971By400Rule = 1970 / 400;
-
- const double yearMinusOne = year - 1;
- const double yearsToAddBy4Rule =
- floor(yearMinusOne / 4.0) - leapDaysBefore1971By4Rule;
- const double yearsToExcludeBy100Rule =
- floor(yearMinusOne / 100.0) - excludedLeapDaysBefore1971By100Rule;
- const double yearsToAddBy400Rule =
- floor(yearMinusOne / 400.0) - leapDaysBefore1971By400Rule;
-
- return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule +
- yearsToAddBy400Rule;
-}
-
-static double msToDays(double ms) {
- return floor(ms / msPerDay);
-}
-
-static void appendTwoDigitNumber(StringBuilder& builder, int number) {
- DCHECK_GE(number, 0);
- DCHECK_LT(number, 100);
- if (number <= 9)
- builder.append('0');
- builder.appendNumber(number);
-}
-
-int msToYear(double ms) {
- DCHECK(std::isfinite(ms));
- DCHECK_GE(ms, kMinimumECMADateInMs);
- DCHECK_LE(ms, kMaximumECMADateInMs);
- int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970);
- double msFromApproxYearTo1970 = msPerDay * daysFrom1970ToYear(approxYear);
- if (msFromApproxYearTo1970 > ms)
- return approxYear - 1;
- if (msFromApproxYearTo1970 + msPerDay * daysInYear(approxYear) <= ms)
- return approxYear + 1;
- return approxYear;
-}
-
-int dayInYear(double ms, int year) {
- return static_cast<int>(msToDays(ms) - daysFrom1970ToYear(year));
-}
-
-static inline double msToMilliseconds(double ms) {
- double result = fmod(ms, msPerDay);
- if (result < 0)
- result += msPerDay;
- return result;
-}
-
-int monthFromDayInYear(int dayInYear, bool leapYear) {
- const int d = dayInYear;
- int step;
-
- if (d < (step = 31))
- return 0;
- step += (leapYear ? 29 : 28);
- if (d < step)
- return 1;
- if (d < (step += 31))
- return 2;
- if (d < (step += 30))
- return 3;
- if (d < (step += 31))
- return 4;
- if (d < (step += 30))
- return 5;
- if (d < (step += 31))
- return 6;
- if (d < (step += 31))
- return 7;
- if (d < (step += 30))
- return 8;
- if (d < (step += 31))
- return 9;
- if (d < (step += 30))
- return 10;
- return 11;
-}
-
-static inline bool checkMonth(int dayInYear,
- int& startDayOfThisMonth,
- int& startDayOfNextMonth,
- int daysInThisMonth) {
- startDayOfThisMonth = startDayOfNextMonth;
- startDayOfNextMonth += daysInThisMonth;
- return (dayInYear <= startDayOfNextMonth);
-}
-
-int dayInMonthFromDayInYear(int dayInYear, bool leapYear) {
- const int d = dayInYear;
- int step;
- int next = 30;
-
- if (d <= next)
- return d + 1;
- const int daysInFeb = (leapYear ? 29 : 28);
- if (checkMonth(d, step, next, daysInFeb))
- return d - step;
- if (checkMonth(d, step, next, 31))
- return d - step;
- if (checkMonth(d, step, next, 30))
- return d - step;
- if (checkMonth(d, step, next, 31))
- return d - step;
- if (checkMonth(d, step, next, 30))
- return d - step;
- if (checkMonth(d, step, next, 31))
- return d - step;
- if (checkMonth(d, step, next, 31))
- return d - step;
- if (checkMonth(d, step, next, 30))
- return d - step;
- if (checkMonth(d, step, next, 31))
- return d - step;
- if (checkMonth(d, step, next, 30))
- return d - step;
- step = next;
- return d - step;
-}
-
-int dayInYear(int year, int month, int day) {
- return firstDayOfMonth[isLeapYear(year)][month] + day - 1;
-}
-
-double dateToDaysFrom1970(int year, int month, int day) {
- year += month / 12;
-
- month %= 12;
- if (month < 0) {
- month += 12;
- --year;
- }
-
- double yearday = floor(daysFrom1970ToYear(year));
- DCHECK((year >= 1970 && yearday >= 0) || (year < 1970 && yearday < 0));
- return yearday + dayInYear(year, month, day);
-}
-
-// There is a hard limit at 2038 that we currently do not have a workaround
-// for (rdar://problem/5052975).
-static inline int maximumYearForDST() {
- return 2037;
-}
-
-static inline double jsCurrentTime() {
- // JavaScript doesn't recognize fractions of a millisecond.
- return floor(WTF::currentTimeMS());
-}
-
-static inline int minimumYearForDST() {
- // Because of the 2038 issue (see maximumYearForDST) if the current year is
- // greater than the max year minus 27 (2010), we want to use the max year
- // minus 27 instead, to ensure there is a range of 28 years that all years
- // can map to.
- return std::min(msToYear(jsCurrentTime()), maximumYearForDST() - 27);
-}
-
-// Find an equivalent year for the one given, where equivalence is deterined by
-// the two years having the same leapness and the first day of the year, falling
-// on the same day of the week.
-//
-// This function returns a year between this current year and 2037, however this
-// function will potentially return incorrect results if the current year is
-// after 2010, (rdar://problem/5052975), if the year passed in is before 1900
-// or after 2100, (rdar://problem/5055038).
-static int equivalentYearForDST(int year) {
- // It is ok if the cached year is not the current year as long as the rules
- // for DST did not change between the two years; if they did the app would
- // need to be restarted.
- static int minYear = minimumYearForDST();
- int maxYear = maximumYearForDST();
-
- int difference;
- if (year > maxYear)
- difference = minYear - year;
- else if (year < minYear)
- difference = maxYear - year;
- else
- return year;
-
- int quotient = difference / 28;
- int product = (quotient)*28;
-
- year += product;
- DCHECK((year >= minYear && year <= maxYear) ||
- (product - year ==
- static_cast<int>(std::numeric_limits<double>::quiet_NaN())));
- return year;
-}
-
-static double calculateUTCOffset() {
-#if OS(WIN)
- TIME_ZONE_INFORMATION timeZoneInformation;
- GetTimeZoneInformation(&timeZoneInformation);
- int32_t bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias;
- return -bias * 60 * 1000;
-#else
- time_t localTime = time(0);
- tm localt;
- getLocalTime(&localTime, &localt);
-
- // tm_gmtoff includes any daylight savings offset, so subtract it.
- return static_cast<double>(localt.tm_gmtoff * msPerSecond -
- (localt.tm_isdst > 0 ? msPerHour : 0));
-#endif
-}
-
-/*
- * Get the DST offset for the time passed in.
- */
-static double calculateDSTOffsetSimple(double localTimeSeconds,
- double utcOffset) {
- if (localTimeSeconds > maxUnixTime)
- localTimeSeconds = maxUnixTime;
- else if (localTimeSeconds <
- 0) // Go ahead a day to make localtime work (does not work with 0)
- localTimeSeconds += secondsPerDay;
-
- // FIXME: time_t has a potential problem in 2038
- time_t localTime = static_cast<time_t>(localTimeSeconds);
-
- tm localTM;
- getLocalTime(&localTime, &localTM);
-
- return localTM.tm_isdst > 0 ? msPerHour : 0;
-}
-
-// Get the DST offset, given a time in UTC
-static double calculateDSTOffset(double ms, double utcOffset) {
- // On macOS, the call to localtime (see calculateDSTOffsetSimple) will return
- // historically accurate DST information (e.g. New Zealand did not have DST
- // from 1946 to 1974) however the JavaScript standard explicitly dictates
- // that historical information should not be considered when determining DST.
- // For this reason we shift away from years that localtime can handle but
- // would return historically accurate information.
- int year = msToYear(ms);
- int equivalentYear = equivalentYearForDST(year);
- if (year != equivalentYear) {
- bool leapYear = isLeapYear(year);
- int dayInYearLocal = dayInYear(ms, year);
- int dayInMonth = dayInMonthFromDayInYear(dayInYearLocal, leapYear);
- int month = monthFromDayInYear(dayInYearLocal, leapYear);
- double day = dateToDaysFrom1970(equivalentYear, month, dayInMonth);
- ms = (day * msPerDay) + msToMilliseconds(ms);
- }
-
- return calculateDSTOffsetSimple(ms / msPerSecond, utcOffset);
-}
-
-void initializeDates() {
-#if DCHECK_IS_ON()
- static bool alreadyInitialized;
- DCHECK(!alreadyInitialized);
- alreadyInitialized = true;
-#endif
-
- equivalentYearForDST(
- 2000); // Need to call once to initialize a static used in this function.
-}
-
-static inline double ymdhmsToSeconds(int year,
- long mon,
- long day,
- long hour,
- long minute,
- double second) {
- double days =
- (day - 32075) + floor(1461 * (year + 4800.0 + (mon - 14) / 12) / 4) +
- 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12 -
- floor(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4) - 2440588;
- return ((days * hoursPerDay + hour) * minutesPerHour + minute) *
- secondsPerMinute +
- second;
-}
-
-// We follow the recommendation of RFC 2822 to consider all
-// obsolete time zones not listed here equivalent to "-0000".
-static const struct KnownZone {
-#if !OS(WIN)
- const
-#endif
- char tzName[4];
- int tzOffset;
-} known_zones[] = {{"UT", 0}, {"GMT", 0}, {"EST", -300}, {"EDT", -240},
- {"CST", -360}, {"CDT", -300}, {"MST", -420}, {"MDT", -360},
- {"PST", -480}, {"PDT", -420}};
-
-inline static void skipSpacesAndComments(const char*& s) {
- int nesting = 0;
- char ch;
- while ((ch = *s)) {
- if (!isASCIISpace(ch)) {
- if (ch == '(')
- nesting++;
- else if (ch == ')' && nesting > 0)
- nesting--;
- else if (nesting == 0)
- break;
- }
- s++;
- }
-}
-
-// returns 0-11 (Jan-Dec); -1 on failure
-static int findMonth(const char* monthStr) {
- DCHECK(monthStr);
- char needle[4];
- for (int i = 0; i < 3; ++i) {
- if (!*monthStr)
- return -1;
- needle[i] = static_cast<char>(toASCIILower(*monthStr++));
- }
- needle[3] = '\0';
- const char* haystack = "janfebmaraprmayjunjulaugsepoctnovdec";
- const char* str = strstr(haystack, needle);
- if (str) {
- int position = static_cast<int>(str - haystack);
- if (position % 3 == 0)
- return position / 3;
- }
- return -1;
-}
-
-static bool parseInt(const char* string,
- char** stopPosition,
- int base,
- int* result) {
- long longResult = strtol(string, stopPosition, base);
- // Avoid the use of errno as it is not available on Windows CE
- if (string == *stopPosition ||
- longResult <= std::numeric_limits<int>::min() ||
- longResult >= std::numeric_limits<int>::max())
- return false;
- *result = static_cast<int>(longResult);
- return true;
-}
-
-static bool parseLong(const char* string,
- char** stopPosition,
- int base,
- long* result) {
- *result = strtol(string, stopPosition, base);
- // Avoid the use of errno as it is not available on Windows CE
- if (string == *stopPosition || *result == std::numeric_limits<long>::min() ||
- *result == std::numeric_limits<long>::max())
- return false;
- return true;
-}
-
-// Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore.
-static double parseDateFromNullTerminatedCharacters(const char* dateString,
- bool& haveTZ,
- int& offset) {
- haveTZ = false;
- offset = 0;
-
- // This parses a date in the form:
- // Tuesday, 09-Nov-99 23:12:40 GMT
- // or
- // Sat, 01-Jan-2000 08:00:00 GMT
- // or
- // Sat, 01 Jan 2000 08:00:00 GMT
- // or
- // 01 Jan 99 22:00 +0100 (exceptions in rfc822/rfc2822)
- // ### non RFC formats, added for Javascript:
- // [Wednesday] January 09 1999 23:12:40 GMT
- // [Wednesday] January 09 23:12:40 GMT 1999
- //
- // We ignore the weekday.
-
- // Skip leading space
- skipSpacesAndComments(dateString);
-
- long month = -1;
- const char* wordStart = dateString;
- // Check contents of first words if not number
- while (*dateString && !isASCIIDigit(*dateString)) {
- if (isASCIISpace(*dateString) || *dateString == '(') {
- if (dateString - wordStart >= 3)
- month = findMonth(wordStart);
- skipSpacesAndComments(dateString);
- wordStart = dateString;
- } else {
- dateString++;
- }
- }
-
- // Missing delimiter between month and day (like "January29")?
- if (month == -1 && wordStart != dateString)
- month = findMonth(wordStart);
-
- skipSpacesAndComments(dateString);
-
- if (!*dateString)
- return std::numeric_limits<double>::quiet_NaN();
-
- // ' 09-Nov-99 23:12:40 GMT'
- char* newPosStr;
- long day;
- if (!parseLong(dateString, &newPosStr, 10, &day))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
-
- if (!*dateString)
- return std::numeric_limits<double>::quiet_NaN();
-
- if (day < 0)
- return std::numeric_limits<double>::quiet_NaN();
-
- int year = 0;
- if (day > 31) {
- // ### where is the boundary and what happens below?
- if (*dateString != '/')
- return std::numeric_limits<double>::quiet_NaN();
- // looks like a YYYY/MM/DD date
- if (!*++dateString)
- return std::numeric_limits<double>::quiet_NaN();
- if (day <= std::numeric_limits<int>::min() ||
- day >= std::numeric_limits<int>::max())
- return std::numeric_limits<double>::quiet_NaN();
- year = static_cast<int>(day);
- if (!parseLong(dateString, &newPosStr, 10, &month))
- return std::numeric_limits<double>::quiet_NaN();
- month -= 1;
- dateString = newPosStr;
- if (*dateString++ != '/' || !*dateString)
- return std::numeric_limits<double>::quiet_NaN();
- if (!parseLong(dateString, &newPosStr, 10, &day))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
- } else if (*dateString == '/' && month == -1) {
- dateString++;
- // This looks like a MM/DD/YYYY date, not an RFC date.
- month = day - 1; // 0-based
- if (!parseLong(dateString, &newPosStr, 10, &day))
- return std::numeric_limits<double>::quiet_NaN();
- if (day < 1 || day > 31)
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
- if (*dateString == '/')
- dateString++;
- if (!*dateString)
- return std::numeric_limits<double>::quiet_NaN();
- } else {
- if (*dateString == '-')
- dateString++;
-
- skipSpacesAndComments(dateString);
-
- if (*dateString == ',')
- dateString++;
-
- if (month == -1) { // not found yet
- month = findMonth(dateString);
- if (month == -1)
- return std::numeric_limits<double>::quiet_NaN();
-
- while (*dateString && *dateString != '-' && *dateString != ',' &&
- !isASCIISpace(*dateString))
- dateString++;
-
- if (!*dateString)
- return std::numeric_limits<double>::quiet_NaN();
-
- // '-99 23:12:40 GMT'
- if (*dateString != '-' && *dateString != '/' && *dateString != ',' &&
- !isASCIISpace(*dateString))
- return std::numeric_limits<double>::quiet_NaN();
- dateString++;
- }
- }
-
- if (month < 0 || month > 11)
- return std::numeric_limits<double>::quiet_NaN();
-
- // '99 23:12:40 GMT'
- if (year <= 0 && *dateString) {
- if (!parseInt(dateString, &newPosStr, 10, &year))
- return std::numeric_limits<double>::quiet_NaN();
- }
-
- // Don't fail if the time is missing.
- long hour = 0;
- long minute = 0;
- long second = 0;
- if (!*newPosStr) {
- dateString = newPosStr;
- } else {
- // ' 23:12:40 GMT'
- if (!(isASCIISpace(*newPosStr) || *newPosStr == ',')) {
- if (*newPosStr != ':')
- return std::numeric_limits<double>::quiet_NaN();
- // There was no year; the number was the hour.
- year = -1;
- } else {
- // in the normal case (we parsed the year), advance to the next number
- dateString = ++newPosStr;
- skipSpacesAndComments(dateString);
- }
-
- parseLong(dateString, &newPosStr, 10, &hour);
- // Do not check for errno here since we want to continue
- // even if errno was set becasue we are still looking
- // for the timezone!
-
- // Read a number? If not, this might be a timezone name.
- if (newPosStr != dateString) {
- dateString = newPosStr;
-
- if (hour < 0 || hour > 23)
- return std::numeric_limits<double>::quiet_NaN();
-
- if (!*dateString)
- return std::numeric_limits<double>::quiet_NaN();
-
- // ':12:40 GMT'
- if (*dateString++ != ':')
- return std::numeric_limits<double>::quiet_NaN();
-
- if (!parseLong(dateString, &newPosStr, 10, &minute))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
-
- if (minute < 0 || minute > 59)
- return std::numeric_limits<double>::quiet_NaN();
-
- // ':40 GMT'
- if (*dateString && *dateString != ':' && !isASCIISpace(*dateString))
- return std::numeric_limits<double>::quiet_NaN();
-
- // seconds are optional in rfc822 + rfc2822
- if (*dateString == ':') {
- dateString++;
-
- if (!parseLong(dateString, &newPosStr, 10, &second))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
-
- if (second < 0 || second > 59)
- return std::numeric_limits<double>::quiet_NaN();
- }
-
- skipSpacesAndComments(dateString);
-
- if (strncasecmp(dateString, "AM", 2) == 0) {
- if (hour > 12)
- return std::numeric_limits<double>::quiet_NaN();
- if (hour == 12)
- hour = 0;
- dateString += 2;
- skipSpacesAndComments(dateString);
- } else if (strncasecmp(dateString, "PM", 2) == 0) {
- if (hour > 12)
- return std::numeric_limits<double>::quiet_NaN();
- if (hour != 12)
- hour += 12;
- dateString += 2;
- skipSpacesAndComments(dateString);
- }
- }
- }
-
- // The year may be after the time but before the time zone.
- if (isASCIIDigit(*dateString) && year == -1) {
- if (!parseInt(dateString, &newPosStr, 10, &year))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
- skipSpacesAndComments(dateString);
- }
-
- // Don't fail if the time zone is missing.
- // Some websites omit the time zone (4275206).
- if (*dateString) {
- if (strncasecmp(dateString, "GMT", 3) == 0 ||
- strncasecmp(dateString, "UTC", 3) == 0) {
- dateString += 3;
- haveTZ = true;
- }
-
- if (*dateString == '+' || *dateString == '-') {
- int o;
- if (!parseInt(dateString, &newPosStr, 10, &o))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
-
- if (o < -9959 || o > 9959)
- return std::numeric_limits<double>::quiet_NaN();
-
- int sgn = (o < 0) ? -1 : 1;
- o = abs(o);
- if (*dateString != ':') {
- if (o >= 24)
- offset = ((o / 100) * 60 + (o % 100)) * sgn;
- else
- offset = o * 60 * sgn;
- } else { // GMT+05:00
- ++dateString; // skip the ':'
- int o2;
- if (!parseInt(dateString, &newPosStr, 10, &o2))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
- offset = (o * 60 + o2) * sgn;
- }
- haveTZ = true;
- } else {
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(known_zones); ++i) {
- if (0 == strncasecmp(dateString, known_zones[i].tzName,
- strlen(known_zones[i].tzName))) {
- offset = known_zones[i].tzOffset;
- dateString += strlen(known_zones[i].tzName);
- haveTZ = true;
- break;
- }
- }
- }
- }
-
- skipSpacesAndComments(dateString);
-
- if (*dateString && year == -1) {
- if (!parseInt(dateString, &newPosStr, 10, &year))
- return std::numeric_limits<double>::quiet_NaN();
- dateString = newPosStr;
- skipSpacesAndComments(dateString);
- }
-
- // Trailing garbage
- if (*dateString)
- return std::numeric_limits<double>::quiet_NaN();
-
- // Y2K: Handle 2 digit years.
- if (year >= 0 && year < 100) {
- if (year < 50)
- year += 2000;
- else
- year += 1900;
- }
-
- return ymdhmsToSeconds(year, month + 1, day, hour, minute, second) *
- msPerSecond;
-}
-
-double parseDateFromNullTerminatedCharacters(const char* dateString) {
- bool haveTZ;
- int offset;
- double ms = parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);
- if (std::isnan(ms))
- return std::numeric_limits<double>::quiet_NaN();
-
- // fall back to local timezone
- if (!haveTZ) {
- double utcOffset = calculateUTCOffset();
- double dstOffset = calculateDSTOffset(ms, utcOffset);
- offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute);
- }
- return ms - (offset * msPerMinute);
-}
-
-// See http://tools.ietf.org/html/rfc2822#section-3.3 for more information.
-String makeRFC2822DateString(unsigned dayOfWeek,
- unsigned day,
- unsigned month,
- unsigned year,
- unsigned hours,
- unsigned minutes,
- unsigned seconds,
- int utcOffset) {
- StringBuilder stringBuilder;
- stringBuilder.append(weekdayName[dayOfWeek]);
- stringBuilder.append(", ");
- stringBuilder.appendNumber(day);
- stringBuilder.append(' ');
- stringBuilder.append(monthName[month]);
- stringBuilder.append(' ');
- stringBuilder.appendNumber(year);
- stringBuilder.append(' ');
-
- appendTwoDigitNumber(stringBuilder, hours);
- stringBuilder.append(':');
- appendTwoDigitNumber(stringBuilder, minutes);
- stringBuilder.append(':');
- appendTwoDigitNumber(stringBuilder, seconds);
- stringBuilder.append(' ');
-
- stringBuilder.append(utcOffset > 0 ? '+' : '-');
- int absoluteUTCOffset = abs(utcOffset);
- appendTwoDigitNumber(stringBuilder, absoluteUTCOffset / 60);
- appendTwoDigitNumber(stringBuilder, absoluteUTCOffset % 60);
-
- return stringBuilder.toString();
-}
-
-double convertToLocalTime(double ms) {
- double utcOffset = calculateUTCOffset();
- double dstOffset = calculateDSTOffset(ms, utcOffset);
- return (ms + utcOffset + dstOffset);
-}
-
-} // namespace WTF
diff --git a/DateMath.h b/DateMath.h
index 51c8c75..f2e3dfa 100644
--- a/DateMath.h
+++ b/DateMath.h
@@ -1,121 +1,9 @@
-/*
- * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2010 Research In Motion Limited. All rights reserved.
- *
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- */
+// Copyright 2017 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.
-#ifndef DateMath_h
-#define DateMath_h
+#include "platform/wtf/DateMath.h"
-#include "wtf/WTFExport.h"
-#include "wtf/text/WTFString.h"
-#include <stdint.h>
-#include <string.h>
-
-namespace WTF {
-
-WTF_EXPORT void initializeDates();
-
-// Not really math related, but this is currently the only shared place to put
-// these.
-WTF_EXPORT double parseDateFromNullTerminatedCharacters(const char* dateString);
-// dayOfWeek: [0, 6] 0 being Monday
-// day: [1, 31]
-// month: [0, 11]
-// year: ex: 2011
-// hours: [0, 23]
-// minutes: [0, 59]
-// seconds: [0, 59]
-// utcOffset: [-720,720].
-WTF_EXPORT String makeRFC2822DateString(unsigned dayOfWeek,
- unsigned day,
- unsigned month,
- unsigned year,
- unsigned hours,
- unsigned minutes,
- unsigned seconds,
- int utcOffset);
-
-const char weekdayName[7][4] = {"Mon", "Tue", "Wed", "Thu",
- "Fri", "Sat", "Sun"};
-const char monthName[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-const char* const monthFullName[12] = {
- "January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December"};
-
-const double minutesPerHour = 60.0;
-const double secondsPerMinute = 60.0;
-const double msPerSecond = 1000.0;
-const double msPerMinute = 60.0 * 1000.0;
-const double msPerHour = 60.0 * 60.0 * 1000.0;
-const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
-
-WTF_EXPORT bool isLeapYear(int year);
-
-// Returns the number of days from 1970-01-01 to the specified date.
-WTF_EXPORT double dateToDaysFrom1970(int year, int month, int day);
-WTF_EXPORT int msToYear(double ms);
-WTF_EXPORT int dayInYear(int year, int month, int day);
-WTF_EXPORT int dayInYear(double ms, int year);
-WTF_EXPORT int monthFromDayInYear(int dayInYear, bool leapYear);
-WTF_EXPORT int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
-
-// Returns milliseconds with UTC and DST.
-WTF_EXPORT double convertToLocalTime(double ms);
-
-} // namespace WTF
-
-using WTF::isLeapYear;
-using WTF::dateToDaysFrom1970;
-using WTF::dayInMonthFromDayInYear;
-using WTF::dayInYear;
-using WTF::minutesPerHour;
-using WTF::monthFromDayInYear;
-using WTF::msPerDay;
-using WTF::msPerHour;
-using WTF::msPerMinute;
-using WTF::msPerSecond;
-using WTF::msToYear;
-using WTF::secondsPerMinute;
-using WTF::parseDateFromNullTerminatedCharacters;
-using WTF::makeRFC2822DateString;
-using WTF::convertToLocalTime;
-
-#endif // DateMath_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/Dummy.cpp b/Dummy.cpp
new file mode 100644
index 0000000..8bf4997
--- /dev/null
+++ b/Dummy.cpp
@@ -0,0 +1,22 @@
+// Copyright 2017 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.
+
+// Now that all .cpp files are gone for target "wtf". However, this seems to
+// trigger a compile error on Mac. This file gives an empty object file and
+// should make Xcode's libtool happy...
+
+// And also, MSVC seems to fail to build a .lib file for wtf.dll if there is
+// no symbol to export.
+
+#include "wtf/build_config.h"
+
+#if OS(WIN)
+
+namespace WTF {
+
+__declspec(dllexport) int dummyExportedValueToForceMSVCToGenerateLibFile;
+
+}
+
+#endif
diff --git a/FilePrintStream.cpp b/FilePrintStream.cpp
deleted file mode 100644
index 48c4ee7..0000000
--- a/FilePrintStream.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/FilePrintStream.h"
-
-#include "wtf/PtrUtil.h"
-#include <memory>
-
-namespace WTF {
-
-FilePrintStream::FilePrintStream(FILE* file, AdoptionMode adoptionMode)
- : m_file(file), m_adoptionMode(adoptionMode) {}
-
-FilePrintStream::~FilePrintStream() {
- if (m_adoptionMode == Borrow)
- return;
- fclose(m_file);
-}
-
-std::unique_ptr<FilePrintStream> FilePrintStream::open(const char* filename,
- const char* mode) {
- FILE* file = fopen(filename, mode);
- if (!file)
- return std::unique_ptr<FilePrintStream>();
-
- return WTF::makeUnique<FilePrintStream>(file);
-}
-
-void FilePrintStream::vprintf(const char* format, va_list argList) {
- vfprintf(m_file, format, argList);
-}
-
-void FilePrintStream::flush() {
- fflush(m_file);
-}
-
-} // namespace WTF
diff --git a/InstanceCounter.cpp b/InstanceCounter.cpp
deleted file mode 100644
index cfffb52..0000000
--- a/InstanceCounter.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/InstanceCounter.h"
-
-#include "wtf/HashMap.h"
-#include "wtf/StdLibExtras.h"
-#include "wtf/ThreadingPrimitives.h"
-#include "wtf/text/StringBuilder.h"
-#include "wtf/text/StringHash.h"
-#include "wtf/text/WTFString.h"
-
-namespace WTF {
-
-#if ENABLE(INSTANCE_COUNTER)
-
-#if COMPILER(CLANG)
-const size_t stringWithTypeNamePrefixLength =
- sizeof("const char *WTF::getStringWithTypeName() [T = ") - 1;
-const size_t stringWithTypeNamePostfixLength = sizeof("]") - 1;
-#elif COMPILER(GCC)
-const size_t stringWithTypeNamePrefixLength =
- sizeof("const char* WTF::getStringWithTypeName() [with T = ") - 1;
-const size_t stringWithTypeNamePostfixLength = sizeof("]") - 1;
-#elif COMPILER(MSVC)
-const size_t stringWithTypeNamePrefixLength =
- sizeof("const char *__cdecl WTF::getStringWithTypeName<class ") - 1;
-const size_t stringWithTypeNamePostfixLength = sizeof(">(void)") - 1;
-#else
-#warning \
- "Extracting typename is supported only in compiler GCC, CLANG and MSVC at this moment"
-#endif
-
-// This function is used to stringify a typename T without using RTTI.
-// The result of stringWithTypeName<T>() is given as |funcName|.
-// |extractTypeNameFromFunctionName| then extracts a typename string from
-// |funcName|.
-String extractTypeNameFromFunctionName(const char* funcName) {
-#if COMPILER(CLANG) || COMPILER(GCC) || COMPILER(MSVC)
- size_t funcNameLength = strlen(funcName);
- DCHECK_GT(funcNameLength,
- stringWithTypeNamePrefixLength + stringWithTypeNamePostfixLength);
-
- const char* funcNameWithoutPrefix = funcName + stringWithTypeNamePrefixLength;
- return String(funcNameWithoutPrefix, funcNameLength -
- stringWithTypeNamePrefixLength -
- stringWithTypeNamePostfixLength);
-#else
- return String("unknown");
-#endif
-}
-
-class InstanceCounter {
- public:
- void incrementInstanceCount(const String& instanceName, void* ptr);
- void decrementInstanceCount(const String& instanceName, void* ptr);
- String dump();
-
- static InstanceCounter* instance() {
- DEFINE_STATIC_LOCAL(InstanceCounter, self, ());
- return &self;
- }
-
- private:
- InstanceCounter() {}
-
- Mutex m_mutex;
- HashMap<String, int> m_counterMap;
-};
-
-void incrementInstanceCount(const char* stringWithTypeNameName, void* ptr) {
- String instanceName = extractTypeNameFromFunctionName(stringWithTypeNameName);
- InstanceCounter::instance()->incrementInstanceCount(instanceName, ptr);
-}
-
-void decrementInstanceCount(const char* stringWithTypeNameName, void* ptr) {
- String instanceName = extractTypeNameFromFunctionName(stringWithTypeNameName);
- InstanceCounter::instance()->decrementInstanceCount(instanceName, ptr);
-}
-
-String dumpRefCountedInstanceCounts() {
- return InstanceCounter::instance()->dump();
-}
-
-void InstanceCounter::incrementInstanceCount(const String& instanceName,
- void* ptr) {
- MutexLocker locker(m_mutex);
- HashMap<String, int>::AddResult result = m_counterMap.add(instanceName, 1);
- if (!result.isNewEntry)
- ++(result.storedValue->value);
-}
-
-void InstanceCounter::decrementInstanceCount(const String& instanceName,
- void* ptr) {
- MutexLocker locker(m_mutex);
- HashMap<String, int>::iterator it = m_counterMap.find(instanceName);
- DCHECK(it != m_counterMap.end());
-
- --(it->value);
- if (!it->value)
- m_counterMap.remove(it);
-}
-
-String InstanceCounter::dump() {
- MutexLocker locker(m_mutex);
-
- StringBuilder builder;
-
- builder.append('{');
- HashMap<String, int>::iterator it = m_counterMap.begin();
- HashMap<String, int>::iterator itEnd = m_counterMap.end();
- for (; it != itEnd; ++it) {
- if (it != m_counterMap.begin())
- builder.append(',');
- builder.append('"');
- builder.append(it->key);
- builder.append("\": ");
- builder.appendNumber(it->value);
- }
- builder.append('}');
-
- return builder.toString();
-}
-
-#else
-
-String dumpRefCountedInstanceCounts() {
- return String("{}");
-}
-
-#endif // ENABLE(INSTANCE_COUNTER)
-
-} // namespace WTF
diff --git a/PrintStream.cpp b/PrintStream.cpp
deleted file mode 100644
index 2a9dde2..0000000
--- a/PrintStream.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/PrintStream.h"
-
-#include "wtf/text/CString.h"
-#include "wtf/text/WTFString.h"
-#include <stdio.h>
-
-namespace WTF {
-
-PrintStream::PrintStream() {}
-PrintStream::~PrintStream() {} // Force the vtable to be in this module
-
-void PrintStream::printf(const char* format, ...) {
- va_list argList;
- va_start(argList, format);
- vprintf(format, argList);
- va_end(argList);
-}
-
-void PrintStream::flush() {}
-
-void printInternal(PrintStream& out, const char* string) {
- out.printf("%s", string);
-}
-
-void printInternal(PrintStream& out, const CString& string) {
- out.print(string.data());
-}
-
-void printInternal(PrintStream& out, const String& string) {
- out.print(string.utf8());
-}
-
-void printInternal(PrintStream& out, bool value) {
- if (value)
- out.print("true");
- else
- out.print("false");
-}
-
-void printInternal(PrintStream& out, int value) {
- out.printf("%d", value);
-}
-
-void printInternal(PrintStream& out, unsigned value) {
- out.printf("%u", value);
-}
-
-void printInternal(PrintStream& out, long value) {
- out.printf("%ld", value);
-}
-
-void printInternal(PrintStream& out, unsigned long value) {
- out.printf("%lu", value);
-}
-
-void printInternal(PrintStream& out, long long value) {
- out.printf("%lld", value);
-}
-
-void printInternal(PrintStream& out, unsigned long long value) {
- out.printf("%llu", value);
-}
-
-void printInternal(PrintStream& out, float value) {
- out.print(static_cast<double>(value));
-}
-
-void printInternal(PrintStream& out, double value) {
- out.printf("%lf", value);
-}
-
-void dumpCharacter(PrintStream& out, char value) {
- out.printf("%c", value);
-}
-
-} // namespace WTF
diff --git a/RefVector.h b/RefVector.h
index 4cfe6e4..1adeee7 100644
--- a/RefVector.h
+++ b/RefVector.h
@@ -1,48 +1,9 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
-#ifndef RefVector_h
-#define RefVector_h
+#include "platform/wtf/RefVector.h"
-#include "wtf/RefCounted.h"
-#include "wtf/RefPtr.h"
-#include "wtf/Vector.h"
-
-namespace blink {
-
-template <typename T>
-class RefVector : public RefCounted<RefVector<T>> {
- public:
- static PassRefPtr<RefVector> create() { return adoptRef(new RefVector<T>); }
- static PassRefPtr<RefVector> create(const Vector<T>& vector) {
- return adoptRef(new RefVector<T>(vector));
- }
- static PassRefPtr<RefVector> create(Vector<T>&& vector) {
- return adoptRef(new RefVector<T>(vector));
- }
- PassRefPtr<RefVector> copy() { return create(vector()); }
-
- const T& operator[](size_t i) const { return m_vector[i]; }
- T& operator[](size_t i) { return m_vector[i]; }
- const T& at(size_t i) const { return m_vector.at(i); }
- T& at(size_t i) { return m_vector.at(i); }
-
- bool operator==(const RefVector& o) const { return m_vector == o.m_vector; }
- bool operator!=(const RefVector& o) const { return m_vector != o.m_vector; }
-
- size_t size() const { return m_vector.size(); }
- bool isEmpty() const { return !size(); }
- void append(const T& decoration) { m_vector.push_back(decoration); }
- const Vector<T>& vector() const { return m_vector; }
-
- private:
- Vector<T> m_vector;
- RefVector() {}
- RefVector(const Vector<T>& vector) : m_vector(vector) {}
- RefVector(Vector<T>&& vector) : m_vector(vector) {}
-};
-
-} // namespace blink
-
-#endif // RefVector_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/SaturatedArithmetic.h b/SaturatedArithmetic.h
index c85f291..5824a06 100644
--- a/SaturatedArithmetic.h
+++ b/SaturatedArithmetic.h
@@ -1,48 +1,9 @@
-/*
- * Copyright (c) 2012, Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+// Copyright 2017 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.
-#ifndef SaturatedArithmetic_h
-#define SaturatedArithmetic_h
+#include "platform/wtf/SaturatedArithmetic.h"
-#include "base/numerics/saturated_arithmetic.h"
-
-namespace WTF {
-using base::SaturatedAddition;
-using base::SaturatedSubtraction;
-using base::SaturatedNegative;
-using base::SaturatedSet;
-} // namespace WTF
-
-using WTF::SaturatedAddition;
-using WTF::SaturatedSubtraction;
-using WTF::SaturatedNegative;
-using WTF::SaturatedSet;
-
-#endif // SaturatedArithmetic_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/ScopedLogger.md b/ScopedLogger.md
deleted file mode 100644
index 5ea0d0f..0000000
--- a/ScopedLogger.md
+++ /dev/null
@@ -1,103 +0,0 @@
-# Debugging with ScopedLogger
-
-## Overview
-
-ScopedLogger is a logger that shows nested calls by indenting.
-
-For example, if you were debugging a layout issue you could add a ScopedLogger
-to the top of the `LayoutBlock::layout` function:
-
-```c++
-void LayoutBlock::layout()
-{
- WTF_CREATE_SCOPED_LOGGER(logger, "layout %s", debugName().utf8().data());
- ...
-```
-
-The arguments of the `WTF_CREATE_SCOPED_LOGGER` macro are the name of the
-object, followed by the first log message, followed by printf-style varargs.
-In the above example, the log message includes the debug name of the block that
-is currently being laid out.
-
-ScopedLogger wraps log messages in parentheses, with indentation proportional to
-the number of instances. This makes it easy to see the flow of control in the
-output, particularly when instrumenting recursive functions. Here is some of
-the output of the above example when laying out www.google.com:
-
-```
-( layout LayoutView #document
- ( layout LayoutBlockFlow HTML
- ( layout LayoutBlockFlow BODY id='gsr' class='hp vasq'
- ( layout LayoutBlockFlow (relative positioned) DIV id='viewport' class='ctr-p'
- ( layout LayoutBlockFlow DIV id='doc-info' )
- ( layout LayoutBlockFlow DIV id='cst' )
- ( layout LayoutBlockFlow (positioned) A )
- ( layout LayoutBlockFlow (positioned) DIV id='searchform' class='jhp' )
- )
- )
- )
-)
-```
-
-## Appending to a ScopedLogger
-
-Every ScopedLogger has an initial log message, which is often sufficient. But
-you can also write additional messages to an existing ScopedLogger with
-`WTF_APPEND_SCOPED_LOGGER`. For example:
-
-```c++
- // further down in LayoutBlock::layout...
-
- if (needsScrollAnchoring) {
- WTF_APPEND_SCOPED_LOGGER(logger, "restoring scroll anchor");
- getScrollableArea()->scrollAnchor().restore();
- }
-```
-
-## Conditional ScopedLoggers
-
-It's often useful to create a ScopedLogger only if some condition is met.
-Unfortunately, the following doesn't work correctly:
-
-```c++
-void foo() {
- if (condition) {
- WTF_CREATE_SCOPED_LOGGER(logger, "foo, with condition");
- // Oops: logger exits scope prematurely!
- }
- bar(); // any ScopedLogger in bar won't nest
-}
-```
-
-To guard a ScopedLogger construction with a condition without restricting its
-scope, use `WTF_CREATE_SCOPED_LOGGER_IF`:
-
-```c++
-void foo() {
- WTF_CREATE_SCOPED_LOGGER_IF(logger, condition, "message");
- bar();
-}
-```
-
-## Requirements
-
-The ScopedLogger class and associated macros are defined in
-[Assertions.h](Assertions.h), which most Blink source files already include
-indirectly. ScopedLogger can't be used outside of Blink code yet.
-
-The ScopedLogger macros work in debug builds by default. They are compiled out
-of release builds, unless your `GYP_DEFINES` or GN args file includes one of the
-following:
-
-* `dcheck_always_on`: enables assertions and ScopedLogger
-* `blink_logging_always_on`: enables ScopedLogger, but not assertions
-
-The macro names are cumbersome to type, but most editors can be configured to
-make this easier. For example, you can add the following to a Sublime Text key
-binding file to make Ctrl+Alt+L insert a ScopedLogger:
-
-```
- { "keys": ["ctrl+alt+l"], "command": "insert",
- "args": {"characters": "WTF_CREATE_SCOPED_LOGGER(logger, \"msg\");"}
- }
-```
diff --git a/SizeLimits.cpp b/SizeLimits.cpp
deleted file mode 100644
index 6999a30..0000000
--- a/SizeLimits.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/Assertions.h"
-#include "wtf/ContainerAnnotations.h"
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
-#include "wtf/RefPtr.h"
-#include "wtf/ThreadRestrictionVerifier.h"
-#include "wtf/Vector.h"
-#include "wtf/text/AtomicString.h"
-#include "wtf/text/WTFString.h"
-#include <memory>
-
-namespace WTF {
-
-#if DCHECK_IS_ON() || ENABLE(SECURITY_ASSERT)
-// The debug/assertion version may get bigger.
-struct SameSizeAsRefCounted {
- int a;
-#if ENABLE(SECURITY_ASSERT)
- bool b;
-#endif
-#if DCHECK_IS_ON()
- bool c;
- ThreadRestrictionVerifier d;
-#endif
-};
-#else
-struct SameSizeAsRefCounted {
- int a;
- // Don't add anything here because this should stay small.
-};
-#endif
-template <typename T, unsigned inlineCapacity = 0>
-struct SameSizeAsVectorWithInlineCapacity;
-
-template <typename T>
-struct SameSizeAsVectorWithInlineCapacity<T, 0> {
- void* bufferPointer;
- unsigned capacity;
- unsigned size;
-};
-
-template <typename T, unsigned inlineCapacity>
-struct SameSizeAsVectorWithInlineCapacity {
- SameSizeAsVectorWithInlineCapacity<T, 0> baseCapacity;
-#if !defined(ANNOTATE_CONTIGUOUS_CONTAINER)
- AlignedBuffer<inlineCapacity * sizeof(T), WTF_ALIGN_OF(T)> inlineBuffer;
-#endif
-};
-
-static_assert(sizeof(std::unique_ptr<int>) == sizeof(int*),
- "std::unique_ptr should stay small");
-static_assert(sizeof(PassRefPtr<RefCounted<int>>) == sizeof(int*),
- "PassRefPtr should stay small");
-static_assert(sizeof(RefCounted<int>) == sizeof(SameSizeAsRefCounted),
- "RefCounted should stay small");
-static_assert(sizeof(RefPtr<RefCounted<int>>) == sizeof(int*),
- "RefPtr should stay small");
-static_assert(sizeof(String) == sizeof(int*), "String should stay small");
-static_assert(sizeof(AtomicString) == sizeof(String),
- "AtomicString should stay small");
-static_assert(sizeof(Vector<int>) ==
- sizeof(SameSizeAsVectorWithInlineCapacity<int>),
- "Vector should stay small");
-static_assert(sizeof(Vector<int, 1>) ==
- sizeof(SameSizeAsVectorWithInlineCapacity<int, 1>),
- "Vector should stay small");
-static_assert(sizeof(Vector<int, 2>) ==
- sizeof(SameSizeAsVectorWithInlineCapacity<int, 2>),
- "Vector should stay small");
-static_assert(sizeof(Vector<int, 3>) ==
- sizeof(SameSizeAsVectorWithInlineCapacity<int, 3>),
- "Vector should stay small");
-} // namespace WTF
diff --git a/StackUtil.cpp b/StackUtil.cpp
deleted file mode 100644
index 0312ad8..0000000
--- a/StackUtil.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2017 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.
-
-#include "wtf/StackUtil.h"
-
-#include "wtf/Assertions.h"
-#include "wtf/Threading.h"
-#include "wtf/WTFThreadData.h"
-
-#if OS(WIN)
-#include <stddef.h>
-#include <windows.h>
-#include <winnt.h>
-#elif defined(__GLIBC__)
-extern "C" void* __libc_stack_end; // NOLINT
-#endif
-
-namespace WTF {
-
-size_t getUnderestimatedStackSize() {
-// FIXME: ASAN bot uses a fake stack as a thread stack frame,
-// and its size is different from the value which APIs tells us.
-#if defined(ADDRESS_SANITIZER)
- return 0;
-#endif
-
-// FIXME: On Mac OSX and Linux, this method cannot estimate stack size
-// correctly for the main thread.
-
-#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
- // pthread_getattr_np() can fail if the thread is not invoked by
- // pthread_create() (e.g., the main thread of webkit_unit_tests).
- // If so, a conservative size estimate is returned.
-
- pthread_attr_t attr;
- int error;
-#if OS(FREEBSD)
- pthread_attr_init(&attr);
- error = pthread_attr_get_np(pthread_self(), &attr);
-#else
- error = pthread_getattr_np(pthread_self(), &attr);
-#endif
- if (!error) {
- void* base;
- size_t size;
- error = pthread_attr_getstack(&attr, &base, &size);
- RELEASE_ASSERT(!error);
- pthread_attr_destroy(&attr);
- return size;
- }
-#if OS(FREEBSD)
- pthread_attr_destroy(&attr);
-#endif
-
- // Return a 512k stack size, (conservatively) assuming the following:
- // - that size is much lower than the pthreads default (x86 pthreads has a 2M
- // default.)
- // - no one is running Blink with an RLIMIT_STACK override, let alone as
- // low as 512k.
- //
- return 512 * 1024;
-#elif OS(MACOSX)
- // pthread_get_stacksize_np() returns too low a value for the main thread on
- // OSX 10.9,
- // http://mail.openjdk.java.net/pipermail/hotspot-dev/2013-October/011369.html
- //
- // Multiple workarounds possible, adopt the one made by
- // https://github.com/robovm/robovm/issues/274
- // (cf.
- // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html
- // on why hardcoding sizes is reasonable.)
- if (pthread_main_np()) {
-#if defined(IOS)
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- size_t guardSize = 0;
- pthread_attr_getguardsize(&attr, &guardSize);
- // Stack size for the main thread is 1MB on iOS including the guard page
- // size.
- return (1 * 1024 * 1024 - guardSize);
-#else
- // Stack size for the main thread is 8MB on OSX excluding the guard page
- // size.
- return (8 * 1024 * 1024);
-#endif
- }
- return pthread_get_stacksize_np(pthread_self());
-#elif OS(WIN) && COMPILER(MSVC)
- return WTFThreadData::threadStackSize();
-#else
-#error "Stack frame size estimation not supported on this platform."
- return 0;
-#endif
-}
-
-void* getStackStart() {
-#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
- pthread_attr_t attr;
- int error;
-#if OS(FREEBSD)
- pthread_attr_init(&attr);
- error = pthread_attr_get_np(pthread_self(), &attr);
-#else
- error = pthread_getattr_np(pthread_self(), &attr);
-#endif
- if (!error) {
- void* base;
- size_t size;
- error = pthread_attr_getstack(&attr, &base, &size);
- RELEASE_ASSERT(!error);
- pthread_attr_destroy(&attr);
- return reinterpret_cast<uint8_t*>(base) + size;
- }
-#if OS(FREEBSD)
- pthread_attr_destroy(&attr);
-#endif
-#if defined(__GLIBC__)
- // pthread_getattr_np can fail for the main thread. In this case
- // just like NaCl we rely on the __libc_stack_end to give us
- // the start of the stack.
- // See https://code.google.com/p/nativeclient/issues/detail?id=3431.
- return __libc_stack_end;
-#else
- NOTREACHED();
- return nullptr;
-#endif
-#elif OS(MACOSX)
- return pthread_get_stackaddr_np(pthread_self());
-#elif OS(WIN) && COMPILER(MSVC)
-// On Windows stack limits for the current thread are available in
-// the thread information block (TIB). Its fields can be accessed through
-// FS segment register on x86 and GS segment register on x86_64.
-#ifdef _WIN64
- return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)));
-#else
- return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
-#endif
-#else
-#error Unsupported getStackStart on this platform.
-#endif
-}
-
-namespace internal {
-
-uintptr_t s_mainThreadStackStart = 0;
-uintptr_t s_mainThreadUnderestimatedStackSize = 0;
-
-void initializeMainThreadStackEstimate() {
- // getStackStart is exclusive, not inclusive (i.e. it points past the last
- // page of the stack in linear order). So, to ensure an inclusive comparison,
- // subtract here and below.
- s_mainThreadStackStart =
- reinterpret_cast<uintptr_t>(getStackStart()) - sizeof(void*);
-
- size_t underestimatedStackSize = getUnderestimatedStackSize();
- if (underestimatedStackSize > sizeof(void*)) {
- underestimatedStackSize = underestimatedStackSize - sizeof(void*);
- }
- s_mainThreadUnderestimatedStackSize = underestimatedStackSize;
-}
-
-#if OS(WIN) && COMPILER(MSVC)
-size_t threadStackSize() {
- // Notice that we cannot use the TIB's StackLimit for the stack end, as i
- // tracks the end of the committed range. We're after the end of the reserved
- // stack area (most of which will be uncommitted, most times.)
- MEMORY_BASIC_INFORMATION stackInfo;
- memset(&stackInfo, 0, sizeof(MEMORY_BASIC_INFORMATION));
- size_t resultSize =
- VirtualQuery(&stackInfo, &stackInfo, sizeof(MEMORY_BASIC_INFORMATION));
- DCHECK_GE(resultSize, sizeof(MEMORY_BASIC_INFORMATION));
- uint8_t* stackEnd = reinterpret_cast<uint8_t*>(stackInfo.AllocationBase);
-
- uint8_t* stackStart = reinterpret_cast<uint8_t*>(WTF::getStackStart());
- RELEASE_ASSERT(stackStart && stackStart > stackEnd);
- size_t s_threadStackSize = static_cast<size_t>(stackStart - stackEnd);
- // When the third last page of the reserved stack is accessed as a
- // guard page, the second last page will be committed (along with removing
- // the guard bit on the third last) _and_ a stack overflow exception
- // is raised.
- //
- // We have zero interest in running into stack overflow exceptions while
- // marking objects, so simply consider the last three pages + one above
- // as off-limits and adjust the reported stack size accordingly.
- //
- // http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-management.aspx
- // explains the details.
- RELEASE_ASSERT(s_threadStackSize > 4 * 0x1000);
- s_threadStackSize -= 4 * 0x1000;
- return s_threadStackSize;
-}
-#endif
-
-} // namespace internal
-
-} // namespace WTF
diff --git a/TerminatedArray.h b/TerminatedArray.h
index 18193a4..8f937d8 100644
--- a/TerminatedArray.h
+++ b/TerminatedArray.h
@@ -1,123 +1,9 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
-#ifndef TerminatedArray_h
-#define TerminatedArray_h
-#include "wtf/Allocator.h"
-#include "wtf/PtrUtil.h"
-#include "wtf/VectorTraits.h"
-#include "wtf/allocator/Partitions.h"
-#include <memory>
+#include "platform/wtf/TerminatedArray.h"
-namespace WTF {
-
-// TerminatedArray<T> represents a sequence of elements of type T in which each
-// element knows whether it is the last element in the sequence or not. For this
-// check type T must provide isLastInArray method.
-// TerminatedArray<T> can only be constructed by TerminatedArrayBuilder<T>.
-template <typename T>
-class TerminatedArray {
- DISALLOW_NEW();
- WTF_MAKE_NONCOPYABLE(TerminatedArray);
-
- public:
- // When TerminatedArray::Allocator implementations grow the backing
- // store, old is copied into the new and larger block.
- static_assert(VectorTraits<T>::canCopyWithMemcpy,
- "Array elements must be memory copyable");
-
- T& at(size_t index) { return reinterpret_cast<T*>(this)[index]; }
- const T& at(size_t index) const {
- return reinterpret_cast<const T*>(this)[index];
- }
-
- template <typename U>
- class iterator_base final {
- STACK_ALLOCATED();
-
- public:
- iterator_base& operator++() {
- if (m_val->isLastInArray()) {
- m_val = 0;
- } else {
- ++m_val;
- }
- return *this;
- }
-
- U& operator*() const { return *m_val; }
-
- bool operator==(const iterator_base& other) const {
- return m_val == other.m_val;
- }
- bool operator!=(const iterator_base& other) const {
- return !(*this == other);
- }
-
- private:
- iterator_base(U* val) : m_val(val) {}
-
- U* m_val;
-
- friend class TerminatedArray;
- };
-
- typedef iterator_base<T> iterator;
- typedef iterator_base<const T> const_iterator;
-
- iterator begin() { return iterator(reinterpret_cast<T*>(this)); }
- const_iterator begin() const {
- return const_iterator(reinterpret_cast<const T*>(this));
- }
-
- iterator end() { return iterator(0); }
- const_iterator end() const { return const_iterator(0); }
-
- size_t size() const {
- size_t count = 0;
- for (const_iterator it = begin(); it != end(); ++it)
- count++;
- return count;
- }
-
- // Match Allocator semantics to be able to use
- // std::unique_ptr<TerminatedArray>.
- void operator delete(void* p) { ::WTF::Partitions::fastFree(p); }
-
- private:
- // Allocator describes how TerminatedArrayBuilder should create new instances
- // of TerminateArray and manage their lifetimes.
- struct Allocator {
- STATIC_ONLY(Allocator);
- using PassPtr = std::unique_ptr<TerminatedArray>;
- using Ptr = std::unique_ptr<TerminatedArray>;
-
- static PassPtr release(Ptr& ptr) { return ptr.release(); }
-
- static PassPtr create(size_t capacity) {
- return WTF::wrapUnique(
- static_cast<TerminatedArray*>(WTF::Partitions::fastMalloc(
- capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T))));
- }
-
- static PassPtr resize(Ptr ptr, size_t capacity) {
- return WTF::wrapUnique(static_cast<TerminatedArray*>(
- WTF::Partitions::fastRealloc(ptr.release(), capacity * sizeof(T),
- WTF_HEAP_PROFILER_TYPE_NAME(T))));
- }
- };
-
- // Prohibit construction. Allocator makes TerminatedArray instances for
- // TerminatedArrayBuilder by pointer casting.
- TerminatedArray();
-
- template <typename, template <typename> class>
- friend class TerminatedArrayBuilder;
-};
-
-} // namespace WTF
-
-using WTF::TerminatedArray;
-
-#endif // TerminatedArray_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/TerminatedArrayBuilder.h b/TerminatedArrayBuilder.h
index 0206261..531d650 100644
--- a/TerminatedArrayBuilder.h
+++ b/TerminatedArrayBuilder.h
@@ -1,78 +1,9 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
-#ifndef TerminatedArrayBuilder_h
-#define TerminatedArrayBuilder_h
-#include "wtf/Allocator.h"
+#include "platform/wtf/TerminatedArrayBuilder.h"
-namespace WTF {
-
-template <typename T, template <typename> class ArrayType = TerminatedArray>
-class TerminatedArrayBuilder {
- STACK_ALLOCATED();
- WTF_MAKE_NONCOPYABLE(TerminatedArrayBuilder);
-
- public:
- explicit TerminatedArrayBuilder(
- typename ArrayType<T>::Allocator::PassPtr array)
- : m_array(array), m_count(0), m_capacity(0) {
- if (!m_array)
- return;
- m_capacity = m_count = m_array->size();
- DCHECK(m_array->at(m_count - 1).isLastInArray());
- }
-
- void grow(size_t count) {
- DCHECK(count);
- if (!m_array) {
- DCHECK(!m_count);
- DCHECK(!m_capacity);
- m_capacity = count;
- m_array = ArrayType<T>::Allocator::create(m_capacity);
- } else {
- DCHECK(m_array->at(m_count - 1).isLastInArray());
- m_capacity += count;
- m_array = ArrayType<T>::Allocator::resize(
- ArrayType<T>::Allocator::release(m_array), m_capacity);
- m_array->at(m_count - 1).setLastInArray(false);
- }
- m_array->at(m_capacity - 1).setLastInArray(true);
- }
-
- void append(const T& item) {
- RELEASE_ASSERT(m_count < m_capacity);
- DCHECK(!item.isLastInArray());
- m_array->at(m_count++) = item;
- if (m_count == m_capacity)
- m_array->at(m_capacity - 1).setLastInArray(true);
- }
-
- typename ArrayType<T>::Allocator::PassPtr release() {
- RELEASE_ASSERT(m_count == m_capacity);
- assertValid();
- return ArrayType<T>::Allocator::release(m_array);
- }
-
- private:
-#if DCHECK_IS_ON()
- void assertValid() {
- for (size_t i = 0; i < m_count; ++i) {
- bool isLastInArray = (i + 1 == m_count);
- DCHECK_EQ(m_array->at(i).isLastInArray(), isLastInArray);
- }
- }
-#else
- void assertValid() {}
-#endif
-
- typename ArrayType<T>::Allocator::Ptr m_array;
- size_t m_count;
- size_t m_capacity;
-};
-
-} // namespace WTF
-
-using WTF::TerminatedArrayBuilder;
-
-#endif // TerminatedArrayBuilder_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/ThreadSpecificWin.cpp b/ThreadSpecificWin.cpp
deleted file mode 100644
index 9e93dbc..0000000
--- a/ThreadSpecificWin.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2009 Jian Li <jianli@chromium.org>
- * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#include "ThreadSpecific.h"
-
-#if OS(WIN)
-
-#include "StdLibExtras.h"
-#include "ThreadingPrimitives.h"
-#include "wtf/Allocator.h"
-#include "wtf/DoublyLinkedList.h"
-
-namespace WTF {
-
-static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList() {
- DEFINE_STATIC_LOCAL(DoublyLinkedList<PlatformThreadSpecificKey>, staticList,
- ());
- return staticList;
-}
-
-static Mutex& destructorsMutex() {
- DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
- return staticMutex;
-}
-
-class PlatformThreadSpecificKey
- : public DoublyLinkedListNode<PlatformThreadSpecificKey> {
- USING_FAST_MALLOC(PlatformThreadSpecificKey);
- WTF_MAKE_NONCOPYABLE(PlatformThreadSpecificKey);
-
- public:
- friend class DoublyLinkedListNode<PlatformThreadSpecificKey>;
-
- PlatformThreadSpecificKey(void (*destructor)(void*))
- : m_destructor(destructor) {
- m_tlsKey = TlsAlloc();
- if (m_tlsKey == TLS_OUT_OF_INDEXES)
- CRASH();
- }
-
- ~PlatformThreadSpecificKey() { TlsFree(m_tlsKey); }
-
- void setValue(void* data) { TlsSetValue(m_tlsKey, data); }
- void* value() { return TlsGetValue(m_tlsKey); }
-
- void callDestructor() {
- if (void* data = value())
- m_destructor(data);
- }
-
- private:
- void (*m_destructor)(void*);
- DWORD m_tlsKey;
- PlatformThreadSpecificKey* m_prev;
- PlatformThreadSpecificKey* m_next;
-};
-
-long& tlsKeyCount() {
- static long count;
- return count;
-}
-
-DWORD* tlsKeys() {
- static DWORD keys[kMaxTlsKeySize];
- return keys;
-}
-
-void threadSpecificKeyCreate(ThreadSpecificKey* key,
- void (*destructor)(void*)) {
- *key = new PlatformThreadSpecificKey(destructor);
-
- MutexLocker locker(destructorsMutex());
- destructorsList().push(*key);
-}
-
-void threadSpecificKeyDelete(ThreadSpecificKey key) {
- MutexLocker locker(destructorsMutex());
- destructorsList().remove(key);
- delete key;
-}
-
-void threadSpecificSet(ThreadSpecificKey key, void* data) {
- key->setValue(data);
-}
-
-void* threadSpecificGet(ThreadSpecificKey key) {
- return key->value();
-}
-
-void ThreadSpecificThreadExit() {
- for (long i = 0; i < tlsKeyCount(); i++) {
- // The layout of ThreadSpecific<T>::Data does not depend on T. So we are
- // safe to do the static cast to ThreadSpecific<int> in order to access its
- // data member.
- ThreadSpecific<int>::Data* data =
- static_cast<ThreadSpecific<int>::Data*>(TlsGetValue(tlsKeys()[i]));
- if (data)
- data->destructor(data);
- }
-
- MutexLocker locker(destructorsMutex());
- PlatformThreadSpecificKey* key = destructorsList().head();
- while (key) {
- PlatformThreadSpecificKey* nextKey = key->next();
- key->callDestructor();
- key = nextKey;
- }
-}
-
-} // namespace WTF
-
-#endif // OS(WIN)
diff --git a/ThreadingPthreads.cpp b/ThreadingPthreads.cpp
deleted file mode 100644
index cdcb377..0000000
--- a/ThreadingPthreads.cpp
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
- * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/Threading.h"
-
-#if OS(POSIX)
-
-#include "wtf/CurrentTime.h"
-#include "wtf/DateMath.h"
-#include "wtf/HashMap.h"
-#include "wtf/StdLibExtras.h"
-#include "wtf/ThreadSpecific.h"
-#include "wtf/ThreadingPrimitives.h"
-#include "wtf/WTFThreadData.h"
-#include "wtf/dtoa/double-conversion.h"
-#include <errno.h>
-#include <limits.h>
-#include <sched.h>
-#include <sys/time.h>
-
-#if OS(MACOSX)
-#include <objc/objc-auto.h>
-#endif
-
-#if OS(LINUX)
-#include <sys/syscall.h>
-#endif
-
-#if OS(LINUX) || OS(ANDROID)
-#include <unistd.h>
-#endif
-
-namespace WTF {
-
-namespace internal {
-
-ThreadIdentifier currentThreadSyscall() {
-#if OS(MACOSX)
- return pthread_mach_thread_np(pthread_self());
-#elif OS(LINUX)
- return syscall(__NR_gettid);
-#elif OS(ANDROID)
- return gettid();
-#else
- return reinterpret_cast<uintptr_t>(pthread_self());
-#endif
-}
-
-} // namespace internal
-
-void initializeThreading() {
- // This should only be called once.
- WTFThreadData::initialize();
-
- initializeDates();
- // Force initialization of static DoubleToStringConverter converter variable
- // inside EcmaScriptConverter function while we are in single thread mode.
- double_conversion::DoubleToStringConverter::EcmaScriptConverter();
-}
-
-namespace {
-ThreadSpecificKey s_currentThreadKey;
-bool s_currentThreadKeyInitialized = false;
-} // namespace
-
-void initializeCurrentThread() {
- DCHECK(!s_currentThreadKeyInitialized);
- threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {});
- s_currentThreadKeyInitialized = true;
-}
-
-ThreadIdentifier currentThread() {
- // This doesn't use WTF::ThreadSpecific (e.g. WTFThreadData) because
- // ThreadSpecific now depends on currentThread. It is necessary to avoid this
- // or a similar loop:
- //
- // currentThread
- // -> wtfThreadData
- // -> ThreadSpecific::operator*
- // -> isMainThread
- // -> currentThread
- static_assert(sizeof(ThreadIdentifier) <= sizeof(void*),
- "ThreadIdentifier must fit in a void*.");
- DCHECK(s_currentThreadKeyInitialized);
- void* value = threadSpecificGet(s_currentThreadKey);
- if (UNLIKELY(!value)) {
- value = reinterpret_cast<void*>(
- static_cast<intptr_t>(internal::currentThreadSyscall()));
- DCHECK(value);
- threadSpecificSet(s_currentThreadKey, value);
- }
- return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey));
-}
-
-MutexBase::MutexBase(bool recursive) {
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(
- &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
-
- int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr);
- DCHECK_EQ(result, 0);
-#if DCHECK_IS_ON()
- m_mutex.m_recursionCount = 0;
-#endif
-
- pthread_mutexattr_destroy(&attr);
-}
-
-MutexBase::~MutexBase() {
- int result = pthread_mutex_destroy(&m_mutex.m_internalMutex);
- DCHECK_EQ(result, 0);
-}
-
-void MutexBase::lock() {
- int result = pthread_mutex_lock(&m_mutex.m_internalMutex);
- DCHECK_EQ(result, 0);
-#if DCHECK_IS_ON()
- ++m_mutex.m_recursionCount;
-#endif
-}
-
-void MutexBase::unlock() {
-#if DCHECK_IS_ON()
- DCHECK(m_mutex.m_recursionCount);
- --m_mutex.m_recursionCount;
-#endif
- int result = pthread_mutex_unlock(&m_mutex.m_internalMutex);
- DCHECK_EQ(result, 0);
-}
-
-// There is a separate tryLock implementation for the Mutex and the
-// RecursiveMutex since on Windows we need to manually check if tryLock should
-// succeed or not for the non-recursive mutex. On Linux the two implementations
-// are equal except we can assert the recursion count is always zero for the
-// non-recursive mutex.
-bool Mutex::tryLock() {
- int result = pthread_mutex_trylock(&m_mutex.m_internalMutex);
- if (result == 0) {
-#if DCHECK_IS_ON()
- // The Mutex class is not recursive, so the recursionCount should be
- // zero after getting the lock.
- DCHECK(!m_mutex.m_recursionCount);
- ++m_mutex.m_recursionCount;
-#endif
- return true;
- }
- if (result == EBUSY)
- return false;
-
- NOTREACHED();
- return false;
-}
-
-bool RecursiveMutex::tryLock() {
- int result = pthread_mutex_trylock(&m_mutex.m_internalMutex);
- if (result == 0) {
-#if DCHECK_IS_ON()
- ++m_mutex.m_recursionCount;
-#endif
- return true;
- }
- if (result == EBUSY)
- return false;
-
- NOTREACHED();
- return false;
-}
-
-ThreadCondition::ThreadCondition() {
- pthread_cond_init(&m_condition, nullptr);
-}
-
-ThreadCondition::~ThreadCondition() {
- pthread_cond_destroy(&m_condition);
-}
-
-void ThreadCondition::wait(MutexBase& mutex) {
- PlatformMutex& platformMutex = mutex.impl();
- int result = pthread_cond_wait(&m_condition, &platformMutex.m_internalMutex);
- DCHECK_EQ(result, 0);
-#if DCHECK_IS_ON()
- ++platformMutex.m_recursionCount;
-#endif
-}
-
-bool ThreadCondition::timedWait(MutexBase& mutex, double absoluteTime) {
- if (absoluteTime < currentTime())
- return false;
-
- if (absoluteTime > INT_MAX) {
- wait(mutex);
- return true;
- }
-
- int timeSeconds = static_cast<int>(absoluteTime);
- int timeNanoseconds = static_cast<int>((absoluteTime - timeSeconds) * 1E9);
-
- timespec targetTime;
- targetTime.tv_sec = timeSeconds;
- targetTime.tv_nsec = timeNanoseconds;
-
- PlatformMutex& platformMutex = mutex.impl();
- int result = pthread_cond_timedwait(
- &m_condition, &platformMutex.m_internalMutex, &targetTime);
-#if DCHECK_IS_ON()
- ++platformMutex.m_recursionCount;
-#endif
- return result == 0;
-}
-
-void ThreadCondition::signal() {
- int result = pthread_cond_signal(&m_condition);
- DCHECK_EQ(result, 0);
-}
-
-void ThreadCondition::broadcast() {
- int result = pthread_cond_broadcast(&m_condition);
- DCHECK_EQ(result, 0);
-}
-
-#if DCHECK_IS_ON()
-static bool s_threadCreated = false;
-
-bool isBeforeThreadCreated() {
- return !s_threadCreated;
-}
-
-void willCreateThread() {
- s_threadCreated = true;
-}
-#endif
-
-} // namespace WTF
-
-#endif // OS(POSIX)
diff --git a/ThreadingWin.cpp b/ThreadingWin.cpp
deleted file mode 100644
index 7f207e1..0000000
--- a/ThreadingWin.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
- * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * There are numerous academic and practical works on how to implement
- * pthread_cond_wait/pthread_cond_signal/pthread_cond_broadcast
- * functions on Win32. Here is one example:
- * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html which is widely credited as
- * a 'starting point' of modern attempts. There are several more or less proven
- * implementations, one in Boost C++ library (http://www.boost.org) and another
- * in pthreads-win32 (http://sourceware.org/pthreads-win32/).
- *
- * The number of articles and discussions is the evidence of significant
- * difficulties in implementing these primitives correctly. The brief search
- * of revisions, ChangeLog entries, discussions in comp.programming.threads and
- * other places clearly documents numerous pitfalls and performance problems
- * the authors had to overcome to arrive to the suitable implementations.
- * Optimally, WebKit would use one of those supported/tested libraries
- * directly. To roll out our own implementation is impractical, if even for
- * the lack of sufficient testing. However, a faithful reproduction of the code
- * from one of the popular supported libraries seems to be a good compromise.
- *
- * The early Boost implementation
- * (http://www.boxbackup.org/trac/browser/box/nick/win/lib/win32/boost_1_32_0/libs/thread/src/condition.cpp?rev=30)
- * is identical to pthreads-win32
- * (http://sourceware.org/cgi-bin/cvsweb.cgi/pthreads/pthread_cond_wait.c?rev=1.10&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32).
- * Current Boost uses yet another (although seemingly equivalent) algorithm
- * which came from their 'thread rewrite' effort.
- *
- * This file includes timedWait/signal/broadcast implementations translated to
- * WebKit coding style from the latest algorithm by Alexander Terekhov and
- * Louis Thomas, as captured here:
- * http://sourceware.org/cgi-bin/cvsweb.cgi/pthreads/pthread_cond_wait.c?rev=1.10&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32
- * It replaces the implementation of their previous algorithm, also documented
- * in the same source above. The naming and comments are left very close to
- * original to enable easy cross-check.
- *
- * The corresponding Pthreads-win32 License is included below, and CONTRIBUTORS
- * file which it refers to is added to source directory (as
- * CONTRIBUTORS.pthreads-win32).
- */
-
-/*
- * Pthreads-win32 - POSIX Threads Library for Win32
- * Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
- * The current list of contributors is contained
- * in the file CONTRIBUTORS included with the source
- * code distribution. The list can also be seen at the
- * following World Wide Web location:
- * http://sources.redhat.com/pthreads-win32/contributors.html
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include "wtf/Threading.h"
-
-#if OS(WIN)
-
-#include "wtf/CurrentTime.h"
-#include "wtf/DateMath.h"
-#include "wtf/HashMap.h"
-#include "wtf/MathExtras.h"
-#include "wtf/ThreadSpecific.h"
-#include "wtf/ThreadingPrimitives.h"
-#include "wtf/WTFThreadData.h"
-#include "wtf/dtoa/double-conversion.h"
-#include <errno.h>
-#include <process.h>
-#include <windows.h>
-
-namespace WTF {
-
-// THREADNAME_INFO comes from
-// <http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>.
-#pragma pack(push, 8)
-typedef struct tagTHREADNAME_INFO {
- DWORD dwType; // must be 0x1000
- LPCSTR szName; // pointer to name (in user addr space)
- DWORD dwThreadID; // thread ID (-1=caller thread)
- DWORD dwFlags; // reserved for future use, must be zero
-} THREADNAME_INFO;
-#pragma pack(pop)
-
-namespace internal {
-
-ThreadIdentifier currentThreadSyscall() {
- return static_cast<ThreadIdentifier>(GetCurrentThreadId());
-}
-
-} // namespace internal
-
-void initializeThreading() {
- // This should only be called once.
- WTFThreadData::initialize();
-
- initializeDates();
- // Force initialization of static DoubleToStringConverter converter variable
- // inside EcmaScriptConverter function while we are in single thread mode.
- double_conversion::DoubleToStringConverter::EcmaScriptConverter();
-}
-
-namespace {
-ThreadSpecificKey s_currentThreadKey;
-bool s_currentThreadKeyInitialized = false;
-} // namespace
-
-void initializeCurrentThread() {
- DCHECK(!s_currentThreadKeyInitialized);
- threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {});
- s_currentThreadKeyInitialized = true;
-}
-
-ThreadIdentifier currentThread() {
- // This doesn't use WTF::ThreadSpecific (e.g. WTFThreadData) because
- // ThreadSpecific now depends on currentThread. It is necessary to avoid this
- // or a similar loop:
- //
- // currentThread
- // -> wtfThreadData
- // -> ThreadSpecific::operator*
- // -> isMainThread
- // -> currentThread
- static_assert(sizeof(ThreadIdentifier) <= sizeof(void*),
- "ThreadIdentifier must fit in a void*.");
- DCHECK(s_currentThreadKeyInitialized);
- void* value = threadSpecificGet(s_currentThreadKey);
- if (UNLIKELY(!value)) {
- value = reinterpret_cast<void*>(internal::currentThreadSyscall());
- DCHECK(value);
- threadSpecificSet(s_currentThreadKey, value);
- }
- return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey));
-}
-
-MutexBase::MutexBase(bool recursive) {
- m_mutex.m_recursionCount = 0;
- InitializeCriticalSection(&m_mutex.m_internalMutex);
-}
-
-MutexBase::~MutexBase() {
- DeleteCriticalSection(&m_mutex.m_internalMutex);
-}
-
-void MutexBase::lock() {
- EnterCriticalSection(&m_mutex.m_internalMutex);
- ++m_mutex.m_recursionCount;
-}
-
-void MutexBase::unlock() {
- DCHECK(m_mutex.m_recursionCount);
- --m_mutex.m_recursionCount;
- LeaveCriticalSection(&m_mutex.m_internalMutex);
-}
-
-bool Mutex::tryLock() {
- // This method is modeled after the behavior of pthread_mutex_trylock,
- // which will return an error if the lock is already owned by the
- // current thread. Since the primitive Win32 'TryEnterCriticalSection'
- // treats this as a successful case, it changes the behavior of several
- // tests in WebKit that check to see if the current thread already
- // owned this mutex (see e.g., IconDatabase::getOrCreateIconRecord)
- DWORD result = TryEnterCriticalSection(&m_mutex.m_internalMutex);
-
- if (result != 0) { // We got the lock
- // If this thread already had the lock, we must unlock and return
- // false since this is a non-recursive mutex. This is to mimic the
- // behavior of POSIX's pthread_mutex_trylock. We don't do this
- // check in the lock method (presumably due to performance?). This
- // means lock() will succeed even if the current thread has already
- // entered the critical section.
- if (m_mutex.m_recursionCount > 0) {
- LeaveCriticalSection(&m_mutex.m_internalMutex);
- return false;
- }
- ++m_mutex.m_recursionCount;
- return true;
- }
-
- return false;
-}
-
-bool RecursiveMutex::tryLock() {
- // CRITICAL_SECTION is recursive/reentrant so TryEnterCriticalSection will
- // succeed if the current thread is already in the critical section.
- DWORD result = TryEnterCriticalSection(&m_mutex.m_internalMutex);
- if (result == 0) { // We didn't get the lock.
- return false;
- }
- ++m_mutex.m_recursionCount;
- return true;
-}
-
-bool PlatformCondition::timedWait(PlatformMutex& mutex,
- DWORD durationMilliseconds) {
- // Enter the wait state.
- DWORD res = WaitForSingleObject(m_blockLock, INFINITE);
- DCHECK_EQ(res, WAIT_OBJECT_0);
- ++m_waitersBlocked;
- res = ReleaseSemaphore(m_blockLock, 1, 0);
- DCHECK(res);
-
- --mutex.m_recursionCount;
- LeaveCriticalSection(&mutex.m_internalMutex);
-
- // Main wait - use timeout.
- bool timedOut =
- (WaitForSingleObject(m_blockQueue, durationMilliseconds) == WAIT_TIMEOUT);
-
- res = WaitForSingleObject(m_unblockLock, INFINITE);
- DCHECK_EQ(res, WAIT_OBJECT_0);
-
- int signalsLeft = m_waitersToUnblock;
-
- if (m_waitersToUnblock) {
- --m_waitersToUnblock;
- } else if (++m_waitersGone == (INT_MAX / 2)) {
- // timeout/canceled or spurious semaphore timeout or spurious wakeup
- // occured, normalize the m_waitersGone count this may occur if many
- // calls to wait with a timeout are made and no call to notify_* is made
- res = WaitForSingleObject(m_blockLock, INFINITE);
- DCHECK_EQ(res, WAIT_OBJECT_0);
- m_waitersBlocked -= m_waitersGone;
- res = ReleaseSemaphore(m_blockLock, 1, 0);
- DCHECK(res);
- m_waitersGone = 0;
- }
-
- res = ReleaseMutex(m_unblockLock);
- DCHECK(res);
-
- if (signalsLeft == 1) {
- res = ReleaseSemaphore(m_blockLock, 1, 0); // Open the gate.
- DCHECK(res);
- }
-
- EnterCriticalSection(&mutex.m_internalMutex);
- ++mutex.m_recursionCount;
-
- return !timedOut;
-}
-
-void PlatformCondition::signal(bool unblockAll) {
- unsigned signalsToIssue = 0;
-
- DWORD res = WaitForSingleObject(m_unblockLock, INFINITE);
- DCHECK_EQ(res, WAIT_OBJECT_0);
-
- if (m_waitersToUnblock) { // the gate is already closed
- if (!m_waitersBlocked) { // no-op
- res = ReleaseMutex(m_unblockLock);
- DCHECK(res);
- return;
- }
-
- if (unblockAll) {
- signalsToIssue = m_waitersBlocked;
- m_waitersToUnblock += m_waitersBlocked;
- m_waitersBlocked = 0;
- } else {
- signalsToIssue = 1;
- ++m_waitersToUnblock;
- --m_waitersBlocked;
- }
- } else if (m_waitersBlocked > m_waitersGone) {
- res = WaitForSingleObject(m_blockLock, INFINITE); // Close the gate.
- DCHECK_EQ(res, WAIT_OBJECT_0);
- if (m_waitersGone != 0) {
- m_waitersBlocked -= m_waitersGone;
- m_waitersGone = 0;
- }
- if (unblockAll) {
- signalsToIssue = m_waitersBlocked;
- m_waitersToUnblock = m_waitersBlocked;
- m_waitersBlocked = 0;
- } else {
- signalsToIssue = 1;
- m_waitersToUnblock = 1;
- --m_waitersBlocked;
- }
- } else { // No-op.
- res = ReleaseMutex(m_unblockLock);
- DCHECK(res);
- return;
- }
-
- res = ReleaseMutex(m_unblockLock);
- DCHECK(res);
-
- if (signalsToIssue) {
- res = ReleaseSemaphore(m_blockQueue, signalsToIssue, 0);
- DCHECK(res);
- }
-}
-
-static const long MaxSemaphoreCount = static_cast<long>(~0UL >> 1);
-
-ThreadCondition::ThreadCondition() {
- m_condition.m_waitersGone = 0;
- m_condition.m_waitersBlocked = 0;
- m_condition.m_waitersToUnblock = 0;
- m_condition.m_blockLock = CreateSemaphore(0, 1, 1, 0);
- m_condition.m_blockQueue = CreateSemaphore(0, 0, MaxSemaphoreCount, 0);
- m_condition.m_unblockLock = CreateMutex(0, 0, 0);
-
- if (!m_condition.m_blockLock || !m_condition.m_blockQueue ||
- !m_condition.m_unblockLock) {
- if (m_condition.m_blockLock)
- CloseHandle(m_condition.m_blockLock);
- if (m_condition.m_blockQueue)
- CloseHandle(m_condition.m_blockQueue);
- if (m_condition.m_unblockLock)
- CloseHandle(m_condition.m_unblockLock);
-
- m_condition.m_blockLock = nullptr;
- m_condition.m_blockQueue = nullptr;
- m_condition.m_unblockLock = nullptr;
- }
-}
-
-ThreadCondition::~ThreadCondition() {
- if (m_condition.m_blockLock)
- CloseHandle(m_condition.m_blockLock);
- if (m_condition.m_blockQueue)
- CloseHandle(m_condition.m_blockQueue);
- if (m_condition.m_unblockLock)
- CloseHandle(m_condition.m_unblockLock);
-}
-
-void ThreadCondition::wait(MutexBase& mutex) {
- m_condition.timedWait(mutex.impl(), INFINITE);
-}
-
-bool ThreadCondition::timedWait(MutexBase& mutex, double absoluteTime) {
- DWORD interval = absoluteTimeToWaitTimeoutInterval(absoluteTime);
-
- if (!interval) {
- // Consider the wait to have timed out, even if our condition has already
- // been signaled, to match the pthreads implementation.
- return false;
- }
-
- return m_condition.timedWait(mutex.impl(), interval);
-}
-
-void ThreadCondition::signal() {
- m_condition.signal(false); // Unblock only 1 thread.
-}
-
-void ThreadCondition::broadcast() {
- m_condition.signal(true); // Unblock all threads.
-}
-
-DWORD absoluteTimeToWaitTimeoutInterval(double absoluteTime) {
- double currentTime = WTF::currentTime();
-
- // Time is in the past - return immediately.
- if (absoluteTime < currentTime)
- return 0;
-
- // Time is too far in the future (and would overflow unsigned long) - wait
- // forever.
- if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0)
- return INFINITE;
-
- return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0);
-}
-
-#if DCHECK_IS_ON()
-static bool s_threadCreated = false;
-
-bool isBeforeThreadCreated() {
- return !s_threadCreated;
-}
-
-void willCreateThread() {
- s_threadCreated = true;
-}
-#endif
-
-} // namespace WTF
-
-#endif // OS(WIN)
diff --git a/WTF.cpp b/WTF.cpp
deleted file mode 100644
index 201efc2..0000000
--- a/WTF.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "wtf/WTF.h"
-
-#include "wtf/Assertions.h"
-#include "wtf/Functional.h"
-#include "wtf/StackUtil.h"
-#include "wtf/ThreadSpecific.h"
-#include "wtf/Threading.h"
-#include "wtf/allocator/Partitions.h"
-#include "wtf/text/AtomicString.h"
-#include "wtf/text/StringStatics.h"
-#include "wtf/typed_arrays/ArrayBufferContents.h"
-
-namespace WTF {
-
-extern void initializeThreading();
-
-bool s_initialized;
-void (*s_callOnMainThreadFunction)(MainThreadFunction, void*);
-ThreadIdentifier s_mainThreadIdentifier;
-
-namespace internal {
-
-void callOnMainThread(MainThreadFunction* function, void* context) {
- (*s_callOnMainThreadFunction)(function, context);
-}
-
-} // namespace internal
-
-bool isMainThread() {
- return currentThread() == s_mainThreadIdentifier;
-}
-
-void initialize(void (*callOnMainThreadFunction)(MainThreadFunction, void*)) {
- // WTF, and Blink in general, cannot handle being re-initialized.
- // Make that explicit here.
- RELEASE_ASSERT(!s_initialized);
- s_initialized = true;
- initializeCurrentThread();
- s_mainThreadIdentifier = currentThread();
-
- initializeThreading();
-
- s_callOnMainThreadFunction = callOnMainThreadFunction;
- internal::initializeMainThreadStackEstimate();
- AtomicString::init();
- StringStatics::init();
-}
-
-} // namespace WTF
diff --git a/WTFThreadData.cpp b/WTFThreadData.cpp
deleted file mode 100644
index 7130a88..0000000
--- a/WTFThreadData.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "wtf/WTFThreadData.h"
-
-#include "wtf/StackUtil.h"
-#include "wtf/text/AtomicStringTable.h"
-#include "wtf/text/TextCodecICU.h"
-
-namespace WTF {
-
-ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
-
-WTFThreadData::WTFThreadData()
- : m_atomicStringTable(new AtomicStringTable),
- m_cachedConverterICU(new ICUConverterWrapper),
- m_threadId(internal::currentThreadSyscall()) {}
-
-WTFThreadData::~WTFThreadData() {}
-
-void WTFThreadData::initialize() {
- DCHECK(!WTFThreadData::staticData);
- WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>;
- wtfThreadData();
-}
-
-#if OS(WIN) && COMPILER(MSVC)
-size_t WTFThreadData::threadStackSize() {
- // Needed to bootstrap WTFThreadData on Windows, because this value is needed
- // before the main thread data is fully initialized.
- if (!WTFThreadData::staticData->isSet())
- return internal::threadStackSize();
-
- WTFThreadData& data = wtfThreadData();
- if (!data.m_threadStackSize)
- data.m_threadStackSize = internal::threadStackSize();
- return data.m_threadStackSize;
-}
-#endif
-
-} // namespace WTF
diff --git a/debug/Alias.h b/debug/Alias.h
index 8907924..b736837 100644
--- a/debug/Alias.h
+++ b/debug/Alias.h
@@ -1,20 +1,9 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
-#ifndef WTF_Alias_h
-#define WTF_Alias_h
+#include "platform/wtf/debug/Alias.h"
-#include "base/debug/alias.h"
-
-namespace WTF {
-namespace debug {
-
-inline void alias(const void* var) {
- base::debug::Alias(var);
-}
-
-} // namespace debug
-} // namespace WTF
-
-#endif // WTF_Alias_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
diff --git a/debug/CrashLogging.h b/debug/CrashLogging.h
index 6bfdba1..037a821 100644
--- a/debug/CrashLogging.h
+++ b/debug/CrashLogging.h
@@ -1,19 +1,9 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2017 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.
-#ifndef WTF_CrashLogging_h
-#define WTF_CrashLogging_h
+#include "platform/wtf/debug/CrashLogging.h"
-#include "base/debug/crash_logging.h"
-#include "wtf/WTFExport.h"
-
-namespace WTF {
-namespace debug {
-
-using ScopedCrashKey = base::debug::ScopedCrashKey;
-
-} // namespace debug
-} // namespace WTF
-
-#endif // WTF_CrashLogging_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ