The "trylock" test patch.
[lcr.git] / chan_lcr.c
index 701d8a2..5968733 100644 (file)
@@ -254,8 +254,9 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st
        if (ast)
                strncpy(ast_text, ast->name, sizeof(ast_text)-1);
        ast_text[sizeof(ast_text)-1] = '\0';
-       
-       ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
+
+printf("\n[call=%s ast=%s] %s\n", call_text, ast_text, buffer);
+//     ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
 
        ast_mutex_unlock(&log_lock);
        lock_debug("l");
@@ -1264,6 +1265,7 @@ int receive_message(int message_type, unsigned int ref, union parameter *param)
        if (message_type == MESSAGE_BCHANNEL) {
                switch(param->bchannel.type) {
                        case BCHANNEL_ASSIGN:
+lock_debug("rx1");
                        CDEBUG(NULL, NULL, "Received BCHANNEL_ASSIGN message. (handle=%08lx) for ref %d\n", param->bchannel.handle, ref);
                        if ((bchannel = find_bchannel_handle(param->bchannel.handle))) {
                                CERROR(NULL, NULL, "bchannel handle %x already assigned.\n", (int)param->bchannel.handle);
@@ -1528,16 +1530,23 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
        struct admin_list *admin;
        struct admin_message msg;
 
+       lock_debug("handle+");
        if ((what & LCR_FD_READ)) {
                /* read from socket */
+               lock_debug("handle1");
                len = read(lcr_sock, &msg, sizeof(msg));
+               lock_debug("handle2");
                if (len == 0) {
                        CERROR(NULL, NULL, "Socket closed.\n");
                        error:
                        CERROR(NULL, NULL, "Handling of socket failed - closing for some seconds.\n");
+                       lock_debug("handle3");
                        close_socket();
+                       lock_debug("handle4");
                        release_all_calls();
+                       lock_debug("handle5");
                        schedule_timer(&socket_retry, SOCKET_RETRY_TIMER, 0);
+                       lock_debug("handle-");
                        return 0;
                }
                if (len > 0) {
@@ -1549,7 +1558,9 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                                CERROR(NULL, NULL, "Socket received illegal message %d.\n", msg.message);
                                goto error;
                        }
+                       lock_debug("handleX");
                        receive_message(msg.u.msg.type, msg.u.msg.ref, &msg.u.msg.param);
+                       lock_debug("handleY");
                } else {
                        CERROR(NULL, NULL, "Socket failed (errno %d).\n", errno);
                        goto error;
@@ -1560,10 +1571,13 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                /* write to socket */
                if (!admin_first) {
                        socket_fd.when &= ~LCR_FD_WRITE;
+                       lock_debug("handle-");
                        return 0;
                }
+               lock_debug("handle6");
                admin = admin_first;
                len = write(lcr_sock, &admin->msg, sizeof(msg));
+               lock_debug("handle7");
                if (len == 0) {
                        CERROR(NULL, NULL, "Socket closed.\n");
                        goto error;
@@ -1574,6 +1588,7 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                                goto error;
                        }
                        /* free head */
+                       lock_debug("handle8");
                        admin_first = admin->next;
                        free(admin);
                        global_change = 1;
@@ -1583,6 +1598,7 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                }
        }
 
+       lock_debug("handle-");
        return 0;
 }
 
@@ -1655,9 +1671,11 @@ static int wake_event(struct lcr_fd *fd, unsigned int what, void *instance, int
 {
        char byte;
 
+       lock_debug("wake+");
        read(wake_pipe[0], &byte, 1);
 
        wake_global = 0;
+       lock_debug("wake-");
 
        return 0;
 }
@@ -1675,7 +1693,11 @@ static void handle_queue()
                ast = call->ast;
                if (*p && ast) {
                        lock_debug("A1+");
-                       ast_channel_lock(ast);
+                       while (ast_channel_trylock(ast)) {
+                               lock_debug("<trylock failed>");
+                               usleep(1000);
+                               lock_debug("A1++");
+                       }
                        lock_debug("A1-");
                        while(*p) {
                                switch (*p) {
@@ -1998,8 +2020,8 @@ static void send_digit_to_chan(struct ast_channel * ast, char digit )
                 ast_playtones_start(ast,0,dtmf_tones[15], 0);
         else {
                 /* not handled */
-                ast_log(LOG_DEBUG, "Unable to handle DTMF tone "
-                       "'%c' for '%s'\n", digit, ast->name);
+//                ast_log(LOG_DEBUG, "Unable to handle DTMF tone "
+//                     "'%c' for '%s'\n", digit, ast->name);
         }
 }