xpcom/glue/MainThreadUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/MainThreadUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef MainThreadUtils_h_
    1.11 +#define MainThreadUtils_h_
    1.12 +
    1.13 +#include "nscore.h"
    1.14 +#include "mozilla/threads/nsThreadIDs.h"
    1.15 +
    1.16 +class nsIThread;
    1.17 +
    1.18 +/**
    1.19 + * Get a reference to the main thread.
    1.20 + *
    1.21 + * @param result
    1.22 + *   The resulting nsIThread object.
    1.23 + */
    1.24 +extern NS_COM_GLUE NS_METHOD
    1.25 +NS_GetMainThread(nsIThread **result);
    1.26 +
    1.27 +#if defined(MOZILLA_INTERNAL_API) && defined(XP_WIN)
    1.28 +bool NS_IsMainThread();
    1.29 +#elif defined(MOZILLA_INTERNAL_API) && defined(NS_TLS)
    1.30 +// This is defined in nsThreadManager.cpp and initialized to `Main` for the
    1.31 +// main thread by nsThreadManager::Init.
    1.32 +extern NS_TLS mozilla::threads::ID gTLSThreadID;
    1.33 +#ifdef MOZ_ASAN
    1.34 +// Temporary workaround, see bug 895845
    1.35 +MOZ_ASAN_BLACKLIST bool NS_IsMainThread();
    1.36 +#else
    1.37 +inline
    1.38 +bool NS_IsMainThread()
    1.39 +{
    1.40 +  return gTLSThreadID == mozilla::threads::Main;
    1.41 +}
    1.42 +#endif
    1.43 +#else
    1.44 +/**
    1.45 + * Test to see if the current thread is the main thread.
    1.46 + *
    1.47 + * @returns true if the current thread is the main thread, and false
    1.48 + * otherwise.
    1.49 + */
    1.50 +extern NS_COM_GLUE bool NS_IsMainThread();
    1.51 +#endif
    1.52 +
    1.53 +#endif // MainThreadUtils_h_

mercurial