--- chan_phone-4.c 2006-01-11 14:14:46.637875000 +0200 +++ chan_phone.c 2006-01-11 14:25:29.153500000 +0200 @@ -36,6 +36,7 @@ #include #include #include +#include #include /* Still use some IXJ specific stuff */ #include @@ -106,6 +107,9 @@ /* Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. */ AST_MUTEX_DEFINE_STATIC(monlock); + +/* Boolean value whether the monitoring thread shall continue. */ +static unsigned int monitor; /* This is the thread for the monitor which checks for input on the channels which are not currently in use. */ @@ -968,22 +972,12 @@ int dotone; /* This thread monitors all the frame relay interfaces which are not yet in use (and thus do not have a separate thread) indefinitely */ - /* From here on out, we die whenever asked */ - if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)) { - ast_log(LOG_WARNING, "Unable to set cancel type to asynchronous\n"); - return NULL; - } - for(;;) { + while(monitor) { /* Don't let anybody kill us right away. Nobody should lock the interface list and wait for the monitor list, but the other way around is okay. */ - if (ast_mutex_lock(&monlock)) { - ast_log(LOG_ERROR, "Unable to grab monitor lock\n"); - return NULL; - } /* Lock the interface list */ if (ast_mutex_lock(&iflock)) { ast_log(LOG_ERROR, "Unable to grab interface lock\n"); - ast_mutex_unlock(&monlock); return NULL; } /* Build the stuff we're going to select on, that is the socket of every @@ -1019,9 +1013,6 @@ /* Okay, now that we know what to do, release the interface lock */ ast_mutex_unlock(&iflock); - /* And from now on, we're okay to be killed, so release the monitor lock as well */ - ast_mutex_unlock(&monlock); - /* Wait indefinitely for something to happen */ if (dotone) { /* If we're ready to recycle the time, set it to 30 ms */ @@ -1070,7 +1061,6 @@ } ast_mutex_unlock(&iflock); } - /* Never reached */ return NULL; } @@ -1095,13 +1085,14 @@ ast_log(LOG_WARNING, "Unable to lock the interface list\n"); return -1; } - pthread_cancel(monitor_thread); -#if 0 + monitor = 0; + while (pthread_kill(monitor_thread, SIGURG) == 0) + sched_yield(); pthread_join(monitor_thread, NULL); -#endif ast_mutex_unlock(&iflock); } - /* Start a new monitor */ + monitor = 1; + /* Start a new monitor */ if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { ast_mutex_unlock(&monlock); ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); @@ -1256,7 +1247,9 @@ } if (!ast_mutex_lock(&monlock)) { if (monitor_thread > AST_PTHREADT_NULL) { - pthread_cancel(monitor_thread); + monitor = 0; + while (pthread_kill(monitor_thread, SIGURG) == 0) + sched_yield(); pthread_join(monitor_thread, NULL); } monitor_thread = AST_PTHREADT_STOP;