VirtualBox

vbox的更動 41763 路徑 trunk/src/VBox/Runtime/r3/posix


忽略:
時間撮記:
2012-6-15 下午05:35:41 (12 年 以前)
作者:
vboxsync
訊息:

IPRT/thread-posix.cpp: Use pthread_setname_np if present (currently darwin only).

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp

    r37733 r41763  
    4848# include <mach/mach_host.h>
    4949#endif
     50#if defined(RT_OS_DARWIN) /*|| defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) - later */ \
     51 || defined(IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP)
     52# define IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP
     53# include <dlfcn.h>
     54#endif
    5055
    5156#include <iprt/thread.h>
     
    7782static int              g_iSigPokeThread = -1;
    7883#endif
     84
     85#ifdef IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP
     86# if defined(RT_OS_DARWIN)
     87/**
     88 * The Mac OS X (10.6 and later) variant of pthread_setname_np.
     89 *
     90 * @returns errno.h
     91 * @param   pszName         The new thread name.
     92 */
     93typedef int (*PFNPTHREADSETNAME)(const char *pszName);
     94# elif
     95/**
     96 * The variant of pthread_setname_np most other unix-like systems implement.
     97 *
     98 * @returns errno.h
     99 * @param   hThread         The thread.
     100 * @param   pszName         The new thread name.
     101 */
     102typedef int (*PFNPTHREADSETNAME)(pthread_t hThread, const char *pszName);
     103# endif
     104
     105/** Pointer to pthread_setname_np if found. */
     106static PFNPTHREADSETNAME g_pfnThreadSetName = NULL;
     107#endif /* IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP */
    79108
    80109
     
    143172    }
    144173#endif /* RTTHREAD_POSIX_WITH_POKE */
     174
     175#ifdef IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP
     176    if (RT_SUCCESS(rc))
     177        g_pfnThreadSetName = (PFNPTHREADSETNAME)(uintptr_t)dlsym(RTLD_DEFAULT, "pthread_setname_np");
     178#endif
    145179    return rc;
    146180}
     
    245279#endif
    246280
     281    /*
     282     * Set the TLS entry and, if possible, the thread name.
     283     */
    247284    int rc = pthread_setspecific(g_SelfKey, pThread);
    248285    AssertReleaseMsg(!rc, ("failed to set self TLS. rc=%d thread '%s'\n", rc, pThread->szName));
     286
     287#ifdef IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP
     288    if (g_pfnThreadSetName)
     289        g_pfnThreadSetName(pThread->szName);
     290#endif
    249291
    250292    /*
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette