[ofw] [PATCH 1/4] nd2: determine when it's safe to unload the library

Hefty, Sean sean.hefty at intel.com
Tue Jul 27 16:48:39 PDT 2010


Count the number of provider instances to know when it's
safe to unload the library.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
 trunk/ulp/netdirect2/user/nd_main.cpp     |    3 ++-
 trunk/ulp/netdirect2/user/nd_provider.cpp |    5 +++++
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/trunk/ulp/netdirect2/user/nd_main.cpp b/trunk/ulp/netdirect2/user/nd_main.cpp
index 6fde5de..1b9e049 100644
--- a/trunk/ulp/netdirect2/user/nd_main.cpp
+++ b/trunk/ulp/netdirect2/user/nd_main.cpp
@@ -34,6 +34,7 @@
 #include "nd_provider.h"
 
 HANDLE g_hHeap;
+volatile LONG g_nRef;
 
 extern "C" {
 
@@ -64,7 +65,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 
 STDAPI DllCanUnloadNow(void)
 {
-	return S_OK;
+	return (g_nRef == 0) ? S_OK : S_FALSE;
 }
 
 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)
diff --git a/trunk/ulp/netdirect2/user/nd_provider.cpp b/trunk/ulp/netdirect2/user/nd_provider.cpp
index 6f94b71..cbc9c22 100644
--- a/trunk/ulp/netdirect2/user/nd_provider.cpp
+++ b/trunk/ulp/netdirect2/user/nd_provider.cpp
@@ -31,9 +31,13 @@
 #include "nd_adapter.h"
 #include <ws2tcpip.h>
 
+extern volatile LONG g_nRef;
+
+
 CNDProvider::CNDProvider()
 {
 	m_pWvProvider = NULL;
+	InterlockedIncrement(&g_nRef);
 }
 
 STDMETHODIMP CNDProvider::
@@ -60,6 +64,7 @@ CNDProvider::~CNDProvider()
 	if (m_pWvProvider) {
 		m_pWvProvider->Release();
 	}
+	InterlockedDecrement(&m_gRef);
 }
 
 STDMETHODIMP CNDProvider::




More information about the ofw mailing list