VirtualBox

Ignore:
Timestamp:
Jun 11, 2013 3:03:22 PM (12 years ago)
Author:
vboxsync
Message:

ipcdclient.cpp: Use a shared critical section instead of the slowlish PRMonitor thingy. The origianl code mentions that a monitor is a bit overkill and PRLock would've sufficed if it only was recursive. I've tried taking this a bit further by using a shared lock so that GetTarget() and IPC_OnMessageAvailable() doesn't need to do exclusive access.

Location:
trunk/src/libs/xpcom18a4/ipc/ipcd/client
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp

    r46435 r46494  
    5959#include "pratom.h"
    6060
     61#ifdef VBOX
     62# include <iprt/critsect.h>
     63# define VBOX_WITH_IPCCLIENT_RW_CS
     64#endif
     65
    6166/* ------------------------------------------------------------------------- */
    6267
     
    147152  ~ipcClientState()
    148153  {
     154#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    149155    if (monitor)
    150156      nsAutoMonitor::DestroyMonitor(monitor);
    151   }
    152 
     157#else
     158    RTCritSectRwDelete(&critSect);
     159#endif
     160  }
     161
     162#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    153163  //
    154164  // the monitor protects the targetMap and the connected and shutdown flags.
     
    160170  //
    161171  PRMonitor    *monitor;
     172#else  /* VBOX_WITH_IPCCLIENT_RW_CS */
     173  RTCRITSECTRW  critSect;
     174#endif /* VBOX_WITH_IPCCLIENT_RW_CS */
    162175  ipcTargetMap  targetMap;
    163176  PRBool        connected;
     
    172185
    173186  ipcClientState()
     187#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    174188    : monitor(nsAutoMonitor::NewMonitor("ipcClientState"))
    175189    , connected(PR_FALSE)
     190#else
     191    : connected(PR_FALSE)
     192#endif
    176193    , shutdown(PR_FALSE)
    177194    , selfID(0)
    178   {}
     195  {
     196#ifdef VBOX_WITH_IPCCLIENT_RW_CS
     197    /* Not employing the lock validator here to keep performance up in debug builds. */
     198    RTCritSectRwInitEx(&critSect, RTCRITSECT_FLAGS_NO_LOCK_VAL, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
     199#endif
     200  }
    179201};
    180202
     
    186208    return NULL;
    187209
     210#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    188211  if (!cs->monitor || !cs->targetMap.Init())
     212#else
     213  if (!RTCritSectRwIsInitialized(&cs->critSect) || !cs->targetMap.Init())
     214#endif
    189215  {
    190216    delete cs;
     
    202228GetTarget(const nsID &aTarget, ipcTargetData **td)
    203229{
     230#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    204231  nsAutoMonitor mon(gClientState->monitor);
    205232  return gClientState->targetMap.Get(nsIDHashKey(&aTarget).GetKey(), td);
     233#else
     234  RTCritSectRwEnterShared(&gClientState->critSect);
     235  PRBool fRc = gClientState->targetMap.Get(nsIDHashKey(&aTarget).GetKey(), td);
     236  RTCritSectRwLeaveShared(&gClientState->critSect);
     237  return fRc;
     238#endif
    206239}
    207240
     
    209242PutTarget(const nsID &aTarget, ipcTargetData *td)
    210243{
     244#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    211245  nsAutoMonitor mon(gClientState->monitor);
    212246  return gClientState->targetMap.Put(nsIDHashKey(&aTarget).GetKey(), td);
     247#else
     248  RTCritSectRwEnterExcl(&gClientState->critSect);
     249  PRBool fRc = gClientState->targetMap.Put(nsIDHashKey(&aTarget).GetKey(), td);
     250  RTCritSectRwLeaveExcl(&gClientState->critSect);
     251  return fRc;
     252#endif
    213253}
    214254
     
    216256DelTarget(const nsID &aTarget)
    217257{
     258#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    218259  nsAutoMonitor mon(gClientState->monitor);
    219260  gClientState->targetMap.Remove(nsIDHashKey(&aTarget).GetKey());
     261#else
     262  RTCritSectRwEnterExcl(&gClientState->critSect);
     263  gClientState->targetMap.Remove(nsIDHashKey(&aTarget).GetKey());
     264  RTCritSectRwLeaveExcl(&gClientState->critSect);
     265#endif
    220266}
    221267
     
    805851      // all targets but IPCM will not be able to use WaitTarget any more.
    806852
     853#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    807854      nsAutoMonitor mon(gClientState->monitor);
     855#else
     856      RTCritSectRwEnterExcl(&gClientState->critSect);
     857#endif
     858
    808859      gClientState->shutdown = PR_TRUE;
    809860      gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndNotify, nsnull);
     861
     862#ifdef VBOX_WITH_IPCCLIENT_RW_CS
     863      RTCritSectRwLeaveExcl(&gClientState->critSect);
     864#endif
    810865    }
    811866
     
    12901345  // unblock any calls to WaitTarget.
    12911346
     1347#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    12921348  nsAutoMonitor mon(gClientState->monitor);
     1349#else
     1350  RTCritSectRwEnterExcl(&gClientState->critSect);
     1351#endif
     1352
    12931353  gClientState->connected = PR_FALSE;
    12941354  gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndNotify, nsnull);
     1355
     1356#ifdef VBOX_WITH_IPCCLIENT_RW_CS
     1357  RTCritSectRwLeaveExcl(&gClientState->critSect);
     1358#endif
    12951359}
    12961360
     
    13931457        // targets) giving them an opportuninty to finish wait cycle because of
    13941458        // the peer client death, when appropriate.
     1459#ifndef VBOX_WITH_IPCCLIENT_RW_CS
    13951460        nsAutoMonitor mon(gClientState->monitor);
     1461#else
     1462        RTCritSectRwEnterShared(&gClientState->critSect);
     1463#endif
     1464
    13961465        gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndPlaceMsg, msg);
    13971466
     1467#ifdef VBOX_WITH_IPCCLIENT_RW_CS
     1468        RTCritSectRwLeaveShared(&gClientState->critSect);
     1469#endif
    13981470        delete msg;
    13991471
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