X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=chan_lcr.c;h=38f969bfbfc9abd90436a877b14f3d3a1259c7e3;hp=d4510d602304c1ff89e0ada53cf7f2fe5c8c5eab;hb=443a7c9eb2993ae43e457045baa3d68bf7501272;hpb=5c120fb5084aad712982f703244a35a9a7a3d8c4 diff --git a/chan_lcr.c b/chan_lcr.c index d4510d6..38f969b 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -227,7 +227,7 @@ void lock_debug(char *text) { pthread_t tid = pthread_self(); // printf("%s|%03x\n", text, ((tid>>6) | (tid>>3) | tid) & 0xfff); fflush(stdout); - printf("%s|%x\n", text, tid); fflush(stdout); + printf(" %s(%x) ", text, (int)tid); fflush(stdout); } /* @@ -240,8 +240,9 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st char ast_text[128] = "NULL"; va_list args; - lock_debug("L"); + lock_debug("L+"); ast_mutex_lock(&log_lock); + lock_debug("L-"); va_start(args,fmt); vsnprintf(buffer,sizeof(buffer)-1,fmt,args); @@ -1263,6 +1264,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); @@ -1527,16 +1529,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) { @@ -1548,7 +1557,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; @@ -1559,10 +1570,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; @@ -1573,6 +1587,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; @@ -1582,6 +1597,7 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i } } + lock_debug("handle-"); return 0; } @@ -1654,9 +1670,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; } @@ -1673,8 +1691,9 @@ static void handle_queue() p = call->queue_string; ast = call->ast; if (*p && ast) { - lock_debug("A1"); - ast_channel_lock(ast); + lock_debug("A1+"); +// ast_channel_lock(ast); + lock_debug("A1-"); while(*p) { switch (*p) { case 'T': @@ -1730,7 +1749,7 @@ static void handle_queue() p++; } call->queue_string[0] = '\0'; - ast_channel_unlock(ast); +// ast_channel_unlock(ast); lock_debug("a1"); } call = call->next; @@ -1748,8 +1767,9 @@ static int handle_retry(struct lcr_timer *timer, void *instance, int index) void lock_chan(void) { - lock_debug("C"); + lock_debug("C+"); ast_mutex_lock(&chan_lock); + lock_debug("C-"); } void unlock_chan(void) @@ -1777,8 +1797,9 @@ static void *chan_thread(void *arg) /* open socket the first time */ handle_retry(NULL, NULL, 0); - lock_debug("A2"); + lock_debug("A2+"); ast_mutex_lock(&chan_lock); + lock_debug("A2-"); while(!quit) { handle_queue(); @@ -1811,8 +1832,9 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c struct ast_channel *ast; struct chan_call *call; - lock_debug("A3"); + lock_debug("A3+"); ast_mutex_lock(&chan_lock); + lock_debug("A3-"); CDEBUG(NULL, NULL, "Received request from Asterisk. (data=%s)\n", (char *)data); /* if socket is closed */ @@ -1905,8 +1927,9 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout) union parameter newparam; struct chan_call *call; - lock_debug("A4"); + lock_debug("A4+"); ast_mutex_lock(&chan_lock); + lock_debug("A4-"); call = ast->tech_pvt; #ifdef LCR_FOR_CALLWEAVER @@ -2016,8 +2039,9 @@ static int lcr_digit(struct ast_channel *ast, char digit) if (digit > 126 || digit < 32) return 0; - lock_debug("A5"); + lock_debug("A5+"); ast_mutex_lock(&chan_lock); + lock_debug("A5-"); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received digit from Asterisk, but no call instance exists.\n"); @@ -2061,8 +2085,9 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat struct chan_call *call; #endif - lock_debug("A6"); + lock_debug("A6+"); ast_mutex_lock(&chan_lock); + lock_debug("A6-"); call = ast->tech_pvt; @@ -2097,8 +2122,9 @@ static int lcr_answer(struct ast_channel *ast) union parameter newparam; struct chan_call *call; - lock_debug("A7"); + lock_debug("A7+"); ast_mutex_lock(&chan_lock); + lock_debug("A7-"); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received answer from Asterisk, but no call instance exists.\n"); @@ -2142,8 +2168,9 @@ static int lcr_hangup(struct ast_channel *ast) pthread_t tid = pthread_self(); if (!pthread_equal(tid, chan_tid)) { - lock_debug("H"); + lock_debug("H+"); ast_mutex_lock(&chan_lock); + lock_debug("H-"); } call = ast->tech_pvt; if (!call) { @@ -2206,8 +2233,9 @@ static int lcr_write(struct ast_channel *ast, struct ast_frame *f) if (!(f->subclass & ast->nativeformats)) CDEBUG(NULL, ast, "Unexpected format.\n"); - lock_debug("A8"); + lock_debug("A8+"); ast_mutex_lock(&chan_lock); + lock_debug("A8-"); call = ast->tech_pvt; if (!call) { ast_mutex_unlock(&chan_lock); @@ -2227,8 +2255,9 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) struct chan_call *call; int len; - lock_debug("A9"); + lock_debug("A9+"); ast_mutex_lock(&chan_lock); + lock_debug("A9-"); call = ast->tech_pvt; if (!call) { ast_mutex_unlock(&chan_lock); @@ -2238,13 +2267,16 @@ static struct ast_frame *lcr_read(struct ast_channel *ast) if (call->pipe[0] > -1) { if (call->rebuffer && !call->hdlc) { /* Make sure we have a complete 20ms (160byte) frame */ + lock_debug("*1"); len=read(call->pipe[0],call->read_buff + call->framepos, 160 - call->framepos); if (len > 0) { call->framepos += len; } } else { + lock_debug("*2"); len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff)); } + lock_debug("*3"); if (len < 0 && errno == EAGAIN) { ast_mutex_unlock(&chan_lock); lock_debug("a9"); @@ -2298,8 +2330,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz struct chan_call *call; const struct tone_zone_sound *ts = NULL; - lock_debug("A0"); + lock_debug("A0+"); ast_mutex_lock(&chan_lock); + lock_debug("A0-"); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received indicate from Asterisk, but no call instance exists.\n"); @@ -2450,8 +2483,9 @@ static int lcr_fixup(struct ast_channel *oldast, struct ast_channel *ast) return -1; } - lock_debug("Af"); + lock_debug("Af+"); ast_mutex_lock(&chan_lock); + lock_debug("Af-"); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n"); @@ -2475,8 +2509,9 @@ static int lcr_send_text(struct ast_channel *ast, const char *text) struct chan_call *call; union parameter newparam; - lock_debug("At"); + lock_debug("At+"); ast_mutex_lock(&chan_lock); + lock_debug("At-"); call = ast->tech_pvt; if (!call) { CERROR(NULL, ast, "Received send_text from Asterisk, but no call instance exists.\n"); @@ -2515,8 +2550,9 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, carr[1] = ast2; /* join via dsp (if the channels are currently open) */ - lock_debug("Ab"); + lock_debug("Ab+"); ast_mutex_lock(&chan_lock); + lock_debug("Ab-"); call1 = ast1->tech_pvt; call2 = ast2->tech_pvt; if (!call1 || !call2) { @@ -2633,8 +2669,9 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1, CDEBUG(NULL, NULL, "Releasing bridge.\n"); /* split channels */ - lock_debug("Ab"); + lock_debug("Ab+"); ast_mutex_lock(&chan_lock); + lock_debug("Ab-"); call1 = ast1->tech_pvt; call2 = ast2->tech_pvt; if (call1 && call1->bridge_id) { @@ -2786,8 +2823,9 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv) { struct chan_call *call; - lock_debug("Ae"); + lock_debug("Ae+"); ast_mutex_lock(&chan_lock); + lock_debug("Ae-"); #ifdef LCR_FOR_ASTERISK CDEBUG(NULL, ast, "Received lcr_config (data=%s)\n", (char *)data); @@ -2989,8 +3027,9 @@ int usecount(void) hae { int res; - lock_debug("U"); + lock_debug("U+"); ast_mutex_lock(&usecnt_lock); + lock_debug("U-"); res = usecnt; ast_mutex_unlock(&usecnt_lock); lock_debug("u");