michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MainThreadUtils_h_ michael@0: #define MainThreadUtils_h_ michael@0: michael@0: #include "nscore.h" michael@0: #include "mozilla/threads/nsThreadIDs.h" michael@0: michael@0: class nsIThread; michael@0: michael@0: /** michael@0: * Get a reference to the main thread. michael@0: * michael@0: * @param result michael@0: * The resulting nsIThread object. michael@0: */ michael@0: extern NS_COM_GLUE NS_METHOD michael@0: NS_GetMainThread(nsIThread **result); michael@0: michael@0: #if defined(MOZILLA_INTERNAL_API) && defined(XP_WIN) michael@0: bool NS_IsMainThread(); michael@0: #elif defined(MOZILLA_INTERNAL_API) && defined(NS_TLS) michael@0: // This is defined in nsThreadManager.cpp and initialized to `Main` for the michael@0: // main thread by nsThreadManager::Init. michael@0: extern NS_TLS mozilla::threads::ID gTLSThreadID; michael@0: #ifdef MOZ_ASAN michael@0: // Temporary workaround, see bug 895845 michael@0: MOZ_ASAN_BLACKLIST bool NS_IsMainThread(); michael@0: #else michael@0: inline michael@0: bool NS_IsMainThread() michael@0: { michael@0: return gTLSThreadID == mozilla::threads::Main; michael@0: } michael@0: #endif michael@0: #else michael@0: /** michael@0: * Test to see if the current thread is the main thread. michael@0: * michael@0: * @returns true if the current thread is the main thread, and false michael@0: * otherwise. michael@0: */ michael@0: extern NS_COM_GLUE bool NS_IsMainThread(); michael@0: #endif michael@0: michael@0: #endif // MainThreadUtils_h_