Attempted fix of threading issue in test.

This commit is contained in:
irungentoo 2014-11-27 21:08:01 -05:00
parent d6f733c7e6
commit 767c0653bd
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -152,8 +152,12 @@ void *in_thread_call (void *arg)
register_callbacks(this_call->Callee.av, arg); register_callbacks(this_call->Callee.av, arg);
/* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */ /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
pthread_mutex_lock(&muhmutex);
while (call_running[this_call->idx]) { while (call_running[this_call->idx]) {
pthread_mutex_unlock(&muhmutex);
switch ( step ) { switch ( step ) {
case 0: /* CALLER */ case 0: /* CALLER */
toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10); toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10);
@ -162,18 +166,26 @@ void *in_thread_call (void *arg)
break; break;
case 1: /* CALLEE */ case 1: /* CALLEE */
pthread_mutex_lock(&muhmutex);
if (this_call->Caller.status == Ringing) { if (this_call->Caller.status == Ringing) {
call_print(call_idx, "Callee answers ..."); call_print(call_idx, "Callee answers ...");
pthread_mutex_unlock(&muhmutex);
toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings); toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings);
step++; step++;
start = time(NULL); start = time(NULL);
pthread_mutex_lock(&muhmutex);
} }
pthread_mutex_unlock(&muhmutex);
break; break;
case 2: /* Rtp transmission */ case 2: /* Rtp transmission */
pthread_mutex_lock(&muhmutex);
if (this_call->Caller.status == InCall) { /* I think this is okay */ if (this_call->Caller.status == InCall) { /* I think this is okay */
call_print(call_idx, "Sending rtp ..."); call_print(call_idx, "Sending rtp ...");
pthread_mutex_unlock(&muhmutex);
c_sleep(1000); /* We have race condition here */ c_sleep(1000); /* We have race condition here */
toxav_prepare_transmission(this_call->Callee.av, 0, 1); toxav_prepare_transmission(this_call->Callee.av, 0, 1);
@ -210,24 +222,36 @@ void *in_thread_call (void *arg)
/* Call over CALLER hangs up */ /* Call over CALLER hangs up */
toxav_hangup(this_call->Caller.av, call_idx); toxav_hangup(this_call->Caller.av, call_idx);
call_print(call_idx, "Hanging up ..."); call_print(call_idx, "Hanging up ...");
pthread_mutex_lock(&muhmutex);
} }
pthread_mutex_unlock(&muhmutex);
break; break;
case 3: /* Wait for Both to have status ended */ case 3: /* Wait for Both to have status ended */
pthread_mutex_lock(&muhmutex);
if (this_call->Caller.status == Ended) { if (this_call->Caller.status == Ended) {
pthread_mutex_unlock(&muhmutex);
c_sleep(1000); /* race condition */ c_sleep(1000); /* race condition */
pthread_mutex_lock(&muhmutex);
this_call->Callee.status = Ended; this_call->Callee.status = Ended;
call_running[this_call->idx] = 0; call_running[this_call->idx] = 0;
} }
pthread_mutex_unlock(&muhmutex);
break; break;
} }
c_sleep(20); c_sleep(20);
pthread_mutex_lock(&muhmutex);
} }
pthread_mutex_unlock(&muhmutex);
call_print(call_idx, "Call ended successfully!"); call_print(call_idx, "Call ended successfully!");
pthread_exit(NULL); pthread_exit(NULL);
} }