Go to the source code of this file.
Data Structures | |
struct | ast_cb_names |
Defines | |
#define | ast_sched_add_object(obj, con, when, callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) |
Convenience macro for objects and reference (add). | |
#define | AST_SCHED_CB(a) ((ast_sched_cb)(a)) |
#define | AST_SCHED_DEL(sched, id) |
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attempting to remove the scheduled task, then whatever callback had been running will complete and reinsert the task into the scheduler. | |
#define | ast_sched_del_object(obj, destructor, con, id) |
Convenience macro for objects and reference (del). | |
#define | AST_SCHED_DEL_SPINLOCK(sched, id, lock) |
schedule task to get deleted releasing the lock between attempts | |
#define | AST_SCHED_DEL_UNREF(sched, id, refcall) |
schedule task to get deleted and call unref function | |
#define | AST_SCHED_REPLACE(id, sched, when, callback, data) AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0) |
#define | AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) |
#define | AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) |
#define | AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) |
#define | SCHED_MAX_CACHE 128 |
Max num of schedule structs. | |
Typedefs | |
typedef int(*) | ast_sched_cb (const void *data) |
callback for a cheops scheduler A cheops scheduler callback takes a pointer with callback data and | |
Functions | |
int | ast_sched_add (struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result |
Adds a scheduled event Schedule an event to take place at some point in the future. callback will be called with data as the argument, when milliseconds into the future (approximately) If callback returns 0, no further events will be re-scheduled. | |
int | ast_sched_add_variable (struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result |
Schedule callback(data) to happen when ms into the future. | |
int | ast_sched_del (struct sched_context *con, int id) attribute_warn_unused_result |
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own event, but return 0 instead. In most cases, you should not call this routine directly, but use the AST_SCHED_DEL() macro instead (especially if you don't intend to do something different when it returns failure). | |
void | ast_sched_dump (struct sched_context *con) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr. | |
const void * | ast_sched_find_data (struct sched_context *con, int id) |
Find a sched structure and return the data field associated with it. | |
int | ast_sched_replace (int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result |
replace a scheduler entry | |
int | ast_sched_replace_variable (int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result |
replace a scheduler entry | |
void | ast_sched_report (struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames) |
Show statics on what it is in the schedule queue. | |
int | ast_sched_runq (struct sched_context *con) |
Runs the queue. | |
int | ast_sched_wait (struct sched_context *con) attribute_warn_unused_result |
Determines number of seconds until the next outstanding event to take place Determine the number of seconds until the next outstanding event should take place, and return the number of milliseconds until it needs to be run. This value is perfect for passing to the poll call. | |
long | ast_sched_when (struct sched_context *con, int id) |
Returns the number of seconds before an event takes place. | |
sched_context * | sched_context_create (void) |
New schedule context. | |
void | sched_context_destroy (struct sched_context *c) |
destroys a schedule context Destroys (free's) the given sched_context structure |
Definition in file sched.h.
#define ast_sched_add_object | ( | obj, | |||
con, | |||||
when, | |||||
callback | ) | ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj))) |
#define AST_SCHED_CB | ( | a | ) | ((ast_sched_cb)(a)) |
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attempting to remove the scheduled task, then whatever callback had been running will complete and reinsert the task into the scheduler.
Since macro expansion essentially works like pass-by-name parameter passing, this macro will still work correctly even if the id of the task to delete changes. This holds as long as the name of the id which could change is passed to the macro and not a copy of the value of the id.
Definition at line 51 of file sched.h.
Referenced by __oh323_destroy(), __oh323_update_info(), __sip_reliable_xmit(), __sip_semi_ack(), ack_trans(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_destroy(), ast_rtp_stop(), ast_sched_replace(), ast_sched_replace_variable(), build_gateway(), build_peer(), delete_users(), destroy_packet(), destroy_packets(), destroy_peer(), dialog_unlink_all(), dnsmgr_start_refresh(), do_reload(), filestream_destructor(), handle_command_response(), handle_request_invite(), handle_response_register(), iax2_destroy_helper(), iax2_frame_free(), make_trunk(), mgcpsock_read(), misdn_tasks_remove(), qualify_peer(), receive_digit(), schedule_delivery(), sip_registry_destroy(), socket_process(), and submit_unscheduled_batch().
#define ast_sched_del_object | ( | obj, | |||
destructor, | |||||
con, | |||||
id | ) |
schedule task to get deleted releasing the lock between attempts
Definition at line 84 of file sched.h.
Referenced by iax2_destroy_helper().
schedule task to get deleted and call unref function
Definition at line 67 of file sched.h.
Referenced by __sip_destroy(), build_peer(), dialog_unlink_all(), handle_request_do(), handle_response_invite(), parse_register_contact(), restart_session_timer(), sip_hangup(), sip_indicate(), sip_poke_peer(), and stop_session_timer().
#define AST_SCHED_REPLACE_UNREF | ( | id, | |||
sched, | |||||
when, | |||||
callback, | |||||
data, | |||||
unrefcall, | |||||
addfailcall, | |||||
refcall | ) | AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall) |
Definition at line 135 of file sched.h.
Referenced by handle_response_peerpoke(), handle_response_register(), reg_source_db(), sip_call(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_send_all_registers(), and transmit_register().
#define SCHED_MAX_CACHE 128 |
Max num of schedule structs.
Definition at line 37 of file sched.h.
Referenced by sched_release().
typedef int(*) ast_sched_cb(const void *data) |
int ast_sched_add | ( | struct sched_context * | con, | |
int | when, | |||
ast_sched_cb | callback, | |||
const void * | data | |||
) |
Adds a scheduled event Schedule an event to take place at some point in the future. callback will be called with data as the argument, when milliseconds into the future (approximately) If callback returns 0, no further events will be re-scheduled.
con | Scheduler context to add | |
when | how many milliseconds to wait for event to occur | |
callback | function to call when the amount of time expires | |
data | data to pass to the callback |
Definition at line 314 of file sched.c.
References ast_sched_add_variable().
Referenced by __oh323_update_info(), ast_readaudio_callback(), ast_readvideo_callback(), ast_rtp_raw_write(), ast_rtp_read(), ast_sched_replace(), do_register(), do_reload(), dundi_discover(), dundi_query(), dundi_send(), handle_command_response(), handle_request_invite(), handle_response_invite(), iax2_hangup(), iax2_key_rotate(), iax2_sched_add(), mgcp_postrequest(), parse_register_contact(), populate_addr(), precache_trans(), qualify_peer(), queue_request(), receive_digit(), rtp_red_init(), sip_scheddestroy(), start_session_timer(), submit_scheduled_batch(), submit_unscheduled_batch(), and transmit_register().
00315 { 00316 return ast_sched_add_variable(con, when, callback, data, 0); 00317 }
int ast_sched_add_variable | ( | struct sched_context * | con, | |
int | when, | |||
ast_sched_cb | callback, | |||
const void * | data, | |||
int | variable | |||
) |
Schedule callback(data) to happen when ms into the future.
Adds a scheduled event with rescheduling support
con | Scheduler context to add | |
when | how many milliseconds to wait for event to occur | |
callback | function to call when the amount of time expires | |
data | data to pass to the callback | |
variable | If true, the result value of callback function will be used for rescheduling Schedule an event to take place at some point in the future. Callback will be called with data as the argument, when milliseconds into the future (approximately) If callback returns 0, no further events will be re-scheduled |
Definition at line 274 of file sched.c.
References ast_debug, ast_mutex_lock(), ast_mutex_unlock(), ast_sched_dump(), ast_tv(), sched::callback, sched::data, DEBUG, sched_context::eventcnt, sched::id, sched_context::lock, option_debug, sched::resched, sched_alloc(), sched_release(), sched_settime(), schedule(), sched::variable, and sched::when.
Referenced by _misdn_tasks_add_variable(), ast_sched_add(), ast_sched_replace_variable(), dnsmgr_start_refresh(), and do_reload().
00275 { 00276 struct sched *tmp; 00277 int res = -1; 00278 00279 DEBUG(ast_debug(1, "ast_sched_add()\n")); 00280 00281 ast_mutex_lock(&con->lock); 00282 if ((tmp = sched_alloc(con))) { 00283 tmp->id = con->eventcnt++; 00284 tmp->callback = callback; 00285 tmp->data = data; 00286 tmp->resched = when; 00287 tmp->variable = variable; 00288 tmp->when = ast_tv(0, 0); 00289 if (sched_settime(&tmp->when, when)) { 00290 sched_release(con, tmp); 00291 } else { 00292 schedule(con, tmp); 00293 res = tmp->id; 00294 } 00295 } 00296 #ifdef DUMP_SCHEDULER 00297 /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ 00298 if (option_debug) 00299 ast_sched_dump(con); 00300 #endif 00301 ast_mutex_unlock(&con->lock); 00302 00303 return res; 00304 }
int ast_sched_del | ( | struct sched_context * | con, | |
int | id | |||
) |
Deletes a scheduled event Remove this event from being run. A procedure should not remove its own event, but return 0 instead. In most cases, you should not call this routine directly, but use the AST_SCHED_DEL() macro instead (especially if you don't intend to do something different when it returns failure).
con | scheduling context to delete item from | |
id | ID of the scheduled item to delete |
Definition at line 336 of file sched.c.
References ast_assert, ast_debug, AST_DLLIST_REMOVE, ast_hashtab_lookup(), ast_hashtab_remove_this_object(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_dump(), DEBUG, sched::id, sched::list, LOG_WARNING, option_debug, s, and sched_release().
Referenced by __sip_ack(), iax2_poke_peer(), reg_source_db(), sip_cancel_destroy(), socket_process(), unlink_peer(), and update_registry().
00340 { 00341 struct sched *s, tmp; 00342 00343 DEBUG(ast_debug(1, "ast_sched_del(%d)\n", id)); 00344 00345 ast_mutex_lock(&con->lock); 00346 00347 /* OK, this is the heart of the sched performance upgrade. 00348 If we have 4700 peers, we can have 4700+ entries in the 00349 schedq list. searching this would take time. So, I add a 00350 hashtab to the context to keep track of each entry, by id. 00351 I also leave the linked list alone, almost, -- I implement 00352 a doubly-linked list instead, because it would do little good 00353 to look up the id in a hashtab, and then have to run thru 00354 a couple thousand entries to remove it from the schedq list! */ 00355 tmp.id = id; 00356 s = ast_hashtab_lookup(con->schedq_ht, &tmp); 00357 if (s) { 00358 struct sched *x = AST_DLLIST_REMOVE(&con->schedq, s, list); 00359 00360 if (!x) 00361 ast_log(LOG_WARNING,"sched entry %d not in the schedq list?\n", s->id); 00362 00363 if (!ast_hashtab_remove_this_object(con->schedq_ht, s)) 00364 ast_log(LOG_WARNING,"Found sched entry %d, then couldn't remove it?\n", s->id); 00365 con->schedcnt--; 00366 sched_release(con, s); 00367 } 00368 00369 #ifdef DUMP_SCHEDULER 00370 /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ 00371 if (option_debug) 00372 ast_sched_dump(con); 00373 #endif 00374 ast_mutex_unlock(&con->lock); 00375 00376 if (!s) { 00377 ast_debug(1, "Attempted to delete nonexistent schedule entry %d!\n", id); 00378 #ifndef AST_DEVMODE 00379 ast_assert(s != NULL); 00380 #else 00381 _ast_assert(0, "s != NULL", file, line, function); 00382 #endif 00383 return -1; 00384 } 00385 00386 return 0; 00387 }
void ast_sched_dump | ( | struct sched_context * | con | ) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
con | Context to dump |
Definition at line 421 of file sched.c.
References ast_debug, AST_DLLIST_TRAVERSE, ast_mutex_lock(), ast_mutex_unlock(), ast_tvnow(), ast_tvsub(), sched::callback, sched::data, sched_context::eventcnt, sched_context::highwater, sched::id, sched_context::lock, sched_context::schedccnt, sched_context::schedcnt, sched_context::schedq, and sched::when.
Referenced by ast_sched_add_variable(), ast_sched_del(), sip_do_reload(), and unload_module().
00422 { 00423 struct sched *q; 00424 struct timeval when = ast_tvnow(); 00425 #ifdef SCHED_MAX_CACHE 00426 ast_debug(1, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache, %d high-water)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt, con->highwater); 00427 #else 00428 ast_debug(1, "Asterisk Schedule Dump (%d in Q, %d Total, %d high-water)\n", con->schedcnt, con->eventcnt - 1, con->highwater); 00429 #endif 00430 00431 ast_debug(1, "=============================================================\n"); 00432 ast_debug(1, "|ID Callback Data Time (sec:ms) |\n"); 00433 ast_debug(1, "+-----+-----------------+-----------------+-----------------+\n"); 00434 ast_mutex_lock(&con->lock); 00435 AST_DLLIST_TRAVERSE(&con->schedq, q, list) { 00436 struct timeval delta = ast_tvsub(q->when, when); 00437 00438 ast_debug(1, "|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n", 00439 q->id, 00440 q->callback, 00441 q->data, 00442 (long)delta.tv_sec, 00443 (long int)delta.tv_usec); 00444 } 00445 ast_mutex_unlock(&con->lock); 00446 ast_debug(1, "=============================================================\n"); 00447 }
const void* ast_sched_find_data | ( | struct sched_context * | con, | |
int | id | |||
) |
Find a sched structure and return the data field associated with it.
con | scheduling context in which to search fro the matching id | |
id | ID of the scheduled item to find |
Definition at line 319 of file sched.c.
References ast_hashtab_lookup(), sched::data, sched::id, and sched_context::schedq_ht.
00320 { 00321 struct sched tmp,*res; 00322 tmp.id = id; 00323 res = ast_hashtab_lookup(con->schedq_ht, &tmp); 00324 if (res) 00325 return res->data; 00326 return NULL; 00327 }
int ast_sched_replace | ( | int | old_id, | |
struct sched_context * | con, | |||
int | when, | |||
ast_sched_cb | callback, | |||
const void * | data | |||
) |
replace a scheduler entry
-1 | failure | |
otherwise,returns | scheduled item ID |
Definition at line 306 of file sched.c.
References ast_sched_add(), and AST_SCHED_DEL.
00307 { 00308 if (old_id > -1) { 00309 AST_SCHED_DEL(con, old_id); 00310 } 00311 return ast_sched_add(con, when, callback, data); 00312 }
int ast_sched_replace_variable | ( | int | old_id, | |
struct sched_context * | con, | |||
int | when, | |||
ast_sched_cb | callback, | |||
const void * | data, | |||
int | variable | |||
) |
replace a scheduler entry
-1 | failure | |
otherwise,returns | scheduled item ID |
Definition at line 262 of file sched.c.
References ast_sched_add_variable(), and AST_SCHED_DEL.
00263 { 00264 /* 0 means the schedule item is new; do not delete */ 00265 if (old_id > 0) { 00266 AST_SCHED_DEL(con, old_id); 00267 } 00268 return ast_sched_add_variable(con, when, callback, data, variable); 00269 }
void ast_sched_report | ( | struct sched_context * | con, | |
struct ast_str ** | buf, | |||
struct ast_cb_names * | cbnames | |||
) |
Show statics on what it is in the schedule queue.
con | Schedule context to check | |
buf | dynamic string to store report | |
cbnames | to check against |
Definition at line 389 of file sched.c.
References AST_DLLIST_TRAVERSE, ast_mutex_lock(), ast_str_set(), buf, sched::callback, ast_cb_names::cblist, sched_context::highwater, sched::list, sched_context::lock, ast_cb_names::numassocs, sched_context::schedcnt, and sched_context::schedq.
Referenced by sip_show_sched().
00390 { 00391 int i; 00392 struct sched *cur; 00393 int countlist[cbnames->numassocs + 1]; 00394 00395 ast_str_set(buf, 0, " Highwater = %d\n schedcnt = %d\n", con->highwater, con->schedcnt); 00396 00397 ast_mutex_lock(&con->lock); 00398 AST_DLLIST_TRAVERSE(&con->schedq, cur, list) { 00399 /* match the callback to the cblist */ 00400 for (i = 0; i < cbnames->numassocs; i++) { 00401 if (cur->callback == cbnames->cblist[i]) { 00402 break; 00403 } 00404 } 00405 if (i < cbnames->numassocs) { 00406 countlist[i]++; 00407 } else { 00408 countlist[cbnames->numassocs]++; 00409 } 00410 } 00411 ast_mutex_unlock(&con->lock); 00412 00413 for (i = 0; i < cbnames->numassocs; i++) { 00414 ast_str_append(buf, 0, " %s : %d\n", cbnames->list[i], countlist[i]); 00415 } 00416 00417 ast_str_append(buf, 0, " <unknown> : %d\n", countlist[cbnames->numassocs]); 00418 }
int ast_sched_runq | ( | struct sched_context * | con | ) |
Runs the queue.
con | Scheduling context to run Run the queue, executing all callbacks which need to be performed at this time. | |
con | context to act upon |
Definition at line 452 of file sched.c.
References ast_debug, AST_DLLIST_EMPTY, AST_DLLIST_FIRST, AST_DLLIST_REMOVE_HEAD, ast_hashtab_remove_this_object(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_tv(), ast_tvadd(), ast_tvcmp(), ast_tvnow(), sched::callback, sched::data, DEBUG, sched::id, sched_context::lock, LOG_ERROR, sched::resched, sched_release(), sched_settime(), sched_context::schedcnt, sched_context::schedq, sched_context::schedq_ht, schedule(), sched::variable, and sched::when.
Referenced by background_detect_exec(), do_cdr(), do_monitor(), do_refresh(), handle_speechrecognize(), misdn_tasks_thread_func(), network_thread(), reload_config(), sched_thread(), speech_background(), wait_for_winner(), and waitstream_core().
00453 { 00454 struct sched *current; 00455 struct timeval when; 00456 int numevents; 00457 int res; 00458 00459 DEBUG(ast_debug(1, "ast_sched_runq()\n")); 00460 00461 ast_mutex_lock(&con->lock); 00462 00463 for (numevents = 0; !AST_DLLIST_EMPTY(&con->schedq); numevents++) { 00464 /* schedule all events which are going to expire within 1ms. 00465 * We only care about millisecond accuracy anyway, so this will 00466 * help us get more than one event at one time if they are very 00467 * close together. 00468 */ 00469 when = ast_tvadd(ast_tvnow(), ast_tv(0, 1000)); 00470 if (ast_tvcmp(AST_DLLIST_FIRST(&con->schedq)->when, when) != -1) 00471 break; 00472 00473 current = AST_DLLIST_REMOVE_HEAD(&con->schedq, list); 00474 if (!ast_hashtab_remove_this_object(con->schedq_ht, current)) 00475 ast_log(LOG_ERROR,"Sched entry %d was in the schedq list but not in the hashtab???\n", current->id); 00476 00477 con->schedcnt--; 00478 00479 /* 00480 * At this point, the schedule queue is still intact. We 00481 * have removed the first event and the rest is still there, 00482 * so it's permissible for the callback to add new events, but 00483 * trying to delete itself won't work because it isn't in 00484 * the schedule queue. If that's what it wants to do, it 00485 * should return 0. 00486 */ 00487 00488 ast_mutex_unlock(&con->lock); 00489 res = current->callback(current->data); 00490 ast_mutex_lock(&con->lock); 00491 00492 if (res) { 00493 /* 00494 * If they return non-zero, we should schedule them to be 00495 * run again. 00496 */ 00497 if (sched_settime(¤t->when, current->variable? res : current->resched)) { 00498 sched_release(con, current); 00499 } else 00500 schedule(con, current); 00501 } else { 00502 /* No longer needed, so release it */ 00503 sched_release(con, current); 00504 } 00505 } 00506 00507 ast_mutex_unlock(&con->lock); 00508 00509 return numevents; 00510 }
int ast_sched_wait | ( | struct sched_context * | con | ) |
Determines number of seconds until the next outstanding event to take place Determine the number of seconds until the next outstanding event should take place, and return the number of milliseconds until it needs to be run. This value is perfect for passing to the poll call.
con | context to act upon |
Definition at line 168 of file sched.c.
References ast_debug, AST_DLLIST_EMPTY, AST_DLLIST_FIRST, ast_mutex_lock(), ast_mutex_unlock(), ast_tvdiff_ms(), ast_tvnow(), DEBUG, sched_context::lock, and sched_context::schedq.
Referenced by background_detect_exec(), do_cdr(), do_monitor(), do_refresh(), handle_speechrecognize(), misdn_tasks_thread_func(), network_thread(), sched_thread(), speech_background(), wait_for_winner(), and waitstream_core().
00169 { 00170 int ms; 00171 00172 DEBUG(ast_debug(1, "ast_sched_wait()\n")); 00173 00174 ast_mutex_lock(&con->lock); 00175 if (AST_DLLIST_EMPTY(&con->schedq)) { 00176 ms = -1; 00177 } else { 00178 ms = ast_tvdiff_ms(AST_DLLIST_FIRST(&con->schedq)->when, ast_tvnow()); 00179 if (ms < 0) 00180 ms = 0; 00181 } 00182 ast_mutex_unlock(&con->lock); 00183 00184 return ms; 00185 }
long ast_sched_when | ( | struct sched_context * | con, | |
int | id | |||
) |
Returns the number of seconds before an event takes place.
con | Context to use | |
id | Id to dump |
Definition at line 512 of file sched.c.
References ast_debug, ast_hashtab_lookup(), ast_mutex_lock(), ast_mutex_unlock(), ast_tvnow(), DEBUG, sched::id, sched_context::lock, s, and sched_context::schedq_ht.
Referenced by _sip_show_peer(), handle_cli_status(), and parse_register_contact().
00513 { 00514 struct sched *s, tmp; 00515 long secs = -1; 00516 DEBUG(ast_debug(1, "ast_sched_when()\n")); 00517 00518 ast_mutex_lock(&con->lock); 00519 00520 /* these next 2 lines replace a lookup loop */ 00521 tmp.id = id; 00522 s = ast_hashtab_lookup(con->schedq_ht, &tmp); 00523 00524 if (s) { 00525 struct timeval now = ast_tvnow(); 00526 secs = s->when.tv_sec - now.tv_sec; 00527 } 00528 ast_mutex_unlock(&con->lock); 00529 00530 return secs; 00531 }
struct sched_context* sched_context_create | ( | void | ) |
New schedule context.
Definition at line 90 of file sched.c.
References ast_calloc, ast_hashtab_create(), ast_hashtab_newsize_java(), ast_hashtab_resize_java(), ast_mutex_init(), sched_cmp(), and sched_hash().
Referenced by ast_cdr_engine_init(), ast_channel_alloc(), dnsmgr_init(), load_module(), and misdn_tasks_init().
00091 { 00092 struct sched_context *tmp; 00093 00094 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) 00095 return NULL; 00096 00097 ast_mutex_init(&tmp->lock); 00098 tmp->eventcnt = 1; 00099 00100 tmp->schedq_ht = ast_hashtab_create(23, sched_cmp, ast_hashtab_resize_java, ast_hashtab_newsize_java, sched_hash, 1); 00101 00102 return tmp; 00103 }
void sched_context_destroy | ( | struct sched_context * | c | ) |
destroys a schedule context Destroys (free's) the given sched_context structure
c | Context to free |
Definition at line 105 of file sched.c.
References AST_DLLIST_REMOVE_HEAD, ast_free, ast_hashtab_destroy(), AST_LIST_REMOVE_HEAD, ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), sched::list, sched_context::lock, s, sched_context::schedc, sched_context::schedq, and sched_context::schedq_ht.
Referenced by __unload_module(), ast_channel_alloc(), ast_channel_free(), ast_hangup(), load_module(), misdn_tasks_destroy(), and unload_module().
00106 { 00107 struct sched *s; 00108 00109 ast_mutex_lock(&con->lock); 00110 00111 #ifdef SCHED_MAX_CACHE 00112 /* Eliminate the cache */ 00113 while ((s = AST_LIST_REMOVE_HEAD(&con->schedc, list))) 00114 ast_free(s); 00115 #endif 00116 00117 /* And the queue */ 00118 while ((s = AST_DLLIST_REMOVE_HEAD(&con->schedq, list))) 00119 ast_free(s); 00120 00121 ast_hashtab_destroy(con->schedq_ht, NULL); 00122 con->schedq_ht = NULL; 00123 00124 /* And the context */ 00125 ast_mutex_unlock(&con->lock); 00126 ast_mutex_destroy(&con->lock); 00127 ast_free(con); 00128 }