void ast_sched_dump(const struct sched_context *con) { /* * Dump the contents of the scheduler to * stderr */ struct sched *q; struct timeval tv = ast_tvnow(); #ifdef SCHED_MAX_CACHE ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt); #else ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total)\n", con->schedcnt, con->eventcnt - 1); #endif ast_log(LOG_DEBUG, "=============================================================\n"); ast_log(LOG_DEBUG, "|ID Callback Data Time (sec:ms) |\n"); ast_log(LOG_DEBUG, "+-----+-----------------+-----------------+-----------------+\n"); for (q = con->schedq; q; q = q->next) { struct timeval delta = ast_tvsub(q->when, tv); ast_log(LOG_DEBUG, "|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n", q->id, q->callback, q->data, delta.tv_sec, (long int)delta.tv_usec); } ast_log(LOG_DEBUG, "=============================================================\n"); }
int ast_poll2(struct pollfd *pArray, unsigned long n_fds, struct timeval *tv) { #if !defined(AST_POLL_COMPAT) struct timeval start = ast_tvnow(); #if defined(HAVE_PPOLL) struct timespec ts = { tv ? tv->tv_sec : 0, tv ? tv->tv_usec * 1000 : 0 }; int res = ppoll(pArray, n_fds, tv ? &ts : NULL, NULL); #else int res = poll(pArray, n_fds, tv ? tv->tv_sec * 1000 + tv->tv_usec / 1000 : -1); #endif struct timeval after = ast_tvnow(); if (res > 0 && tv && ast_tvdiff_ms(ast_tvadd(*tv, start), after) > 0) { *tv = ast_tvsub(*tv, ast_tvsub(after, start)); } else if (res > 0 && tv) { *tv = ast_tv(0, 0); } return res; #else ast_fdset read_descs, write_descs, except_descs; int ready_descriptors, max_fd = 0; FD_ZERO(&read_descs); FD_ZERO(&write_descs); FD_ZERO(&except_descs); if (pArray) { max_fd = map_poll_spec(pArray, n_fds, &read_descs, &write_descs, &except_descs); } ready_descriptors = ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, tv); if (ready_descriptors >= 0) { map_select_results(pArray, n_fds, &read_descs, &write_descs, &except_descs); } return ready_descriptors; #endif }
int __ast_rwlock_timedwrlock(const char *filename, int line, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout) { int res; #ifdef DEBUG_THREADS struct ast_lock_track *lt; int canlog = strcmp(filename, "logger.c") & t->tracking; #ifdef HAVE_BKTR struct ast_bt *bt = NULL; #endif #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE) if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) { /* Don't warn abount uninitialized lock. * Simple try to initialize it. * May be not needed in linux system. */ res = __ast_rwlock_init(t->tracking, filename, line, func, name, t); if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) { __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n", filename, line, func, name); return res; } } #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ if (t->tracking && !t->track) { ast_reentrancy_init(&t->track); } lt = t->track; if (t->tracking) { #ifdef HAVE_BKTR ast_reentrancy_lock(lt); if (lt->reentrancy != AST_MAX_REENTRANCY) { ast_bt_get_addresses(<->backtrace[lt->reentrancy]); bt = <->backtrace[lt->reentrancy]; } ast_reentrancy_unlock(lt); ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt); #else ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t); #endif } #endif /* DEBUG_THREADS */ #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout); #else do { struct timeval _start = ast_tvnow(), _diff; for (;;) { if (!(res = pthread_rwlock_trywrlock(&t->lock))) { break; } _diff = ast_tvsub(ast_tvnow(), _start); if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) { break; } usleep(1); } } while (0); #endif #ifdef DEBUG_THREADS if (!res && t->tracking) { ast_reentrancy_lock(lt); if (lt->reentrancy < AST_MAX_REENTRANCY) { lt->file[lt->reentrancy] = filename; lt->lineno[lt->reentrancy] = line; lt->func[lt->reentrancy] = func; lt->thread[lt->reentrancy] = pthread_self(); lt->reentrancy++; } ast_reentrancy_unlock(lt); if (t->tracking) { ast_mark_lock_acquired(t); } } else if (t->tracking) { #ifdef HAVE_BKTR if (lt->reentrancy) { ast_reentrancy_lock(lt); bt = <->backtrace[lt->reentrancy-1]; ast_reentrancy_unlock(lt); } else { bt = NULL; } if (t->tracking) { ast_remove_lock_info(t, bt); } #else if (t->tracking) { ast_remove_lock_info(t); } #endif } if (res) { __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n", filename, line, func, strerror(res)); DO_THREAD_CRASH; } #endif /* DEBUG_THREADS */ return res; }
$NetBSD$ --- main/sched.c.orig 2010-12-20 17:15:54.000000000 +0000 +++ main/sched.c @@ -553,12 +553,12 @@ void ast_sched_dump(struct ast_sched_con struct timeval delta; q = ast_heap_peek(con->sched_heap, x); delta = ast_tvsub(q->when, when); - ast_debug(1, "|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n", + ast_debug(1, "|%.4d | %-15p | %-15p | %.6jd : %.6jd |\n", q->id, q->callback, q->data, - (long)delta.tv_sec, - (long int)delta.tv_usec); + (intmax_t)delta.tv_sec, + (intmax_t)delta.tv_usec); } ast_mutex_unlock(&con->lock); ast_debug(1, "=============================================================\n");
struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume) { struct ast_trans_pvt *p; struct ast_frame *out; struct timeval delivery; p = path; /* Feed the first frame into the first translator */ p->step->framein(p->state, f); if (!ast_tvzero(f->delivery)) { if (!ast_tvzero(path->nextin)) { /* Make sure this is in line with what we were expecting */ if (!ast_tveq(path->nextin, f->delivery)) { /* The time has changed between what we expected and this most recent time on the new packet. If we have a valid prediction adjust our output time appropriately */ if (!ast_tvzero(path->nextout)) { path->nextout = ast_tvadd(path->nextout, ast_tvsub(f->delivery, path->nextin)); } path->nextin = f->delivery; } } else { /* This is our first pass. Make sure the timing looks good */ path->nextin = f->delivery; path->nextout = f->delivery; } /* Predict next incoming sample */ path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, 8000)); } delivery = f->delivery; if (consume) ast_frfree(f); while(p) { out = p->step->frameout(p->state); /* If we get nothing out, return NULL */ if (!out) return NULL; /* If there is a next state, feed it in there. If not, return this frame */ if (p->next) p->next->step->framein(p->next->state, out); else { if (!ast_tvzero(delivery)) { /* Regenerate prediction after a discontinuity */ if (ast_tvzero(path->nextout)) path->nextout = ast_tvnow(); /* Use next predicted outgoing timestamp */ out->delivery = path->nextout; /* Predict next outgoing timestamp from samples in this frame. */ path->nextout = ast_tvadd(path->nextout, ast_samp2tv( out->samples, 8000)); } else { out->delivery = ast_tv(0, 0); } /* Invalidate prediction if we're entering a silence period */ if (out->frametype == AST_FRAME_CNG) path->nextout = ast_tv(0, 0); return out; } p = p->next; } ast_log(LOG_WARNING, "I should never get here...\n"); return NULL; }