VirtualBox

Changeset 58300 in vbox


Ignore:
Timestamp:
Oct 18, 2015 7:52:19 PM (9 years ago)
Author:
vboxsync
Message:

RTLocalIpc: Added RTLocalIpcSessionRetain and RTLocalIpcSessionRelease.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/localipc.h

    r58297 r58300  
    138138/** @} */
    139139
    140 
    141140/**
    142141 * Closes the local IPC session.
    143142 *
    144143 * This can be used with sessions created by both RTLocalIpcSessionConnect
    145  * and RTLocalIpcServerListen.
     144 * and RTLocalIpcServerListen.  It will release one cancel pending I/O and
     145 * relase one reference (typically the implict reference from the create API).
    146146 *
    147147 * @returns IPRT status code.
     
    152152 */
    153153RTDECL(int) RTLocalIpcSessionClose(RTLOCALIPCSESSION hSession);
     154
     155/**
     156 * Retain a refence to the given session.
     157 *
     158 * @returns New reference count, UINT32_MAX if the handle is invalid.
     159 * @param   hSession            The session handle.
     160 */
     161RTDECL(uint32_t) RTLocalIpcSessionRetain(RTLOCALIPCSESSION hSession);
     162
     163/**
     164 * Releases a refence to the given session.
     165 *
     166 * This differs from RTLocalIpcSessionClose in that it won't cancel any pending
     167 * I/O.  So, better call RTLocalIpcSessionClose if you want to terminate the
     168 * session.
     169 *
     170 * @returns New reference count, 0 if NIL handle, UINT32_MAX if the handle is
     171 *          invalid.
     172 * @param   hSession            The session handle.
     173 */
     174RTDECL(uint32_t) RTLocalIpcSessionRelease(RTLOCALIPCSESSION hSession);
     175
    154176
    155177/**
  • trunk/include/iprt/mangling.h

    r58295 r58300  
    743743# define RTLocalIpcSessionRead                          RT_MANGLER(RTLocalIpcSessionRead)
    744744# define RTLocalIpcSessionReadNB                        RT_MANGLER(RTLocalIpcSessionReadNB)
     745# define RTLocalIpcSessionRetain                        RT_MANGLER(RTLocalIpcSessionRetain)
     746# define RTLocalIpcSessionRelease                       RT_MANGLER(RTLocalIpcSessionRelease)
    745747# define RTLocalIpcSessionWrite                         RT_MANGLER(RTLocalIpcSessionWrite)
    746748# define RTLocalIpcSessionFlush                         RT_MANGLER(RTLocalIpcSessionFlush)
  • trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp

    r58297 r58300  
    557557
    558558
     559RTDECL(uint32_t) RTLocalIpcSessionRetain(RTLOCALIPCSESSION hSession)
     560{
     561    PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession;
     562    AssertPtrReturn(pThis, UINT32_MAX);
     563    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, UINT32_MAX);
     564
     565    uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
     566    Assert(cRefs < UINT32_MAX / 2 && cRefs);
     567    return cRefs;
     568}
     569
     570
    559571/**
    560572 * Session instance destructor.
     
    590602    Log(("rtLocalIpcSessionRelease: %u refs left\n", cRefs));
    591603    return VINF_SUCCESS;
     604}
     605
     606
     607RTDECL(uint32_t) RTLocalIpcSessionRelease(RTLOCALIPCSESSION hSession)
     608{
     609    if (hSession == NIL_RTLOCALIPCSESSION)
     610        return 0;
     611
     612    PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession;
     613    AssertPtrReturn(pThis, UINT32_MAX);
     614    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, UINT32_MAX);
     615
     616    uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
     617    Assert(cRefs < UINT32_MAX / 2);
     618    if (cRefs)
     619        Log(("RTLocalIpcSessionRelease: %u refs left\n", cRefs));
     620    else
     621        rtLocalIpcSessionDtor(pThis);
     622    return cRefs;
    592623}
    593624
  • trunk/src/VBox/Runtime/r3/win/localipc-win.cpp

    r58299 r58300  
    909909
    910910
     911RTDECL(uint32_t) RTLocalIpcSessionRetain(RTLOCALIPCSESSION hSession)
     912{
     913    PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession;
     914    AssertPtrReturn(pThis, UINT32_MAX);
     915    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, UINT32_MAX);
     916
     917    uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
     918    Assert(cRefs < UINT32_MAX / 2 && cRefs);
     919    return cRefs;
     920}
     921
     922
    911923/**
    912924 * Call when the reference count reaches 0.
     
    936948    RTMemFree(pThis);
    937949    return VINF_OBJECT_DESTROYED;
    938 }
    939 
    940 
    941 /**
    942  * Session instance destructor.
    943  *
    944  * @returns VINF_OBJECT_DESTROYED
    945  * @param   pThis               The server instance.
    946  */
    947 DECL_NO_INLINE(static, int) rtLocalIpcSessionDtor(PRTLOCALIPCSESSIONINT pThis)
    948 {
    949     RTCritSectEnter(&pThis->CritSect);
    950     return rtLocalIpcSessionWinDestroy(pThis);
    951 }
    952 
    953 
    954 /**
    955  * Releases a reference to the session instance.
    956  *
    957  * @returns VINF_SUCCESS or VINF_OBJECT_DESTROYED as appropriate.
    958  * @param   pThis               The session instance.
    959  */
    960 DECLINLINE(int) rtLocalIpcSessionRelease(PRTLOCALIPCSESSIONINT pThis)
    961 {
    962     uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
    963     Assert(cRefs < UINT32_MAX / 2);
    964     if (!cRefs)
    965         return rtLocalIpcSessionDtor(pThis);
    966     Log(("rtLocalIpcSessionRelease: %u refs left\n", cRefs));
    967     return VINF_SUCCESS;
    968950}
    969951
     
    983965
    984966    int rc2 = RTCritSectLeave(&pThis->CritSect); AssertRC(rc2);
    985     Log(("rtLocalIpcSessionRelease: %u refs left\n", cRefs));
     967    Log(("rtLocalIpcSessionReleaseAndUnlock: %u refs left\n", cRefs));
    986968    return VINF_SUCCESS;
     969}
     970
     971
     972RTDECL(uint32_t) RTLocalIpcSessionRelease(RTLOCALIPCSESSION hSession)
     973{
     974    if (hSession == NIL_RTLOCALIPCSESSION)
     975        return 0;
     976
     977    PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession;
     978    AssertPtrReturn(pThis, UINT32_MAX);
     979    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, UINT32_MAX);
     980
     981    uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
     982    Assert(cRefs < UINT32_MAX / 2);
     983    if (cRefs)
     984        Log(("RTLocalIpcSessionRelease: %u refs left\n", cRefs));
     985    else
     986    {
     987        RTCritSectEnter(&pThis->CritSect);
     988        rtLocalIpcSessionWinDestroy(pThis);
     989    }
     990    return cRefs;
    987991}
    988992
     
    10021006     * Invalidate the instance, cancel all outstanding I/O and drop our reference.
    10031007     */
    1004     AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, ~RTLOCALIPCSESSION_MAGIC, RTLOCALIPCSESSION_MAGIC), VERR_WRONG_ORDER);
    1005 
    10061008    RTCritSectEnter(&pThis->CritSect);
    10071009    rtLocalIpcWinCancel(pThis);
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