code checked */
| 1522 | |
| 1523 | /* code checked */ |
| 1524 | static void rtpstream_stop_task(rtpstream_callinfo_t* callinfo) |
| 1525 | { |
| 1526 | threaddata_t **threadlist; |
| 1527 | taskentry_t *taskinfo = callinfo->taskinfo; |
| 1528 | int busy_index; |
| 1529 | |
| 1530 | if (taskinfo) |
| 1531 | { |
| 1532 | if (taskinfo->parent_thread) |
| 1533 | { |
| 1534 | /* this call's task is registered with an executing thread */ |
| 1535 | /* first move owning thread to the ready list - will be ready soon */ |
| 1536 | busy_index = taskinfo->parent_thread->busy_list_index; |
| 1537 | if (busy_index >= 0) |
| 1538 | { |
| 1539 | /* make sure we have enough entries in ready list */ |
| 1540 | if (num_ready_threads >= ready_threads_max) |
| 1541 | { |
| 1542 | /* need to allocate more memory for thread list */ |
| 1543 | ready_threads_max += RTPSTREAM_THREADBLOCKSIZE; |
| 1544 | threadlist = (threaddata_t **) realloc(ready_threads, sizeof(*ready_threads) * ready_threads_max); |
| 1545 | if (!threadlist) |
| 1546 | { |
| 1547 | /* could not allocate bigger block... reset max threads */ |
| 1548 | /* this is a problem - ready thread gets "lost" on busy list */ |
| 1549 | ready_threads_max -= RTPSTREAM_THREADBLOCKSIZE; |
| 1550 | } |
| 1551 | else |
| 1552 | { |
| 1553 | ready_threads = threadlist; |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | if (num_ready_threads < ready_threads_max) |
| 1558 | { |
| 1559 | /* OK, got space on ready list, move to ready list */ |
| 1560 | busy_threads[busy_index]->busy_list_index = -1; |
| 1561 | ready_threads[num_ready_threads++] = busy_threads[busy_index]; |
| 1562 | num_busy_threads--; |
| 1563 | /* fill up gap in the busy thread list */ |
| 1564 | if (busy_index != num_busy_threads) |
| 1565 | { |
| 1566 | busy_threads[busy_index] = busy_threads[num_busy_threads]; |
| 1567 | busy_threads[busy_index]->busy_list_index = busy_index; |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | /* then ask the thread to destroy this task (and its memory) */ |
| 1572 | pthread_mutex_lock(&(taskinfo->parent_thread->tasklist_mutex)); |
| 1573 | taskinfo->parent_thread->del_pending++; |
| 1574 | taskinfo->flags |= TI_KILLTASK; |
| 1575 | pthread_mutex_unlock(&(taskinfo->parent_thread->tasklist_mutex)); |
| 1576 | |
| 1577 | // PTHREAD IS NOT JOINABLE HERE... |
| 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | /* no playback thread owner, just free it */ |
no test coverage detected