This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
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 | 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) |
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) |
Schedule callback(data) to happen when ms into the future. | |
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. | |
void | ast_sched_dump (const struct sched_context *con) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr. | |
int | ast_sched_runq (struct sched_context *con) |
Runs the queue. | |
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. | |
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 50 of file sched.h.
Referenced by __oh323_destroy(), __oh323_update_info(), __sip_destroy(), __sip_semi_ack(), ack_trans(), ast_closestream(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_destroy(), ast_rtp_stop(), auth_fail(), build_gateway(), build_peer(), destroy_packet(), destroy_packets(), destroy_peer(), dnsmgr_start_refresh(), do_reload(), handle_command_response(), handle_response_invite(), handle_response_peerpoke(), handle_response_register(), iax2_ack_registry(), iax2_destroy_helper(), iax2_do_register(), iax2_dprequest(), iax2_frame_free(), iax2_provision(), make_trunk(), mgcpsock_read(), misdn_tasks_remove(), parse_register_contact(), qualify_peer(), receive_digit(), reg_source_db(), schedule_delivery(), sip_call(), sip_hangup(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_registry_destroy(), sip_scheddestroy(), sip_send_all_registers(), socket_process(), submit_unscheduled_batch(), transmit_register(), and update_jbsched().
#define ast_sched_del_object | ( | obj, | |||
destructor, | |||||
con, | |||||
id | ) |
#define SCHED_MAX_CACHE 128 |
Max num of schedule structs.
Definition at line 36 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 247 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(), do_register(), do_reload(), dundi_discover(), dundi_query(), dundi_send(), handle_command_response(), handle_response_invite(), handle_response_peerpoke(), handle_response_register(), iax2_sched_add(), mgcp_postrequest(), parse_register_contact(), populate_addr(), precache_trans(), qualify_peer(), receive_digit(), reg_source_db(), sip_call(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_scheddestroy(), sip_send_all_registers(), submit_scheduled_batch(), submit_unscheduled_batch(), and transmit_register().
00248 { 00249 return ast_sched_add_variable(con, when, callback, data, 0); 00250 }
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 214 of file sched.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_dump(), DEBUG, sched_context::eventcnt, sched_context::lock, LOG_DEBUG, LOG_NOTICE, option_debug, sched_alloc(), sched_release(), sched_settime(), and schedule().
Referenced by __sip_reliable_xmit(), _misdn_tasks_add_variable(), ast_sched_add(), dnsmgr_start_refresh(), and do_reload().
00215 { 00216 struct sched *tmp; 00217 int res = -1; 00218 DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n")); 00219 if (!when) { 00220 ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n"); 00221 return -1; 00222 } 00223 ast_mutex_lock(&con->lock); 00224 if ((tmp = sched_alloc(con))) { 00225 tmp->id = con->eventcnt++; 00226 tmp->callback = callback; 00227 tmp->data = data; 00228 tmp->resched = when; 00229 tmp->variable = variable; 00230 tmp->when = ast_tv(0, 0); 00231 if (sched_settime(&tmp->when, when)) { 00232 sched_release(con, tmp); 00233 } else { 00234 schedule(con, tmp); 00235 res = tmp->id; 00236 } 00237 } 00238 #ifdef DUMP_SCHEDULER 00239 /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ 00240 if (option_debug) 00241 ast_sched_dump(con); 00242 #endif 00243 ast_mutex_unlock(&con->lock); 00244 return res; 00245 }
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.
con | scheduling context to delete item from | |
id | ID of the scheduled item to delete |
Definition at line 258 of file sched.c.
References ast_assert, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_dump(), DEBUG, sched_context::lock, LOG_DEBUG, option_debug, s, sched_release(), and sched_context::schedcnt.
Referenced by __sip_ack(), delete_users(), iax2_poke_peer(), reg_source_db(), sip_cancel_destroy(), socket_process(), unlink_peer(), and update_registry().
00259 { 00260 struct sched *s; 00261 00262 DEBUG(ast_log(LOG_DEBUG, "ast_sched_del()\n")); 00263 00264 ast_mutex_lock(&con->lock); 00265 AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, s, list) { 00266 if (s->id == id) { 00267 AST_LIST_REMOVE_CURRENT(&con->schedq, list); 00268 con->schedcnt--; 00269 sched_release(con, s); 00270 break; 00271 } 00272 } 00273 AST_LIST_TRAVERSE_SAFE_END 00274 00275 #ifdef DUMP_SCHEDULER 00276 /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ 00277 if (option_debug) 00278 ast_sched_dump(con); 00279 #endif 00280 ast_mutex_unlock(&con->lock); 00281 00282 if (!s) { 00283 if (option_debug) 00284 ast_log(LOG_DEBUG, "Attempted to delete nonexistent schedule entry %d!\n", id); 00285 ast_assert(0); 00286 return -1; 00287 } 00288 00289 return 0; 00290 }
void ast_sched_dump | ( | const struct sched_context * | con | ) |
Dumps the scheduler contents Debugging: Dump the contents of the scheduler to stderr.
con | Context to dump |
Definition at line 293 of file sched.c.
References AST_LIST_TRAVERSE, ast_log(), ast_tvsub(), sched_context::eventcnt, LOG_DEBUG, and sched_context::schedcnt.
Referenced by ast_sched_add_variable(), and ast_sched_del().
00294 { 00295 struct sched *q; 00296 struct timeval tv = ast_tvnow(); 00297 #ifdef SCHED_MAX_CACHE 00298 ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt); 00299 #else 00300 ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total)\n", con->schedcnt, con->eventcnt - 1); 00301 #endif 00302 00303 ast_log(LOG_DEBUG, "=============================================================\n"); 00304 ast_log(LOG_DEBUG, "|ID Callback Data Time (sec:ms) |\n"); 00305 ast_log(LOG_DEBUG, "+-----+-----------------+-----------------+-----------------+\n"); 00306 AST_LIST_TRAVERSE(&con->schedq, q, list) { 00307 struct timeval delta = ast_tvsub(q->when, tv); 00308 00309 ast_log(LOG_DEBUG, "|%.4d | %-15p | %-15p | %.6ld : %.6ld |\n", 00310 q->id, 00311 q->callback, 00312 q->data, 00313 delta.tv_sec, 00314 (long int)delta.tv_usec); 00315 } 00316 ast_log(LOG_DEBUG, "=============================================================\n"); 00317 00318 }
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 323 of file sched.c.
References AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_tvadd(), DEBUG, sched_context::lock, LOG_DEBUG, sched_release(), sched_settime(), sched_context::schedcnt, and schedule().
Referenced by background_detect_exec(), do_cdr(), do_monitor(), do_refresh(), misdn_tasks_thread_func(), network_thread(), reload_config(), sched_thread(), speech_background(), wait_for_winner(), and waitstream_core().
00324 { 00325 struct sched *current; 00326 struct timeval tv; 00327 int numevents; 00328 int res; 00329 00330 DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n")); 00331 00332 ast_mutex_lock(&con->lock); 00333 00334 for (numevents = 0; !AST_LIST_EMPTY(&con->schedq); numevents++) { 00335 /* schedule all events which are going to expire within 1ms. 00336 * We only care about millisecond accuracy anyway, so this will 00337 * help us get more than one event at one time if they are very 00338 * close together. 00339 */ 00340 tv = ast_tvadd(ast_tvnow(), ast_tv(0, 1000)); 00341 if (ast_tvcmp(AST_LIST_FIRST(&con->schedq)->when, tv) != -1) 00342 break; 00343 00344 current = AST_LIST_REMOVE_HEAD(&con->schedq, list); 00345 con->schedcnt--; 00346 00347 /* 00348 * At this point, the schedule queue is still intact. We 00349 * have removed the first event and the rest is still there, 00350 * so it's permissible for the callback to add new events, but 00351 * trying to delete itself won't work because it isn't in 00352 * the schedule queue. If that's what it wants to do, it 00353 * should return 0. 00354 */ 00355 00356 ast_mutex_unlock(&con->lock); 00357 res = current->callback(current->data); 00358 ast_mutex_lock(&con->lock); 00359 00360 if (res) { 00361 /* 00362 * If they return non-zero, we should schedule them to be 00363 * run again. 00364 */ 00365 if (sched_settime(¤t->when, current->variable? res : current->resched)) { 00366 sched_release(con, current); 00367 } else 00368 schedule(con, current); 00369 } else { 00370 /* No longer needed, so release it */ 00371 sched_release(con, current); 00372 } 00373 } 00374 00375 ast_mutex_unlock(&con->lock); 00376 00377 return numevents; 00378 }
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 148 of file sched.c.
References AST_LIST_EMPTY, AST_LIST_FIRST, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), DEBUG, sched_context::lock, and LOG_DEBUG.
Referenced by background_detect_exec(), do_cdr(), do_monitor(), do_refresh(), misdn_tasks_thread_func(), network_thread(), sched_thread(), speech_background(), wait_for_winner(), and waitstream_core().
00149 { 00150 int ms; 00151 00152 DEBUG(ast_log(LOG_DEBUG, "ast_sched_wait()\n")); 00153 00154 ast_mutex_lock(&con->lock); 00155 if (AST_LIST_EMPTY(&con->schedq)) { 00156 ms = -1; 00157 } else { 00158 ms = ast_tvdiff_ms(AST_LIST_FIRST(&con->schedq)->when, ast_tvnow()); 00159 if (ms < 0) 00160 ms = 0; 00161 } 00162 ast_mutex_unlock(&con->lock); 00163 00164 return ms; 00165 }
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 380 of file sched.c.
References AST_LIST_TRAVERSE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), DEBUG, sched_context::lock, LOG_DEBUG, and s.
Referenced by _sip_show_peer(), handle_cli_status(), and parse_register_contact().
00381 { 00382 struct sched *s; 00383 long secs = -1; 00384 DEBUG(ast_log(LOG_DEBUG, "ast_sched_when()\n")); 00385 00386 ast_mutex_lock(&con->lock); 00387 AST_LIST_TRAVERSE(&con->schedq, s, list) { 00388 if (s->id == id) 00389 break; 00390 } 00391 if (s) { 00392 struct timeval now = ast_tvnow(); 00393 secs = s->when.tv_sec - now.tv_sec; 00394 } 00395 ast_mutex_unlock(&con->lock); 00396 00397 return secs; 00398 }
struct sched_context* sched_context_create | ( | void | ) |
New schedule context.
Definition at line 75 of file sched.c.
References ast_calloc, and ast_mutex_init().
Referenced by ast_cdr_engine_init(), ast_channel_alloc(), dnsmgr_init(), load_module(), and misdn_tasks_init().
00076 { 00077 struct sched_context *tmp; 00078 00079 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) 00080 return NULL; 00081 00082 ast_mutex_init(&tmp->lock); 00083 tmp->eventcnt = 1; 00084 00085 return tmp; 00086 }
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 88 of file sched.c.
References AST_LIST_REMOVE_HEAD, ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), free, sched_context::lock, and s.
Referenced by __unload_module(), ast_channel_alloc(), ast_channel_free(), ast_hangup(), load_module(), misdn_tasks_destroy(), and unload_module().
00089 { 00090 struct sched *s; 00091 00092 ast_mutex_lock(&con->lock); 00093 00094 #ifdef SCHED_MAX_CACHE 00095 /* Eliminate the cache */ 00096 while ((s = AST_LIST_REMOVE_HEAD(&con->schedc, list))) 00097 free(s); 00098 #endif 00099 00100 /* And the queue */ 00101 while ((s = AST_LIST_REMOVE_HEAD(&con->schedq, list))) 00102 free(s); 00103 00104 /* And the context */ 00105 ast_mutex_unlock(&con->lock); 00106 ast_mutex_destroy(&con->lock); 00107 free(con); 00108 }