[chan_lcr] Unloading chan_lcr is now possible
authorAndreas Eversberg <jolly@eversberg.eu>
Thu, 24 Feb 2011 07:59:17 +0000 (08:59 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Thu, 24 Feb 2011 07:59:17 +0000 (08:59 +0100)
Hi,

I tried to tackle the issue that 'core stop|restart when convenient' won't
work because unloading chan_lcr does not work.

The issue is that the thread blocks in select().

I tried to move the clean-up work from after the main select loop to the
module unloading code, make that loop a real infinite loop and replaced
pthread_join() by pthred_cancel().

The result seems to work.
Proposed patch attached.

Unloading chan_lcr while it has open channels is fatal, with or without
that patch.

   Greetings,
     WIMPy

chan_lcr.c

index 13aa680..3904c9a 100644 (file)
@@ -208,8 +208,6 @@ int wake_global = 0;
 int wake_pipe[2];
 struct lcr_fd wake_fd;
 
 int wake_pipe[2];
 struct lcr_fd wake_fd;
 
-int quit;
-
 int glob_channel = 0;
 
 int lcr_sock = -1;
 int glob_channel = 0;
 
 int lcr_sock = -1;
@@ -1935,23 +1933,11 @@ static void *chan_thread(void *arg)
 
        ast_mutex_lock(&chan_lock);
 
 
        ast_mutex_lock(&chan_lock);
 
-       while(!quit) {
+       while(1) {
                handle_queue();
                select_main(0, &global_change, lock_chan, unlock_chan);
        }
 
                handle_queue();
                select_main(0, &global_change, lock_chan, unlock_chan);
        }
 
-       close_socket();
-
-       del_timer(&socket_retry);
-
-       unregister_fd(&wake_fd);
-       close(wake_pipe[0]);
-       close(wake_pipe[1]);
-
-       CERROR(NULL, NULL, "Thread exit.\n");
-
-       ast_mutex_unlock(&chan_lock);
-
        return NULL;
 }
 
        return NULL;
 }
 
@@ -3303,7 +3289,6 @@ int load_module(void)
        ast_cli_register(&cli_port_unload);
 #endif
 
        ast_cli_register(&cli_port_unload);
 #endif
 
-       quit = 0;
        if ((pthread_create(&chan_tid, NULL, chan_thread, NULL)<0)) {
                /* failed to create thread */
                bchannel_deinitialize();
        if ((pthread_create(&chan_tid, NULL, chan_thread, NULL)<0)) {
                /* failed to create thread */
                bchannel_deinitialize();
@@ -3325,16 +3310,24 @@ int load_module(void)
 int unload_module(void)
 {
        /* First, take us out of the channel loop */
 int unload_module(void)
 {
        /* First, take us out of the channel loop */
-       CDEBUG(NULL, NULL, "-- Unregistering mISDN Channel Driver --\n");
+       CDEBUG(NULL, NULL, "-- Unregistering Linux-Call-Router Channel Driver --\n");
+
+       pthread_cancel(chan_tid);
+
+       close_socket();
 
 
-       quit = 1;
-       pthread_join(chan_tid, NULL);
+       del_timer(&socket_retry);
+
+       unregister_fd(&wake_fd);
+       close(wake_pipe[0]);
+       close(wake_pipe[1]);
+
+//     ast_mutex_unlock(&chan_lock);
 
        ast_channel_unregister(&lcr_tech);
 
        ast_unregister_application("lcr_config");
 
 
        ast_channel_unregister(&lcr_tech);
 
        ast_unregister_application("lcr_config");
 
-
        if (mISDN_created) {
                bchannel_deinitialize();
                mISDN_created = 0;
        if (mISDN_created) {
                bchannel_deinitialize();
                mISDN_created = 0;