]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
don't hold loadable_modules.mutex while a module shutdown function is run, so that...
authorMathieu Rene <mrene@avgs.ca>
Mon, 24 Jan 2011 22:54:43 +0000 (17:54 -0500)
committerMathieu Rene <mrene@avgs.ca>
Mon, 24 Jan 2011 22:55:18 +0000 (17:55 -0500)
src/switch_loadable_module.c

index 03858aca2967e9bb10ef2727fee5d514519bf1dc..d6796c81199b37c807fdc186da2c842ccd9efbc6 100644 (file)
@@ -1047,20 +1047,24 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir,
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Module is not unloadable.\n");
                        *err = "Module is not unloadable";
                        status = SWITCH_STATUS_NOUNLOAD;
-                       goto end;
+                       goto unlock;
                } else {
-                       if ((status = do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE, !force, err) != SWITCH_STATUS_SUCCESS)) {
-                               goto end;
+                       /* Prevent anything from using the module while it's shutting down */
+                       switch_core_hash_delete(loadable_modules.module_hash, fname);
+                       switch_mutex_unlock(loadable_modules.mutex);
+                       if ((status = do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE, !force, err)) != SWITCH_STATUS_SUCCESS) {
+                               /* Something went wrong in the module's shutdown function, add it again */
+                               switch_core_hash_insert_locked(loadable_modules.module_hash, fname, module, loadable_modules.mutex);
                        }
+                       goto end;
                }
-               switch_core_hash_delete(loadable_modules.module_hash, fname);
        } else {
                *err = "No such module!";
                status = SWITCH_STATUS_FALSE;
        }
-  end:
+unlock:
        switch_mutex_unlock(loadable_modules.mutex);
-
+  end:
        if (force) {
                switch_yield(1000000);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "PHEW!\n");