Changeset 15917 in vbox for trunk/src/VBox
- Timestamp:
- Jan 13, 2009 2:45:18 PM (16 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxNetFlt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c
r15893 r15917 611 611 * Destroy a device that has been disconnected from the switch. 612 612 * 613 * @return true iff the instance is destroyed, false otherwise 613 614 * @param pThis The instance to be destroyed. This is 614 615 * no longer valid when this function returns. 615 616 */ 616 static void vboxNetFltDestroyInstance(PVBOXNETFLTINS pThis)617 static bool vboxNetFltCheckDestroyInstance(PVBOXNETFLTINS pThis) 617 618 { 618 619 PVBOXNETFLTGLOBALS pGlobals = pThis->pGlobals; 619 620 int rc; 620 LogFlow(("vboxNetFltDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName)); 621 uint32_t cRefs = ASMAtomicUoReadU32((uint32_t volatile *)&pThis->cRefs); 622 LogFlow(("vboxNetFltCheckDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName)); 621 623 622 624 /* … … 640 642 */ 641 643 rc = RTSemFastMutexRequest(pGlobals->hFastMtx); AssertRC(rc); 642 vboxNetFltSetState(pThis, kVBoxNetFltInsState_Disconnecting); 644 if(cRefs != 0) 645 { 646 Assert(cRefs < UINT32_MAX / 2); 647 RTSemFastMutexRelease(pGlobals->hFastMtx); 648 return false; 649 } 650 vboxNetFltSetState(pThis, kVBoxNetFltInsState_Destroying); 643 651 RTSemFastMutexRelease(pGlobals->hFastMtx); 644 652 … … 658 666 pThis->hSpinlock = NIL_RTSPINLOCK; 659 667 RTMemFree(pThis); 668 return true; 660 669 } 661 670 … … 707 716 cRefs = ASMAtomicDecU32(&pThis->cRefs); 708 717 if (!cRefs) 709 vboxNetFlt DestroyInstance(pThis);718 vboxNetFltCheckDestroyInstance(pThis); 710 719 else 711 720 Assert(cRefs < UINT32_MAX / 2); … … 961 970 DECLHIDDEN(int) vboxNetFltSearchCreateInstance(PVBOXNETFLTGLOBALS pGlobals, const char *pszName, PVBOXNETFLTINS *ppInstance, void * pContext) 962 971 { 972 PINTNETTRUNKIFPORT pIfPort; 963 973 int rc; 964 974 … … 967 977 968 978 *ppInstance = vboxNetFltFindInstanceLocked(pGlobals, pszName); 969 if(!(*ppInstance)) 970 { 971 PINTNETTRUNKIFPORT pIfPort; 972 973 RTSemFastMutexRelease(pGlobals->hFastMtx); 974 975 rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext); 976 if(RT_SUCCESS(rc)) 977 *ppInstance = IFPORT_2_VBOXNETFLTINS(pIfPort); 978 else 979 *ppInstance = NULL; 980 } 979 if(*ppInstance) 980 { 981 VBOXNETFTLINSSTATE enmState = vboxNetFltGetState(*ppInstance); 982 if(enmState != kVBoxNetFltInsState_Destroying && enmState != kVBoxNetFltInsState_Destroyed) 983 { 984 vboxNetFltRetain(*ppInstance, false); 985 RTSemFastMutexRelease(pGlobals->hFastMtx); 986 return VINF_ALREADY_INITIALIZED; 987 } 988 989 /*wait for the instance to be removed from the list */ 990 991 *ppInstance = NULL; 992 993 do 994 { 995 RTSemFastMutexRelease(pGlobals->hFastMtx); 996 997 RTSemEventWait(pGlobals->hTimerEvent, 2); 998 999 rc = RTSemFastMutexRequest(pGlobals->hFastMtx); 1000 AssertRCReturn(rc, rc); 1001 } while(vboxNetFltFindInstanceLocked(pGlobals, pszName)); 1002 } 1003 1004 RTSemFastMutexRelease(pGlobals->hFastMtx); 1005 1006 rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext); 1007 if(RT_SUCCESS(rc)) 1008 *ppInstance = IFPORT_2_VBOXNETFLTINS(pIfPort); 981 1009 else 982 { 983 RTSemFastMutexRelease(pGlobals->hFastMtx); 984 rc = VINF_ALREADY_INITIALIZED; 985 } 986 987 1010 *ppInstance = NULL; 988 1011 989 1012 return rc; … … 1186 1209 RTSemFastMutexDestroy(pGlobals->hFastMtx); 1187 1210 pGlobals->hFastMtx = NIL_RTSEMFASTMUTEX; 1211 1212 #ifdef VBOXNETFLT_STATIC_CONFIG 1213 RTSemEventDestroy(pGlobals->hTimerEvent); 1214 pGlobals->hTimerEvent = NIL_RTSEMEVENT; 1215 #endif 1216 1188 1217 } 1189 1218 … … 1222 1251 if (RT_SUCCESS(rc)) 1223 1252 { 1224 pGlobals->pInstanceHead = NULL; 1225 1226 pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease; 1227 pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect; 1228 1229 strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt"); 1230 pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface; 1253 #ifdef VBOXNETFLT_STATIC_CONFIG 1254 rc = RTSemEventCreate(&pGlobals->hTimerEvent); 1255 if (RT_SUCCESS(rc)) 1256 { 1257 #endif 1258 pGlobals->pInstanceHead = NULL; 1259 1260 pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease; 1261 pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect; 1262 1263 strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt"); 1264 pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface; 1265 1266 return rc; 1267 #ifdef VBOXNETFLT_STATIC_CONFIG 1268 } 1269 RTSemFastMutexDestroy(pGlobals->hFastMtx); 1270 #endif 1231 1271 } 1232 1272 -
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
r15893 r15917 68 68 * Partly for reasons of deadlock avoidance again. */ 69 69 kVBoxNetFltInsState_Disconnecting, 70 /** Destroying the instance 71 * Partly for reasons of deadlock avoidance again. */ 72 kVBoxNetFltInsState_Destroying, 70 73 /** The instance has been disconnected from both the host and the internal network. */ 71 74 kVBoxNetFltInsState_Destroyed, … … 248 251 /** The number of current factory references. */ 249 252 int32_t volatile cFactoryRefs; 250 253 #ifdef VBOXNETFLT_STATIC_CONFIG 254 /* wait timer event */ 255 RTSEMEVENT hTimerEvent; 256 #endif 251 257 /** The SUPDRV IDC handle (opaque struct). */ 252 258 SUPDRVIDCHANDLE SupDrvIDC;
Note:
See TracChangeset
for help on using the changeset viewer.