ofed libs: prevent double initialization of critical section
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 26 Aug 2009 16:44:24 +0000 (16:44 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 26 Aug 2009 16:44:24 +0000 (16:44 +0000)
DllMain is called multiple times for a given process.  Prevent double
initialization of critical sections by only initializing it during process
attach.  This avoids corrupting the critical section while it may be in use.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2382 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/libibverbs/src/ibv_main.cpp
ulp/librdmacm/src/cma_main.cpp

index 04f4de5..4b01115 100644 (file)
@@ -34,9 +34,18 @@ extern CRITICAL_SECTION lock;
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
 {\r
        UNREFERENCED_PARAMETER(hInstance);\r
-       UNREFERENCED_PARAMETER(dwReason);\r
        UNREFERENCED_PARAMETER(lpReserved);\r
 \r
-       InitializeCriticalSection(&lock);\r
+       switch (dwReason) {\r
+       case DLL_PROCESS_ATTACH:\r
+               InitializeCriticalSection(&lock);\r
+               break;\r
+       case DLL_PROCESS_DETACH:\r
+               DeleteCriticalSection(&lock);\r
+               break;\r
+       default:\r
+               break;\r
+       }\r
+\r
        return TRUE;\r
 }\r
index 44519eb..3521018 100644 (file)
@@ -35,10 +35,18 @@ CRITICAL_SECTION lock;
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
 {\r
        UNREFERENCED_PARAMETER(hInstance);\r
-       UNREFERENCED_PARAMETER(dwReason);\r
        UNREFERENCED_PARAMETER(lpReserved);\r
 \r
-       InitializeCriticalSection(&lock);\r
+       switch (dwReason) {\r
+       case DLL_PROCESS_ATTACH:\r
+               InitializeCriticalSection(&lock);\r
+               break;\r
+       case DLL_PROCESS_DETACH:\r
+               DeleteCriticalSection(&lock);\r
+               break;\r
+       default:\r
+               break;\r
+       }\r
 \r
        return TRUE;\r
 }\r