VirtualBox

Changeset 27772 in vbox for trunk/src


Ignore:
Timestamp:
Mar 29, 2010 9:42:20 AM (15 years ago)
Author:
vboxsync
Message:

Backed out 59389 (r3/socket.cpp) as it seems to cause some really weird regression for single threaded apps (latperf) besides not being complete and what I had in mind.

File:
1 edited

Legend:

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

    r27755 r27772  
    121121    /** Magic number (RTTCPSOCKET_MAGIC). */
    122122    uint32_t            u32Magic;
    123     /** Usage bit.  This is used to prevent two threads from accessing the
     123    /** Usage count.  This is used to prevent two threads from accessing the
    124124     *  handle concurrently. */
    125125    uint32_t volatile   cUsers;
    126     /* Number of references to this object */
    127     int32_t volatile    cRefs;
    128126    /** The native socket handle. */
    129127    RTSOCKETNATIVE      hNative;
     
    214212
    215213/**
    216  * Increase reference counter of socket. This is orthogonal to usage bit,
    217  * as some users of socket may not really modify its state (such as RTSocketSelectOne())
    218  * or be allowed to perform operation disregarding if socket is in use (such as RTSocketShutdown()).
    219  *
    220  * Call rtSocketRelease() when done with socket.
    221  *
    222  * @returns @c true if object valid, @c false otherwise.
    223  * @param   pThis               The socket structure.
    224  */
    225 DECLINLINE(bool) rtSocketAddRef(RTSOCKETINT *pThis)
    226 {
    227     if (ASMAtomicReadS32(&pThis->cRefs) < 0)
    228         return false;
    229 
    230     ASMAtomicAddS32(&pThis->cRefs, 1);
    231     return true;
    232 }
    233 
    234 /**
    235  * Decrease reference counter of socket.
    236  *
    237  * @returns @c true if object valid, @c false otherwise.
    238  * @param   pThis               The socket structure.
    239  */
    240 DECLINLINE(bool) rtSocketRelease(RTSOCKETINT *pThis)
    241 {
    242     if (ASMAtomicReadS32(&pThis->cRefs) <= 0)
    243         return false;
    244 
    245     ASMAtomicSubS32(&pThis->cRefs, 1);
    246     return true;
    247 }
    248 
    249 /**
    250  * Declare socket dead.
    251  *
    252  * @param   pThis               The socket structure.
    253  */
    254 DECLINLINE(void) rtSocketNoMore(RTSOCKETINT *pThis)
    255 {
    256     ASMAtomicWriteS32(&pThis->cRefs, -1);
    257 }
    258 
    259 
    260 /**
    261214 * Tries to lock the socket for exclusive usage by the calling thread.
    262215 *
     
    268221DECLINLINE(bool) rtSocketTryLock(RTSOCKETINT *pThis)
    269222{
    270     bool rv = ASMAtomicCmpXchgU32(&pThis->cUsers, 1, 0);
    271     if (rv)
    272     {
    273         rv = rtSocketAddRef(pThis);
    274         AssertReturn(rv, false);
    275     }
    276 
    277     return rv;
     223    return ASMAtomicCmpXchgU32(&pThis->cUsers, 1, 0);
    278224}
    279225
     
    286232DECLINLINE(void) rtSocketUnlock(RTSOCKETINT *pThis)
    287233{
    288     bool rv = ASMAtomicCmpXchgU32(&pThis->cUsers, 0, 1);
    289     Assert(rv);
    290 
    291     if (rv)
    292     {
    293         rv = rtSocketRelease(pThis);
    294         Assert(rv);
    295     }
    296 }
     234    ASMAtomicCmpXchgU32(&pThis->cUsers, 0, 1);
     235}
     236
    297237
    298238/**
     
    397337        pThis->hNative = NIL_RTSOCKETNATIVE;
    398338    }
    399 
    400     rtSocketNoMore(pThis);
    401339
    402340    return rc;
     
    574512    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    575513    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    576     AssertReturn(rtSocketAddRef(pThis), VERR_INVALID_HANDLE);
     514    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    577515
    578516    /*
     
    602540        rc = rtSocketError();
    603541
    604     rtSocketRelease(pThis);
     542    rtSocketUnlock(pThis);
    605543    return rc;
    606544}
     
    617555    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    618556    AssertReturn(fRead || fWrite, VERR_INVALID_PARAMETER);
    619     AssertReturn(rtSocketAddRef(pThis), VERR_INVALID_HANDLE);
    620557
    621558    /*
     
    633570        rc = rtSocketError();
    634571
    635     rtSocketRelease(pThis);
    636572    return rc;
    637573}
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