Index: /trunk/src/VBox/Main/src-server/HostImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/HostImpl.cpp	(revision 55250)
+++ /trunk/src/VBox/Main/src-server/HostImpl.cpp	(revision 55251)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2004-2014 Oracle Corporation
+ * Copyright (C) 2004-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -614,10 +614,13 @@
 {
 #if defined(RT_OS_WINDOWS) || defined(VBOX_WITH_NETFLT) /*|| defined(RT_OS_OS2)*/
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
 # ifdef VBOX_WITH_HOSTNETIF_API
-    int rc = i_updateNetIfList();
-    if (rc)
-        Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
+    HRESULT rc = i_updateNetIfList();
+    if (FAILED(rc))
+    {
+        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
+        return rc;
+    }
+
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     aNetworkInterfaces.resize(m->llNetIfs.size());
@@ -1486,15 +1489,14 @@
         return E_INVALIDARG;
 
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
-    aNetworkInterface = NULL;
+    HRESULT rc = i_updateNetIfList();
+    if (FAILED(rc))
+    {
+        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
+        return rc;
+    }
+
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     ComObjPtr<HostNetworkInterface> found;
-    int rc = i_updateNetIfList();
-    if (RT_FAILURE(rc))
-    {
-        Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
-        return E_FAIL;
-    }
     for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
     {
@@ -1522,17 +1524,15 @@
         return E_INVALIDARG;
 
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
-    aNetworkInterface = NULL;
+    HRESULT rc = i_updateNetIfList();
+    if (FAILED(rc))
+    {
+        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
+        return rc;
+    }
+
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     ComObjPtr<HostNetworkInterface> found;
-    int rc = i_updateNetIfList();
-    if (RT_FAILURE(rc))
-    {
-        Log(("Failed to get host network interface list with rc=%Rrc\n", rc));
-        return E_FAIL;
-    }
-    HostNetworkInterfaceList::iterator it;
-    for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
+    for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
     {
         Bstr g;
@@ -1554,11 +1554,14 @@
 {
 #ifdef VBOX_WITH_HOSTNETIF_API
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-    int rc = i_updateNetIfList();
-    if (RT_FAILURE(rc))
-        return E_FAIL;
+    HRESULT rc = i_updateNetIfList();
+    if (FAILED(rc))
+    {
+        Log(("Failed to update host network interface list with rc=%Rhrc\n", rc));
+        return rc;
+    }
+
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     HostNetworkInterfaceList resultList;
-
     for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
     {
@@ -2951,8 +2954,12 @@
 {
 #ifdef VBOX_WITH_HOSTNETIF_API
-    AssertReturn(   getObjectState().getState() == ObjectState::InInit
-                 || isWriteLockOnCurrentThread(), E_FAIL);
-
-    HostNetworkInterfaceList list, listCopy;
+    AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL);
+
+    /** @todo r=klaus it would save lots of clock cycles if for concurrent
+     * threads executing this code we'd only do one interface enumeration
+     * and update, and let the other threads use the result as is. However
+     * if there's a constant hammering of this method, we don't want this
+     * to cause update starvation. */
+    HostNetworkInterfaceList list;
     int rc = NetIfList(list);
     if (rc)
@@ -2961,7 +2968,10 @@
         return E_FAIL;
     }
+
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
     AssertReturn(m->pParent, E_FAIL);
     /* Make a copy as the original may be partially destroyed later. */
-    listCopy = list;
+    HostNetworkInterfaceList listCopy(list);
     HostNetworkInterfaceList::iterator itOld, itNew;
 # ifdef VBOX_WITH_RESOURCE_USAGE_API
@@ -3001,6 +3011,6 @@
     {
         HostNetworkInterfaceType_T t;
-        HRESULT hr = (*itNew)->COMGETTER(InterfaceType)(&t);
-        if (FAILED(hr))
+        HRESULT hrc = (*itNew)->COMGETTER(InterfaceType)(&t);
+        if (FAILED(hrc))
         {
             Bstr n;
