[ibal] Replace mutex unsafe function with events.
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 28 Oct 2008 09:34:52 +0000 (09:34 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 28 Oct 2008 09:34:52 +0000 (09:34 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1701 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/bus/kernel/bus_driver.c
core/bus/kernel/bus_driver.h
core/bus/kernel/bus_iou_mgr.c
core/bus/kernel/bus_pnp.c
core/bus/kernel/bus_port_mgr.c

index ddfd116..7c6215d 100644 (file)
@@ -799,7 +799,7 @@ DriverEntry(
        // Mutex to synchronize multiple threads creating & deleting \r
        // control deviceobjects. \r
 \r
-       ExInitializeFastMutex(&g_ControlMutex);\r
+       KeInitializeEvent(&g_ControlEvent, SynchronizationEvent, TRUE);\r
        g_bfi_InstanceCount = 0;\r
        memset(  __out_bcount(sizeof(g_bus_filters)) (void*)g_bus_filters, 0,\r
                        sizeof(g_bus_filters) );\r
index 12ed47c..c362535 100644 (file)
@@ -255,7 +255,7 @@ typedef struct _bus_filter_instance
 \r
 extern bus_filter_t    g_bus_filters[MAX_BUS_FILTERS];\r
 extern ULONG g_bfi_InstanceCount;\r
-extern FAST_MUTEX g_ControlMutex;      // serializes InstanceCount & g_bus_filters\r
+extern KEVENT g_ControlEvent;  // serializes InstanceCount & g_bus_filters\r
 \r
 extern bus_filter_t *alloc_bfi( IN DRIVER_OBJECT *, OUT int * );\r
 extern int free_bfi( IN bus_filter_t *p_bfi );\r
@@ -265,4 +265,12 @@ extern bus_filter_t *get_bfi_by_ca_guid( IN net64_t ca_guid );
 extern bus_filter_t *get_set_bfi_by_ca_guid( IN net64_t ca_guid );\r
 extern char *get_obj_state_str(cl_state_t state);\r
 \r
+inline VOID lock_control_event() {\r
+       KeWaitForSingleObject(&g_ControlEvent, Executive, KernelMode , FALSE, NULL);\r
+}\r
+\r
+inline VOID unlock_control_event() {\r
+       KeSetEvent(&g_ControlEvent, 0, FALSE);\r
+}\r
+\r
 #endif /* !defined _BUS_DRIVER_H_ */\r
index e9ff3ff..fcc3175 100644 (file)
@@ -483,13 +483,13 @@ bus_reg_iou_pnp( IN bus_filter_t *p_bfi )
         */\r
        if ( !bus_globals.h_pnp_iou )\r
        {\r
-               ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+               lock_control_event();\r
                if ( !bus_globals.h_pnp_iou )\r
                {\r
                        bus_globals.h_pnp_iou = (ib_pnp_handle_t)1; /* block others */ \r
                        need_pnp_reg = TRUE;\r
                }\r
-               ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+               unlock_control_event();\r
 \r
                if ( need_pnp_reg )\r
                {\r
index 7eb4481..661d5d3 100644 (file)
@@ -51,7 +51,7 @@
 static UNICODE_STRING  al_ifc_name;\r
 static UNICODE_STRING  ci_ifc_name;\r
 \r
-FAST_MUTEX                             g_ControlMutex;\r
+KEVENT                                 g_ControlEvent;\r
 ULONG                                  g_bfi_InstanceCount;\r
 bus_filter_t                   g_bus_filters[MAX_BUS_FILTERS];\r
 \r
@@ -334,7 +334,7 @@ fdo_start(
                return status;\r
        }\r
 \r
-       ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
        if ( !gh_al ) {\r
                /* Initialize AL */\r
                ib_status = al_initialize();\r
@@ -343,12 +343,12 @@ fdo_start(
                        al_cleanup();\r
                        BUS_TRACE_EXIT( BUS_DBG_ERROR, ("al_initialize returned %s.\n",\r
                                                        ib_get_err_str(ib_status)) );\r
-                       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+                       unlock_control_event();\r
                        return STATUS_UNSUCCESSFUL;\r
                }\r
                AL_init_here = TRUE;\r
        }\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+       unlock_control_event();\r
 \r
        /* Initialize the port manager. */\r
        ib_status = create_port_mgr( p_ext->bus_filter, &p_ext->p_port_mgr );\r
@@ -1252,7 +1252,7 @@ get_bfi_by_obj(IN int obj_type, IN cl_obj_t *p_obj )
 \r
        CL_ASSERT((obj_type == BFI_PORT_MGR_OBJ) || (obj_type == BFI_IOU_MGR_OBJ));\r
 \r
-    ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
 \r
        for(p_bfi=g_bus_filters; p_bfi < &g_bus_filters[MAX_BUS_FILTERS]; p_bfi++) {\r
 \r
@@ -1272,7 +1272,7 @@ get_bfi_by_obj(IN int obj_type, IN cl_obj_t *p_obj )
                        }\r
                }\r
        }\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+       unlock_control_event();\r
 \r
        BUS_PRINT( BUS_DBG_PNP,\r
                                ("%s() cl_obj %p type %s_MGR_OBJ --> bfi[%d] %p\n",\r
@@ -1302,7 +1302,7 @@ get_bfi_by_ca_guid( IN net64_t ca_guid )
                return matched;\r
        }\r
 \r
-       ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
 \r
        for(p_bfi=g_bus_filters; p_bfi < &g_bus_filters[MAX_BUS_FILTERS]; p_bfi++)\r
        {\r
@@ -1315,7 +1315,7 @@ get_bfi_by_ca_guid( IN net64_t ca_guid )
                        break;\r
                }\r
        }\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+       unlock_control_event();\r
 \r
 #if DBG\r
        if ( !matched )\r
@@ -1376,7 +1376,7 @@ get_set_bfi_by_ca_guid( IN net64_t ca_guid )
         */\r
        if ( !matched )\r
        {\r
-               ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+               lock_control_event();\r
 \r
                for(p_bfi=g_bus_filters; p_bfi < &g_bus_filters[MAX_BUS_FILTERS]; p_bfi++)\r
                {\r
@@ -1391,7 +1391,7 @@ get_set_bfi_by_ca_guid( IN net64_t ca_guid )
                                break;\r
                        }\r
                }\r
-               ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+               unlock_control_event();\r
        }\r
 \r
        BUS_PRINT( BUS_DBG_PNP,\r
@@ -1413,7 +1413,7 @@ alloc_bfi( IN DRIVER_OBJECT  *p_driver_obj, OUT int *p_instance_count )
      * IoCreateDeviceSecure & IoCreateSymbolicLink must be called at\r
      * PASSIVE_LEVEL.\r
         */\r
-       ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
 \r
        // find 1st unused bfi slot.\r
        for(p_bfi=g_bus_filters; p_bfi < &g_bus_filters[MAX_BUS_FILTERS]; p_bfi++)\r
@@ -1430,7 +1430,7 @@ alloc_bfi( IN DRIVER_OBJECT  *p_driver_obj, OUT int *p_instance_count )
                        break;\r
                }\r
        }\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+       unlock_control_event();\r
 \r
 #if DBG\r
        RtlStringCbPrintfA ( p_bfi->whoami,\r
@@ -1453,12 +1453,12 @@ free_bfi( IN  bus_filter_t  *p_bfi )
 {\r
        int     remaining;\r
 \r
-       ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
        p_bfi->p_bus_ext = NULL;\r
        p_bfi->ca_guid = 0ULL;\r
        remaining = --g_bfi_InstanceCount; // one less bfi in-use\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
-\r
+       unlock_control_event();\r
+       \r
        return remaining;\r
 }\r
 \r
@@ -1467,10 +1467,10 @@ get_bfi_count( void )
 {\r
        int     ic;\r
 \r
-       ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+       lock_control_event();\r
        ic = g_bfi_InstanceCount;\r
-       ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
-\r
+       unlock_control_event();\r
+       \r
        return ic;\r
 }\r
 \r
index fc0fade..e7b3212 100644 (file)
@@ -483,12 +483,12 @@ bus_reg_port_pnp( IN bus_filter_t *p_bfi )
         */\r
        if ( !bus_globals.h_pnp_port )\r
        {\r
-               ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+               lock_control_event();\r
                if ( !bus_globals.h_pnp_port ) {\r
                        bus_globals.h_pnp_port = (ib_pnp_handle_t)1; /* block others */\r
                        need_pnp_reg = TRUE;\r
                }\r
-               ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+               unlock_control_event();\r
 \r
                if ( need_pnp_reg )\r
                {\r
@@ -1005,10 +1005,10 @@ cl_status_t port_mgr_pkey_rem( IN pkey_array_t *pkeys )
                if ( !p_bfi->p_bus_ext )\r
                        continue;\r
                GO = FALSE;\r
-               ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+               lock_control_event();\r
                if ( p_bfi->ca_guid && p_bfi->p_port_mgr )\r
                        GO = TRUE;\r
-               ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+               unlock_control_event();\r
                if ( GO == FALSE )\r
                        continue;\r
                status = _port_mgr_pkey_rem( pkeys, p_bfi->p_port_mgr );\r
@@ -1149,10 +1149,10 @@ cl_status_t port_mgr_pkey_add(pkey_array_t *pkeys)
                if ( !p_bfi->p_bus_ext )\r
                        continue;\r
                GO = FALSE;\r
-               ExAcquireFastMutexUnsafe(&g_ControlMutex);\r
+               lock_control_event();\r
                if ( p_bfi->ca_guid && p_bfi->p_port_mgr )\r
                        GO = TRUE;\r
-               ExReleaseFastMutexUnsafe(&g_ControlMutex);\r
+               unlock_control_event();\r
                if ( GO == FALSE )\r
                        continue;\r
                status = _port_mgr_pkey_add( pkeys, p_bfi, p_bfi->p_port_mgr );\r