VirtualBox

Changeset 18989 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Apr 17, 2009 1:01:30 PM (16 years ago)
Author:
vboxsync
Message:

iprt/process: update the cached process ID on fork

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/init.cpp

    r18196 r18989  
    5151#include <iprt/string.h>
    5252#include <iprt/param.h>
     53#include <iprt/process.h>
    5354#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
    5455# include <iprt/file.h>
     
    231232     * The Process ID.
    232233     */
    233 #ifdef _MSC_VER
    234     g_ProcessSelf = _getpid(); /* crappy ansi compiler */
    235 #else
    236     g_ProcessSelf = getpid();
    237 #endif
     234    /* The first call to RTProcSelf lazily initialises the cached pid, and
     235     * on posix systems also sets a callback to update the cache on fork.
     236     * We just do a dummy call to it here rather than duplicating
     237     * initialisation code. */
     238    /** @todo since we do lazy initialisation anyway, do we really also need
     239     * to do it explicitly? */
     240    RTProcSelf();
    238241
    239242    /*
  • trunk/src/VBox/Runtime/r3/process.cpp

    r11836 r18989  
    4747#endif
    4848
     49#if !defined (RT_OS_OS2) && !defined(RT_OS_WINDOWS)
     50# include <pthread.h>
     51#endif
     52
     53#if !defined (RT_OS_OS2) && !defined(RT_OS_WINDOWS)
     54/** Update the cached pid on fork on posix systems */
     55static void rtProcPThreadAtFork(void)
     56{
     57    g_ProcessSelf = getpid();
     58}
     59#endif
    4960
    5061/**
     
    6071
    6172    /* lazy init. */
     73#if !defined (RT_OS_OS2) && !defined(RT_OS_WINDOWS)
     74    /* Update the cached pid on fork on posix systems */
     75    if (pthread_atfork(NULL, NULL, rtProcPThreadAtFork) != 0)
     76        return 0;
     77#endif
    6278#ifdef _MSC_VER
    6379    Self = _getpid(); /* crappy ansi compiler */
Note: See TracChangeset for help on using the changeset viewer.

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