VirtualBox

Changeset 11596

Show
Ignore:
Timestamp:
08/24/08 01:25:03 (3 months ago)
Author:
vboxsync
Message:

iprt: Added RTThreadCreateV and RTThreadCreateF which takes a format string and arguments for the thread name.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/iprt/thread.h

    r8645 r11596  
    3333#include <iprt/cdefs.h> 
    3434#include <iprt/types.h> 
     35#include <iprt/stdarg.h> 
    3536 
    3637#ifdef IN_GC 
     
    216217 
    217218/** 
     219 * Create a new thread.  
     220 *   
     221 * Same as RTThreadCreate except the name is given in the RTStrPrintfV form. 
     222 * 
     223 * @returns iprt status code. 
     224 * @param   pThread     See RTThreadCreate. 
     225 * @param   pfnThread   See RTThreadCreate. 
     226 * @param   pvUser      See RTThreadCreate. 
     227 * @param   cbStack     See RTThreadCreate. 
     228 * @param   enmType     See RTThreadCreate. 
     229 * @param   fFlags      See RTThreadCreate. 
     230 * @param   pszName     Thread name format. 
     231 * @param   va          Format arguments. 
     232 */ 
     233RTDECL(int) RTThreadCreateV(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 
     234                            RTTHREADTYPE enmType, uint32_t fFlags, const char *pszNameFmt, va_list va); 
     235 
     236/** 
     237 * Create a new thread.  
     238 *   
     239 * Same as RTThreadCreate except the name is given in the RTStrPrintf form. 
     240 * 
     241 * @returns iprt status code. 
     242 * @param   pThread     See RTThreadCreate. 
     243 * @param   pfnThread   See RTThreadCreate. 
     244 * @param   pvUser      See RTThreadCreate. 
     245 * @param   cbStack     See RTThreadCreate. 
     246 * @param   enmType     See RTThreadCreate. 
     247 * @param   fFlags      See RTThreadCreate. 
     248 * @param   pszName     Thread name format. 
     249 * @param   ...         Format arguments. 
     250 */ 
     251RTDECL(int) RTThreadCreateF(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 
     252                            RTTHREADTYPE enmType, uint32_t fFlags, const char *pszNameFmt, ...); 
     253 
     254/** 
    218255 * Gets the native thread id of a IPRT thread. 
    219256 * 
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r10795 r11596  
    114114 * in thread local storage (TLS). 
    115115 * 
    116  * In Ring-0 we only try keep track of kernel threads created by RTCreateThread 
     116 * In Ring-0 we only try keep track of kernel threads created by RTThreadCreate 
    117117 * at the moment. There we really only need the 'join' feature, but doing things 
    118118 * the same way allow us to name threads and similar stuff. 
     
    716716    LogFlow(("RTThreadCreate: Failed to create thread, rc=%Vrc\n", rc)); 
    717717    AssertReleaseRC(rc); 
     718    return rc; 
     719} 
     720 
     721 
     722/** 
     723 * Create a new thread.  
     724 *   
     725 * Same as RTThreadCreate except the name is given in the RTStrPrintfV form. 
     726 * 
     727 * @returns iprt status code. 
     728 * @param   pThread     See RTThreadCreate. 
     729 * @param   pfnThread   See RTThreadCreate. 
     730 * @param   pvUser      See RTThreadCreate. 
     731 * @param   cbStack     See RTThreadCreate. 
     732 * @param   enmType     See RTThreadCreate. 
     733 * @param   fFlags      See RTThreadCreate. 
     734 * @param   pszName     Thread name format. 
     735 * @param   va          Format arguments. 
     736 */ 
     737RTDECL(int) RTThreadCreateV(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 
     738                            RTTHREADTYPE enmType, uint32_t fFlags, const char *pszNameFmt, va_list va) 
     739{ 
     740    char szName[RTTHREAD_NAME_LEN * 2]; 
     741    RTStrPrintfV(szName, sizeof(szName), pszNameFmt, va); 
     742    return RTThreadCreate(pThread, pfnThread, pvUser, cbStack, enmType, fFlags, szName); 
     743} 
     744 
     745 
     746/** 
     747 * Create a new thread.  
     748 *   
     749 * Same as RTThreadCreate except the name is given in the RTStrPrintf form. 
     750 * 
     751 * @returns iprt status code. 
     752 * @param   pThread     See RTThreadCreate. 
     753 * @param   pfnThread   See RTThreadCreate. 
     754 * @param   pvUser      See RTThreadCreate. 
     755 * @param   cbStack     See RTThreadCreate. 
     756 * @param   enmType     See RTThreadCreate. 
     757 * @param   fFlags      See RTThreadCreate. 
     758 * @param   pszName     Thread name format. 
     759 * @param   ...         Format arguments. 
     760 */ 
     761RTDECL(int) RTThreadCreateF(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 
     762                            RTTHREADTYPE enmType, uint32_t fFlags, const char *pszNameFmt, ...) 
     763{ 
     764    va_list va; 
     765    va_start(va, pszNameFmt); 
     766    int rc = RTThreadCreateV(pThread, pfnThread, pvUser, cbStack, enmType, fFlags, pszNameFmt, va); 
     767    va_end(va); 
    718768    return rc; 
    719769} 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy