| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef StackUtil_h | 5 #include "platform/wtf/StackUtil.h" |
| 6 #define StackUtil_h | |
| 7 | 6 |
| 8 #include "wtf/Compiler.h" | 7 // The contents of this header was moved to platform/wtf as part of |
| 9 #include "wtf/WTFExport.h" | 8 // WTF migration project. See the following post for details: |
| 10 #include "wtf/build_config.h" | 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY
CAAJ |
| 11 #include <stddef.h> | |
| 12 #include <stdint.h> | |
| 13 | |
| 14 namespace WTF { | |
| 15 | |
| 16 WTF_EXPORT size_t getUnderestimatedStackSize(); | |
| 17 WTF_EXPORT void* getStackStart(); | |
| 18 | |
| 19 namespace internal { | |
| 20 | |
| 21 WTF_EXPORT extern uintptr_t s_mainThreadStackStart; | |
| 22 WTF_EXPORT extern uintptr_t s_mainThreadUnderestimatedStackSize; | |
| 23 | |
| 24 WTF_EXPORT void initializeMainThreadStackEstimate(); | |
| 25 | |
| 26 #if OS(WIN) && COMPILER(MSVC) | |
| 27 size_t threadStackSize(); | |
| 28 #endif | |
| 29 | |
| 30 } // namespace internal | |
| 31 | |
| 32 // Returns true if the function is not called on the main thread. Note carefully | |
| 33 // that this function may have false positives, i.e. it can return true even if | |
| 34 // we are on the main thread. If the function returns false, we are certainly | |
| 35 // on the main thread. | |
| 36 inline bool mayNotBeMainThread() { | |
| 37 uintptr_t dummy; | |
| 38 uintptr_t addressDiff = | |
| 39 internal::s_mainThreadStackStart - reinterpret_cast<uintptr_t>(&dummy); | |
| 40 // This is a fast way to judge if we are in the main thread. | |
| 41 // If |&dummy| is within |s_mainThreadUnderestimatedStackSize| byte from | |
| 42 // the stack start of the main thread, we judge that we are in | |
| 43 // the main thread. | |
| 44 return addressDiff >= internal::s_mainThreadUnderestimatedStackSize; | |
| 45 } | |
| 46 | |
| 47 } // namespace WTF | |
| 48 | |
| 49 #endif // StackUtil_h | |
| OLD | NEW |