summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxav/msi.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 3497f4e7..1219c64a 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -620,18 +620,20 @@ int timer_alloc ( TimerHandler *timers_container, void *(func)(void *, int), voi
620 * 620 *
621 * @param timers_container handler 621 * @param timers_container handler
622 * @param idx index 622 * @param idx index
623 * @param idx lock_mutex (does the mutex need to be locked)
623 * @return int 624 * @return int
624 */ 625 */
625int timer_release ( TimerHandler *timers_container, int idx ) 626int timer_release ( TimerHandler *timers_container, int idx , int lock_mutex)
626{ 627{
627 int rc = pthread_mutex_trylock(&timers_container->mutex); 628 if (lock_mutex)
629 pthread_mutex_lock(&timers_container->mutex);
628 630
629 Timer **timed_events = timers_container->timers; 631 Timer **timed_events = timers_container->timers;
630 632
631 if (!timed_events[idx]) { 633 if (!timed_events[idx]) {
632 LOGGER_WARNING("No event under index: %d", idx); 634 LOGGER_WARNING("No event under index: %d", idx);
633 635
634 if ( rc != EBUSY ) pthread_mutex_unlock(&timers_container->mutex); 636 if (lock_mutex) pthread_mutex_unlock(&timers_container->mutex);
635 637
636 return -1; 638 return -1;
637 } 639 }
@@ -651,7 +653,7 @@ int timer_release ( TimerHandler *timers_container, int idx )
651 653
652 LOGGER_DEBUG("Popped index: %d, current size: %d ", idx, timers_container->size); 654 LOGGER_DEBUG("Popped index: %d, current size: %d ", idx, timers_container->size);
653 655
654 if ( rc != EBUSY ) pthread_mutex_unlock(&timers_container->mutex); 656 if (lock_mutex) pthread_mutex_unlock(&timers_container->mutex);
655 657
656 return 0; 658 return 0;
657} 659}
@@ -678,7 +680,7 @@ void *timer_poll( void *arg )
678 handler->timers[0]->func(handler->timers[0]->func_arg1, handler->timers[0]->func_arg2); 680 handler->timers[0]->func(handler->timers[0]->func_arg1, handler->timers[0]->func_arg2);
679 LOGGER_DEBUG("Exectued timer assigned at: %d", handler->timers[0]->timeout); 681 LOGGER_DEBUG("Exectued timer assigned at: %d", handler->timers[0]->timeout);
680 682
681 timer_release(handler, 0); 683 timer_release(handler, 0, 0);
682 } 684 }
683 685
684 } 686 }
@@ -1107,8 +1109,8 @@ int terminate_call ( MSISession *session, MSICall *call )
1107 * NOTE: This has to be done before possibly 1109 * NOTE: This has to be done before possibly
1108 * locking the mutex the second time 1110 * locking the mutex the second time
1109 */ 1111 */
1110 timer_release ( session->timer_handler, call->request_timer_id ); 1112 timer_release ( session->timer_handler, call->request_timer_id, 1);
1111 timer_release ( session->timer_handler, call->ringing_timer_id ); 1113 timer_release ( session->timer_handler, call->ringing_timer_id, 1);
1112 1114
1113 /* Get a handle */ 1115 /* Get a handle */
1114 pthread_mutex_lock ( &call->mutex ); 1116 pthread_mutex_lock ( &call->mutex );
@@ -1371,7 +1373,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
1371 flush_peer_type ( call, msg, 0 ); 1373 flush_peer_type ( call, msg, 0 );
1372 1374
1373 1375
1374 timer_release ( session->timer_handler, call->ringing_timer_id ); 1376 timer_release ( session->timer_handler, call->ringing_timer_id, 1 );
1375 pthread_mutex_unlock(&session->mutex); 1377 pthread_mutex_unlock(&session->mutex);
1376 1378
1377 invoke_callback(call->call_idx, MSI_OnStarting); 1379 invoke_callback(call->call_idx, MSI_OnStarting);
@@ -1389,7 +1391,7 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
1389 LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id ); 1391 LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id );
1390 1392
1391 /* Stop timer */ 1393 /* Stop timer */
1392 timer_release ( session->timer_handler, call->request_timer_id ); 1394 timer_release ( session->timer_handler, call->request_timer_id, 1 );
1393 1395
1394 pthread_mutex_unlock(&session->mutex); 1396 pthread_mutex_unlock(&session->mutex);
1395 1397
@@ -1531,7 +1533,7 @@ void msi_handle_packet ( Messenger *messenger, int source, const uint8_t *data,
1531 } 1533 }
1532 1534
1533 /* Got response so cancel timer */ 1535 /* Got response so cancel timer */
1534 if ( call ) timer_release ( session->timer_handler, call->request_timer_id ); 1536 if ( call ) timer_release ( session->timer_handler, call->request_timer_id, 1 );
1535 1537
1536 uint8_t _response_value[32]; 1538 uint8_t _response_value[32];
1537 1539