VirtualBox

Changeset 55251 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Apr 14, 2015 2:43:40 PM (10 years ago)
Author:
vboxsync
Message:

Main/Host: reduce the amount of unnecessary locking greatly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r55223 r55251  
    55
    66/*
    7  * Copyright (C) 2004-2014 Oracle Corporation
     7 * Copyright (C) 2004-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    614614{
    615615#if defined(RT_OS_WINDOWS) || defined(VBOX_WITH_NETFLT) /*|| defined(RT_OS_OS2)*/
    616     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    617 
    618616# ifdef VBOX_WITH_HOSTNETIF_API
    619     int rc = i_updateNetIfList();
    620     if (rc)
    621         Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
     617    HRESULT rc = i_updateNetIfList();
     618    if (FAILED(rc))
     619    {
     620        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
     621        return rc;
     622    }
     623
     624    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    622625
    623626    aNetworkInterfaces.resize(m->llNetIfs.size());
     
    14861489        return E_INVALIDARG;
    14871490
    1488     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1489 
    1490     aNetworkInterface = NULL;
     1491    HRESULT rc = i_updateNetIfList();
     1492    if (FAILED(rc))
     1493    {
     1494        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
     1495        return rc;
     1496    }
     1497
     1498    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    14911499
    14921500    ComObjPtr<HostNetworkInterface> found;
    1493     int rc = i_updateNetIfList();
    1494     if (RT_FAILURE(rc))
    1495     {
    1496         Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
    1497         return E_FAIL;
    1498     }
    14991501    for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
    15001502    {
     
    15221524        return E_INVALIDARG;
    15231525
    1524     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1525 
    1526     aNetworkInterface = NULL;
     1526    HRESULT rc = i_updateNetIfList();
     1527    if (FAILED(rc))
     1528    {
     1529        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
     1530        return rc;
     1531    }
     1532
     1533    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    15271534
    15281535    ComObjPtr<HostNetworkInterface> found;
    1529     int rc = i_updateNetIfList();
    1530     if (RT_FAILURE(rc))
    1531     {
    1532         Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
    1533         return E_FAIL;
    1534     }
    1535     HostNetworkInterfaceList::iterator it;
    1536     for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
     1536    for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
    15371537    {
    15381538        Bstr g;
     
    15541554{
    15551555#ifdef VBOX_WITH_HOSTNETIF_API
    1556     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1557     int rc = i_updateNetIfList();
    1558     if (RT_FAILURE(rc))
    1559         return E_FAIL;
     1556    HRESULT rc = i_updateNetIfList();
     1557    if (FAILED(rc))
     1558    {
     1559        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
     1560        return rc;
     1561    }
     1562
     1563    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    15601564
    15611565    HostNetworkInterfaceList resultList;
    1562 
    15631566    for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
    15641567    {
     
    29512954{
    29522955#ifdef VBOX_WITH_HOSTNETIF_API
    2953     AssertReturn(   getObjectState().getState() == ObjectState::InInit
    2954                  || isWriteLockOnCurrentThread(), E_FAIL);
    2955 
    2956     HostNetworkInterfaceList list, listCopy;
     2956    AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL);
     2957
     2958    /** @todo r=klaus it would save lots of clock cycles if for concurrent
     2959     * threads executing this code we'd only do one interface enumeration
     2960     * and update, and let the other threads use the result as is. However
     2961     * if there's a constant hammering of this method, we don't want this
     2962     * to cause update starvation. */
     2963    HostNetworkInterfaceList list;
    29572964    int rc = NetIfList(list);
    29582965    if (rc)
     
    29612968        return E_FAIL;
    29622969    }
     2970
     2971    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     2972
    29632973    AssertReturn(m->pParent, E_FAIL);
    29642974    /* Make a copy as the original may be partially destroyed later. */
    2965     listCopy = list;
     2975    HostNetworkInterfaceList listCopy(list);
    29662976    HostNetworkInterfaceList::iterator itOld, itNew;
    29672977# ifdef VBOX_WITH_RESOURCE_USAGE_API
     
    30013011    {
    30023012        HostNetworkInterfaceType_T t;
    3003         HRESULT hr = (*itNew)->COMGETTER(InterfaceType)(&t);
    3004         if (FAILED(hr))
     3013        HRESULT hrc = (*itNew)->COMGETTER(InterfaceType)(&t);
     3014        if (FAILED(hrc))
    30053015        {
    30063016            Bstr n;
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