summaryrefslogtreecommitdiff
path: root/auto_tests/toxav_many_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-11-27 21:08:01 -0500
committerirungentoo <irungentoo@gmail.com>2014-11-27 21:08:01 -0500
commit767c0653bd6531c463ee4d005938470462faeb71 (patch)
treeb85da33b8f1f4e8401e0d136da0562d719cb3214 /auto_tests/toxav_many_test.c
parentd6f733c7e6b1ab81f8942eaef212c92e89fbbb2c (diff)
Attempted fix of threading issue in test.
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r--auto_tests/toxav_many_test.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 5d327e53..4e3567d7 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -152,8 +152,12 @@ void *in_thread_call (void *arg)
152 register_callbacks(this_call->Callee.av, arg); 152 register_callbacks(this_call->Callee.av, arg);
153 153
154 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */ 154 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
155 pthread_mutex_lock(&muhmutex);
156
155 while (call_running[this_call->idx]) { 157 while (call_running[this_call->idx]) {
156 158
159 pthread_mutex_unlock(&muhmutex);
160
157 switch ( step ) { 161 switch ( step ) {
158 case 0: /* CALLER */ 162 case 0: /* CALLER */
159 toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10); 163 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)
162 break; 166 break;
163 167
164 case 1: /* CALLEE */ 168 case 1: /* CALLEE */
169 pthread_mutex_lock(&muhmutex);
170
165 if (this_call->Caller.status == Ringing) { 171 if (this_call->Caller.status == Ringing) {
166 call_print(call_idx, "Callee answers ..."); 172 call_print(call_idx, "Callee answers ...");
173 pthread_mutex_unlock(&muhmutex);
167 toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings); 174 toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings);
168 step++; 175 step++;
169 start = time(NULL); 176 start = time(NULL);
177 pthread_mutex_lock(&muhmutex);
170 } 178 }
171 179
180 pthread_mutex_unlock(&muhmutex);
172 break; 181 break;
173 182
174 case 2: /* Rtp transmission */ 183 case 2: /* Rtp transmission */
184 pthread_mutex_lock(&muhmutex);
185
175 if (this_call->Caller.status == InCall) { /* I think this is okay */ 186 if (this_call->Caller.status == InCall) { /* I think this is okay */
176 call_print(call_idx, "Sending rtp ..."); 187 call_print(call_idx, "Sending rtp ...");
188 pthread_mutex_unlock(&muhmutex);
177 189
178 c_sleep(1000); /* We have race condition here */ 190 c_sleep(1000); /* We have race condition here */
179 toxav_prepare_transmission(this_call->Callee.av, 0, 1); 191 toxav_prepare_transmission(this_call->Callee.av, 0, 1);
@@ -210,24 +222,36 @@ void *in_thread_call (void *arg)
210 /* Call over CALLER hangs up */ 222 /* Call over CALLER hangs up */
211 toxav_hangup(this_call->Caller.av, call_idx); 223 toxav_hangup(this_call->Caller.av, call_idx);
212 call_print(call_idx, "Hanging up ..."); 224 call_print(call_idx, "Hanging up ...");
225
226 pthread_mutex_lock(&muhmutex);
213 } 227 }
214 228
229 pthread_mutex_unlock(&muhmutex);
215 break; 230 break;
216 231
217 case 3: /* Wait for Both to have status ended */ 232 case 3: /* Wait for Both to have status ended */
233 pthread_mutex_lock(&muhmutex);
234
218 if (this_call->Caller.status == Ended) { 235 if (this_call->Caller.status == Ended) {
236 pthread_mutex_unlock(&muhmutex);
219 c_sleep(1000); /* race condition */ 237 c_sleep(1000); /* race condition */
238 pthread_mutex_lock(&muhmutex);
220 this_call->Callee.status = Ended; 239 this_call->Callee.status = Ended;
221 call_running[this_call->idx] = 0; 240 call_running[this_call->idx] = 0;
222 } 241 }
223 242
243 pthread_mutex_unlock(&muhmutex);
244
224 break; 245 break;
225 246
226 } 247 }
227 248
228 c_sleep(20); 249 c_sleep(20);
250
251 pthread_mutex_lock(&muhmutex);
229 } 252 }
230 253
254 pthread_mutex_unlock(&muhmutex);
231 call_print(call_idx, "Call ended successfully!"); 255 call_print(call_idx, "Call ended successfully!");
232 pthread_exit(NULL); 256 pthread_exit(NULL);
233} 257}