[asterisk-commits] russell: trunk r299091 - in /trunk: channels/ channels/sip/ channels/sip/incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Dec 20 17:16:00 UTC 2010
Author: russell
Date: Mon Dec 20 11:15:54 2010
New Revision: 299091
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299091
Log:
Some scheduler API cleanup and improvements.
Previously, I had added the ast_sched_thread stuff that was a generic scheduler
thread implementation. However, if you used it, it required using different
functions for modifying scheduler contents. This patch reworks how this is
done and just allows you to optionally start a thread on the original scheduler
context structure that has always been there. This makes it trivial to switch
to the generic scheduler thread implementation without having to touch any of
the other code that adds or removes scheduler entries.
In passing, I made some naming tweaks to add ast_ prefixes where they were not
there before.
Review: https://reviewboard.asterisk.org/r/1007/
Modified:
trunk/channels/chan_gtalk.c
trunk/channels/chan_h323.c
trunk/channels/chan_iax2.c
trunk/channels/chan_jingle.c
trunk/channels/chan_mgcp.c
trunk/channels/chan_sip.c
trunk/channels/chan_skinny.c
trunk/channels/chan_unistim.c
trunk/channels/sip/dialplan_functions.c
trunk/channels/sip/include/globals.h
trunk/include/asterisk.h
trunk/include/asterisk/channel.h
trunk/include/asterisk/rtp_engine.h
trunk/include/asterisk/sched.h
trunk/include/asterisk/udptl.h
trunk/main/ccss.c
trunk/main/cdr.c
trunk/main/channel.c
trunk/main/dnsmgr.c
trunk/main/rtp_engine.c
trunk/main/sched.c
trunk/main/udptl.c
trunk/pbx/pbx_dundi.c
trunk/res/res_calendar.c
trunk/res/res_rtp_asterisk.c
trunk/res/res_rtp_multicast.c
trunk/res/res_stun_monitor.c
trunk/tests/test_sched.c
Modified: trunk/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_gtalk.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_gtalk.c (original)
+++ trunk/channels/chan_gtalk.c Mon Dec 20 11:15:54 2010
@@ -226,7 +226,7 @@
static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */
-static struct sched_context *sched; /*!< The scheduling context */
+static struct ast_sched_context *sched; /*!< The scheduling context */
static struct io_context *io; /*!< The IO context */
static struct in_addr __ourip;
@@ -2248,7 +2248,7 @@
return 0;
}
- sched = sched_context_create();
+ sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_WARNING, "Unable to create schedule context\n");
}
Modified: trunk/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_h323.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Mon Dec 20 11:15:54 2010
@@ -205,7 +205,7 @@
} aliasl;
/* Asterisk RTP stuff */
-static struct sched_context *sched;
+static struct ast_sched_context *sched;
static struct io_context *io;
AST_MUTEX_DEFINE_STATIC(iflock); /*!< Protect the interface list (oh323_pvt) */
@@ -3261,7 +3261,7 @@
int res;
h323debug = 0;
- sched = sched_context_create();
+ sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_WARNING, "Unable to create schedule context\n");
return AST_MODULE_LOAD_FAILURE;
@@ -3282,7 +3282,7 @@
ast_cli_unregister(&cli_h323_reload);
io_context_destroy(io);
io = NULL;
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
sched = NULL;
ASTOBJ_CONTAINER_DESTROY(&userl);
ASTOBJ_CONTAINER_DESTROY(&peerl);
@@ -3295,7 +3295,7 @@
ast_cli_unregister(&cli_h323_reload);
h323_end_process();
io_context_destroy(io);
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
ASTOBJ_CONTAINER_DESTROY(&userl);
@@ -3334,7 +3334,7 @@
ast_cli_unregister(&cli_h323_reload);
h323_end_process();
io_context_destroy(io);
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
ASTOBJ_CONTAINER_DESTROY(&userl);
@@ -3421,7 +3421,7 @@
if (io)
io_context_destroy(io);
if (sched)
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
ASTOBJ_CONTAINER_DESTROY(&userl);
Modified: trunk/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Mon Dec 20 11:15:54 2010
@@ -356,8 +356,8 @@
ast_log(LOG_NOTICE, msg " IAX_COMMAND_RTKEY to rotate key to '%s'\n", digest); \
} while(0)
-static struct io_context *io;
-static struct ast_sched_thread *sched;
+static struct io_context *io;
+static struct ast_sched_context *sched;
#define DONT_RESCHEDULE -2
@@ -1183,7 +1183,7 @@
static int iax2_queryoption(struct ast_channel *c, int option, void *data, int *datalen);
static int iax2_transfer(struct ast_channel *c, const char *dest);
static int iax2_write(struct ast_channel *c, struct ast_frame *f);
-static int iax2_sched_add(struct ast_sched_thread *st, int when, ast_sched_cb callback, const void *data);
+static int iax2_sched_add(struct ast_sched_context *sched, int when, ast_sched_cb callback, const void *data);
static int send_trunk(struct iax2_trunk_peer *tpeer, struct timeval *now);
static int send_command(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int, int);
@@ -1487,18 +1487,16 @@
#define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__)
#endif
-static int iax2_sched_replace(int id, struct ast_sched_thread *st, int when,
+static int iax2_sched_replace(int id, struct ast_sched_context *con, int when,
ast_sched_cb callback, const void *data)
{
- ast_sched_thread_del(st, id);
-
- return ast_sched_thread_add(st, when, callback, data);
-}
-
-static int iax2_sched_add(struct ast_sched_thread *st, int when,
+ return ast_sched_replace(id, con, when, callback, data);
+}
+
+static int iax2_sched_add(struct ast_sched_context *con, int when,
ast_sched_cb callback, const void *data)
{
- return ast_sched_thread_add(st, when, callback, data);
+ return ast_sched_add(con, when, callback, data);
}
static int send_ping(const void *data);
@@ -1787,20 +1785,20 @@
ast_clear_flag64(pvt, IAX_MAXAUTHREQ);
}
/* No more pings or lagrq's */
- AST_SCHED_DEL_SPINLOCK(ast_sched_thread_get_context(sched), pvt->pingid, &iaxsl[pvt->callno]);
+ AST_SCHED_DEL_SPINLOCK(sched, pvt->pingid, &iaxsl[pvt->callno]);
pvt->pingid = DONT_RESCHEDULE;
- AST_SCHED_DEL_SPINLOCK(ast_sched_thread_get_context(sched), pvt->lagid, &iaxsl[pvt->callno]);
+ AST_SCHED_DEL_SPINLOCK(sched, pvt->lagid, &iaxsl[pvt->callno]);
pvt->lagid = DONT_RESCHEDULE;
- ast_sched_thread_del(sched, pvt->autoid);
- ast_sched_thread_del(sched, pvt->authid);
- ast_sched_thread_del(sched, pvt->initid);
- ast_sched_thread_del(sched, pvt->jbid);
- ast_sched_thread_del(sched, pvt->keyrotateid);
+ AST_SCHED_DEL(sched, pvt->autoid);
+ AST_SCHED_DEL(sched, pvt->authid);
+ AST_SCHED_DEL(sched, pvt->initid);
+ AST_SCHED_DEL(sched, pvt->jbid);
+ AST_SCHED_DEL(sched, pvt->keyrotateid);
}
static void iax2_frame_free(struct iax_frame *fr)
{
- ast_sched_thread_del(sched, fr->retrans);
+ AST_SCHED_DEL(sched, fr->retrans);
iax_frame_free(fr);
}
@@ -2058,8 +2056,8 @@
* \note We delete these before switching the slot, because if
* they fire in the meantime, they will generate a warning.
*/
- ast_sched_thread_del(sched, iaxs[callno]->pingid);
- ast_sched_thread_del(sched, iaxs[callno]->lagid);
+ AST_SCHED_DEL(sched, iaxs[callno]->pingid);
+ AST_SCHED_DEL(sched, iaxs[callno]->lagid);
iaxs[callno]->lagid = iaxs[callno]->pingid = -1;
iaxs[x] = iaxs[callno];
iaxs[x]->callno = x;
@@ -4194,7 +4192,7 @@
jb_reset(iaxs[fr->callno]->jb);
- ast_sched_thread_del(sched, iaxs[fr->callno]->jbid);
+ AST_SCHED_DEL(sched, iaxs[fr->callno]->jbid);
/* deliver this frame now */
if (tsout)
@@ -4389,7 +4387,7 @@
ast_copy_flags64(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
if (ast_test_flag64(peer, IAX_RTAUTOCLEAR)) {
if (peer->expire > -1) {
- if (!ast_sched_thread_del(sched, peer->expire)) {
+ if (!AST_SCHED_DEL(sched, peer->expire)) {
peer->expire = -1;
peer_unref(peer);
}
@@ -5217,7 +5215,7 @@
ast_debug(1, "Really destroying %s now...\n", c->name);
iax2_destroy(callno);
} else if (iaxs[callno]) {
- if (ast_sched_thread_add(sched, 10000, scheduled_destroy, CALLNO_TO_PTR(callno)) < 0) {
+ if (ast_sched_add(sched, 10000, scheduled_destroy, CALLNO_TO_PTR(callno)) < 0) {
ast_log(LOG_ERROR, "Unable to schedule iax2 callno %d destruction?!! Destroying immediately.\n", callno);
iax2_destroy(callno);
}
@@ -5348,12 +5346,11 @@
struct MD5Context md5;
char key[17] = "";
struct iax_ie_data ied = {
- .pos = 0,
+ .pos = 0,
};
-
+
ast_mutex_lock(&iaxsl[pvt->callno]);
- pvt->keyrotateid =
- ast_sched_thread_add(sched, 120000 + (ast_random() % 180001), iax2_key_rotate, vpvt);
+ pvt->keyrotateid = ast_sched_add(sched, 120000 + (ast_random() % 180001), iax2_key_rotate, vpvt);
snprintf(key, sizeof(key), "%lX", ast_random());
@@ -8543,14 +8540,14 @@
static void unlink_peer(struct iax2_peer *peer)
{
if (peer->expire > -1) {
- if (!ast_sched_thread_del(sched, peer->expire)) {
+ if (!AST_SCHED_DEL(sched, peer->expire)) {
peer->expire = -1;
peer_unref(peer);
}
}
if (peer->pokeexpire > -1) {
- if (!ast_sched_thread_del(sched, peer->pokeexpire)) {
+ if (!AST_SCHED_DEL(sched, peer->pokeexpire)) {
peer->pokeexpire = -1;
peer_unref(peer);
}
@@ -8629,7 +8626,7 @@
iax2_poke_peer(p, 0);
if (p->expire > -1) {
- if (!ast_sched_thread_del(sched, p->expire)) {
+ if (!AST_SCHED_DEL(sched, p->expire)) {
p->expire = -1;
peer_unref(p);
}
@@ -8741,7 +8738,7 @@
p->sockfd = fd;
/* Setup the expiry */
if (p->expire > -1) {
- if (!ast_sched_thread_del(sched, p->expire)) {
+ if (!AST_SCHED_DEL(sched, p->expire)) {
p->expire = -1;
peer_unref(p);
}
@@ -10297,7 +10294,7 @@
}
}
if (f.frametype == AST_FRAME_IAX) {
- ast_sched_thread_del(sched, iaxs[fr->callno]->initid);
+ AST_SCHED_DEL(sched, iaxs[fr->callno]->initid);
/* Handle the IAX pseudo frame itself */
if (iaxdebug)
ast_debug(1, "IAX subclass %d received\n", f.subclass.integer);
@@ -10823,7 +10820,7 @@
/* Remove scheduled iax2_poke_noanswer */
if (peer->pokeexpire > -1) {
- if (!ast_sched_thread_del(sched, peer->pokeexpire)) {
+ if (!AST_SCHED_DEL(sched, peer->pokeexpire)) {
peer_unref(peer);
peer->pokeexpire = -1;
}
@@ -11943,22 +11940,22 @@
iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
iaxs[peer->callno]->peerpoke = peer;
- if (peer->pokeexpire > -1) {
- if (!ast_sched_thread_del(sched, peer->pokeexpire)) {
- peer->pokeexpire = -1;
- peer_unref(peer);
- }
- }
-
+ if (peer->pokeexpire > -1) {
+ if (!AST_SCHED_DEL(sched, peer->pokeexpire)) {
+ peer->pokeexpire = -1;
+ peer_unref(peer);
+ }
+ }
+
/* Queue up a new task to handle no reply */
/* If the host is already unreachable then use the unreachable interval instead */
if (peer->lastms < 0)
- peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer_ref(peer));
+ peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer_ref(peer));
else
- peer->pokeexpire = iax2_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer_ref(peer));
-
- if (peer->pokeexpire == -1)
- peer_unref(peer);
+ peer->pokeexpire = iax2_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer_ref(peer));
+
+ if (peer->pokeexpire == -1)
+ peer_unref(peer);
/* And send the poke */
ast_mutex_lock(&iaxsl[callno]);
@@ -12391,7 +12388,7 @@
}
} else {
/* Non-dynamic. Make sure we become that way if we're not */
- ast_sched_thread_del(sched, peer->expire);
+ AST_SCHED_DEL(sched, peer->expire);
ast_clear_flag64(peer, IAX_DYNAMIC);
if (ast_dnsmgr_lookup(v->value, &peer->addr, &peer->dnsmgr, srvlookup ? "_iax._udp" : NULL))
return peer_unref(peer);
@@ -12835,7 +12832,7 @@
AST_LIST_LOCK(®istrations);
while ((reg = AST_LIST_REMOVE_HEAD(®istrations, entry))) {
if (sched) {
- ast_sched_thread_del(sched, reg->expire);
+ AST_SCHED_DEL(sched, reg->expire);
}
if (reg->callno) {
int callno = reg->callno;
@@ -14269,7 +14266,8 @@
ast_timer_close(timer);
}
transmit_processor = ast_taskprocessor_unreference(transmit_processor);
- sched = ast_sched_thread_destroy(sched);
+ ast_sched_context_destroy(sched);
+ sched = NULL;
con = ast_context_find(regcontext);
if (con)
@@ -14588,21 +14586,29 @@
ast_mutex_init(&iaxsl[x]);
}
- if (!(sched = ast_sched_thread_create())) {
+ if (!(sched = ast_sched_context_create())) {
ast_log(LOG_ERROR, "Failed to create scheduler thread\n");
return AST_MODULE_LOAD_FAILURE;
}
+ if (ast_sched_start_thread(sched)) {
+ ast_sched_context_destroy(sched);
+ sched = NULL;
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
if (!(io = io_context_create())) {
ast_log(LOG_ERROR, "Failed to create I/O context\n");
- sched = ast_sched_thread_destroy(sched);
+ ast_sched_context_destroy(sched);
+ sched = NULL;
return AST_MODULE_LOAD_FAILURE;
}
if (!(netsock = ast_netsock_list_alloc())) {
ast_log(LOG_ERROR, "Failed to create netsock list\n");
io_context_destroy(io);
- sched = ast_sched_thread_destroy(sched);
+ ast_sched_context_destroy(sched);
+ sched = NULL;
return AST_MODULE_LOAD_FAILURE;
}
ast_netsock_init(netsock);
@@ -14611,7 +14617,8 @@
if (!outsock) {
ast_log(LOG_ERROR, "Could not allocate outsock list.\n");
io_context_destroy(io);
- sched = ast_sched_thread_destroy(sched);
+ ast_sched_context_destroy(sched);
+ sched = NULL;
return AST_MODULE_LOAD_FAILURE;
}
ast_netsock_init(outsock);
Modified: trunk/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_jingle.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_jingle.c (original)
+++ trunk/channels/chan_jingle.c Mon Dec 20 11:15:54 2010
@@ -210,7 +210,7 @@
static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */
-static struct sched_context *sched; /*!< The scheduling context */
+static struct ast_sched_context *sched; /*!< The scheduling context */
static struct io_context *io; /*!< The IO context */
static struct in_addr __ourip;
@@ -1903,7 +1903,7 @@
return AST_MODULE_LOAD_DECLINE;
}
- sched = sched_context_create();
+ sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_WARNING, "Unable to create schedule context\n");
}
Modified: trunk/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Mon Dec 20 11:15:54 2010
@@ -231,7 +231,7 @@
static int mgcpdebug = 0;
-static struct sched_context *sched;
+static struct ast_sched_context *sched;
static struct io_context *io;
/*! The private structures of the mgcp channels are linked for
* selecting outgoing channels
@@ -4776,14 +4776,14 @@
/*! \brief load_module: PBX load module - initialization ---*/
static int load_module(void)
{
- if (!(sched = sched_context_create())) {
+ if (!(sched = ast_sched_context_create())) {
ast_log(LOG_WARNING, "Unable to create schedule context\n");
return AST_MODULE_LOAD_FAILURE;
}
if (!(io = io_context_create())) {
ast_log(LOG_WARNING, "Unable to create I/O context\n");
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
return AST_MODULE_LOAD_FAILURE;
}
@@ -4794,7 +4794,7 @@
if (ast_channel_register(&mgcp_tech)) {
ast_log(LOG_ERROR, "Unable to register channel class 'MGCP'\n");
io_context_destroy(io);
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
return AST_MODULE_LOAD_FAILURE;
}
@@ -4905,7 +4905,7 @@
close(mgcpsock);
ast_rtp_glue_unregister(&mgcp_rtp_glue);
ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
return 0;
}
Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Mon Dec 20 11:15:54 2010
@@ -782,7 +782,7 @@
static int sip_reloading = FALSE; /*!< Flag for avoiding multiple reloads at the same time */
static enum channelreloadreason sip_reloadreason; /*!< Reason for last reload/load of configuration */
-struct sched_context *sched; /*!< The scheduling context */
+struct ast_sched_context *sched; /*!< The scheduling context */
static struct io_context *io; /*!< The IO context */
static int *sipsock_read_id; /*!< ID of IO entry for sipsock FD */
struct sip_pkt;
@@ -28901,14 +28901,14 @@
ASTOBJ_CONTAINER_INIT(®l); /* Registry object list -- not searched for anything */
ASTOBJ_CONTAINER_INIT(&submwil); /* MWI subscription object list */
- if (!(sched = sched_context_create())) {
+ if (!(sched = ast_sched_context_create())) {
ast_log(LOG_ERROR, "Unable to create scheduler context\n");
return AST_MODULE_LOAD_FAILURE;
}
if (!(io = io_context_create())) {
ast_log(LOG_ERROR, "Unable to create I/O context\n");
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
return AST_MODULE_LOAD_FAILURE;
}
@@ -28930,7 +28930,7 @@
if (ast_channel_register(&sip_tech)) {
ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
io_context_destroy(io);
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
return AST_MODULE_LOAD_FAILURE;
}
@@ -29151,7 +29151,7 @@
clear_sip_domains();
ast_free_ha(sip_cfg.contact_ha);
close(sipsock);
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
con = ast_context_find(used_context);
if (con) {
ast_context_destroy(con, "SIP");
Modified: trunk/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Mon Dec 20 11:15:54 2010
@@ -1151,7 +1151,7 @@
#endif
/* driver scheduler */
-static struct sched_context *sched = NULL;
+static struct ast_sched_context *sched = NULL;
static struct io_context *io;
/* Protect the monitoring thread, so only one process can kill or start it, and not
@@ -7368,7 +7368,7 @@
ast_manager_register_xml("SKINNYlines", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_skinny_show_lines);
ast_manager_register_xml("SKINNYshowline", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_skinny_show_line);
- sched = sched_context_create();
+ sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_WARNING, "Unable to create schedule context\n");
}
@@ -7449,8 +7449,9 @@
ast_mutex_unlock(&netlock);
close(skinnysock);
- if (sched)
- sched_context_destroy(sched);
+ if (sched) {
+ ast_sched_context_destroy(sched);
+ }
con = ast_context_find(used_context);
if (con)
Modified: trunk/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_unistim.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/chan_unistim.c (original)
+++ trunk/channels/chan_unistim.c Mon Dec 20 11:15:54 2010
@@ -217,7 +217,7 @@
} qos = { 0, 0, 0, 0 };
static struct io_context *io;
-static struct sched_context *sched;
+static struct ast_sched_context *sched;
static struct sockaddr_in public_ip = { 0, };
/*! give the IP address for the last packet received */
static struct sockaddr_in address_from;
@@ -5645,7 +5645,7 @@
goto io_failed;
}
- sched = sched_context_create();
+ sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_ERROR, "Failed to allocate scheduler context\n");
goto sched_failed;
@@ -5671,7 +5671,7 @@
chanreg_failed:
/*! XXX \todo Leaking anything allocated by reload_config() ... */
- sched_context_destroy(sched);
+ ast_sched_context_destroy(sched);
sched = NULL;
sched_failed:
io_context_destroy(io);
@@ -5686,8 +5686,9 @@
static int unload_module(void)
{
/* First, take us out of the channel loop */
- if (sched)
- sched_context_destroy(sched);
+ if (sched) {
+ ast_sched_context_destroy(sched);
+ }
ast_cli_unregister_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
Modified: trunk/channels/sip/dialplan_functions.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/sip/dialplan_functions.c?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/sip/dialplan_functions.c (original)
+++ trunk/channels/sip/dialplan_functions.c Mon Dec 20 11:15:54 2010
@@ -225,7 +225,7 @@
}
#ifdef TEST_FRAMEWORK
-static int test_sip_rtpqos_1_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *addr, void *data)
+static int test_sip_rtpqos_1_new(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *addr, void *data)
{
/* Needed to pass sanity checks */
ast_rtp_instance_set_data(instance, data);
Modified: trunk/channels/sip/include/globals.h
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/sip/include/globals.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/channels/sip/include/globals.h (original)
+++ trunk/channels/sip/include/globals.h Mon Dec 20 11:15:54 2010
@@ -25,7 +25,7 @@
#define _SIP_GLOBALS_H
extern struct ast_sockaddr bindaddr; /*!< UDP: The address we bind to */
-extern struct sched_context *sched; /*!< The scheduling context */
+extern struct ast_sched_context *sched; /*!< The scheduling context */
/*! \brief Definition of this channel for PBX channel registration */
extern const struct ast_channel_tech sip_tech;
Modified: trunk/include/asterisk.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/include/asterisk.h (original)
+++ trunk/include/asterisk.h Mon Dec 20 11:15:54 2010
@@ -211,6 +211,7 @@
struct ast_module;
struct ast_variable;
struct ast_str;
+struct ast_sched_context;
#ifdef bzero
#undef bzero
Modified: trunk/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Mon Dec 20 11:15:54 2010
@@ -139,7 +139,6 @@
#define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
#include "asterisk/frame.h"
-#include "asterisk/sched.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
@@ -744,7 +743,7 @@
const char *blockproc; /*!< Procedure causing blocking */
const char *appl; /*!< Current application */
const char *data; /*!< Data passed to current application */
- struct sched_context *sched; /*!< Schedule context */
+ struct ast_sched_context *sched; /*!< Schedule context */
struct ast_filestream *stream; /*!< Stream itself. */
struct ast_filestream *vstream; /*!< Video Stream itself. */
int (*timingfunc)(const void *data);
Modified: trunk/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/rtp_engine.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/include/asterisk/rtp_engine.h (original)
+++ trunk/include/asterisk/rtp_engine.h Mon Dec 20 11:15:54 2010
@@ -313,7 +313,7 @@
/*! Module this RTP engine came from, used for reference counting */
struct ast_module *mod;
/*! Callback for setting up a new RTP instance */
- int (*new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *sa, void *data);
+ int (*new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data);
/*! Callback for destroying an RTP instance */
int (*destroy)(struct ast_rtp_instance *instance);
/*! Callback for writing out a frame */
@@ -542,7 +542,7 @@
* \since 1.8
*/
struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
- struct sched_context *sched, const struct ast_sockaddr *sa,
+ struct ast_sched_context *sched, const struct ast_sockaddr *sa,
void *data);
/*!
Modified: trunk/include/asterisk/sched.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/sched.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/include/asterisk/sched.h (original)
+++ trunk/include/asterisk/sched.h Mon Dec 20 11:15:54 2010
@@ -1,9 +1,10 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 1999 - 2010, Digium, Inc.
*
* Mark Spencer <markster at digium.com>
+ * Russell Bryant <russell at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -27,16 +28,10 @@
extern "C" {
#endif
-
-/*! \brief Max num of schedule structs
- * \note The max number of schedule structs to keep around
- * for use. Undefine to disable schedule structure
- * caching. (Only disable this on very low memory
- * machines)
- */
-#define SCHED_MAX_CACHE 128
-
-/*! \brief a loop construct to ensure that
+/*!
+ * \brief Remove a scheduler entry
+ *
+ * This is 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
@@ -137,25 +132,27 @@
#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)
-struct sched_context;
-
-/*! \brief New schedule context
- * \note Create a scheduling context
+/*!
+ * \brief Create a scheduler context
+ *
* \return Returns a malloc'd sched_context structure, NULL on failure
*/
-struct sched_context *sched_context_create(void);
-
-/*! \brief destroys a schedule context
- * Destroys (free's) the given sched_context structure
+struct ast_sched_context *ast_sched_context_create(void);
+
+/*!
+ * \brief destroys a schedule context
+ *
* \param c Context to free
- * \return Returns 0 on success, -1 on failure
- */
-void sched_context_destroy(struct sched_context *c);
-
-/*! \brief callback for a cheops scheduler
- * A cheops scheduler callback takes a pointer with callback data and
- * \return returns a 0 if it should not be run again, or non-zero if it should be
- * rescheduled to run again
+ */
+void ast_sched_context_destroy(struct ast_sched_context *c);
+
+/*!
+ * \brief scheduler callback
+ *
+ * A scheduler callback takes a pointer with callback data and
+ *
+ * \retval 0 if the callback should not be rescheduled
+ * \retval non-zero if the callback should be scheduled agai
*/
typedef int (*ast_sched_cb)(const void *data);
#define AST_SCHED_CB(a) ((ast_sched_cb)(a))
@@ -173,20 +170,25 @@
* \param cbnames to check against
* \since 1.6.1
*/
-void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames);
-
-/*! \brief Adds a scheduled event
+void ast_sched_report(struct ast_sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames);
+
+/*!
+ * \brief 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
+ *
* \param con Scheduler context to add
* \param when how many milliseconds to wait for event to occur
* \param callback function to call when the amount of time expires
* \param data data to pass to the callback
+ *
* \return Returns a schedule item ID on success, -1 on failure
*/
-int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
+int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
/*!
* \brief replace a scheduler entry
@@ -199,22 +201,27 @@
* \retval -1 failure
* \retval otherwise, returns scheduled item ID
*/
-int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
-
-/*!Adds a scheduled event with rescheduling support
+int ast_sched_replace(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
+
+/*!
+ * \brief Adds a scheduled event with rescheduling support
+ *
* \param con Scheduler context to add
* \param when how many milliseconds to wait for event to occur
* \param callback function to call when the amount of time expires
* \param data data to pass to the callback
* \param 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
+ *
* \return Returns a schedule item ID on success, -1 on failure
*/
-int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result;
+int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result;
/*!
* \brief replace a scheduler entry
@@ -227,66 +234,83 @@
* \retval -1 failure
* \retval otherwise, returns scheduled item ID
*/
-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;
-
-
+int ast_sched_replace_variable(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result;
+
/*!
* \brief Find a sched structure and return the data field associated with it.
+ *
* \param con scheduling context in which to search fro the matching id
* \param id ID of the scheduled item to find
* \return the data field from the matching sched struct if found; else return NULL if not found.
- * \since 1.6.1
- */
-
-const void *ast_sched_find_data(struct sched_context *con, int id);
-
-/*! \brief Deletes a scheduled event
+ *
+ * \since 1.6.1
+ */
+const void *ast_sched_find_data(struct ast_sched_context *con, int id);
+
+/*!
+ * \brief 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).
+ *
* \param con scheduling context to delete item from
* \param id ID of the scheduled item to delete
+ *
* \return Returns 0 on success, -1 on failure
*/
#ifndef AST_DEVMODE
-int ast_sched_del(struct sched_context *con, int id) attribute_warn_unused_result;
+int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result;
#else
-int _ast_sched_del(struct sched_context *con, int id, const char *file, int line, const char *function) attribute_warn_unused_result;
+int _ast_sched_del(struct ast_sched_context *con, int id, const char *file, int line, const char *function) attribute_warn_unused_result;
#define ast_sched_del(a, b) _ast_sched_del(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#endif
-/*! \brief Determines number of seconds until the next outstanding event to take place
+/*!
+ * \brief 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.
+ *
* \param con context to act upon
+ *
* \return Returns "-1" if there is nothing there are no scheduled events
* (and thus the poll should not timeout)
*/
-int ast_sched_wait(struct sched_context *con) attribute_warn_unused_result;
-
-/*! \brief Runs the queue
- * \param con Scheduling context to run
+int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result;
+
+/*!
+ * \brief Runs the queue
+ *
* Run the queue, executing all callbacks which need to be performed
* at this time.
+ *
+ * \param con Scheduling context to run
* \param con context to act upon
+ *
* \return Returns the number of events processed.
*/
-int ast_sched_runq(struct sched_context *con);
-
-/*! \brief Dumps the scheduler contents
+int ast_sched_runq(struct ast_sched_context *con);
+
+/*!
+ * \brief Dumps the scheduler contents
+ *
* Debugging: Dump the contents of the scheduler to stderr
+ *
* \param con Context to dump
*/
-void ast_sched_dump(struct sched_context *con);
-
-/*! \brief Returns the number of seconds before an event takes place
+void ast_sched_dump(struct ast_sched_context *con);
+
+/*!
+ * \brief Returns the number of seconds before an event takes place
+ *
* \param con Context to use
* \param id Id to dump
*/
-long ast_sched_when(struct sched_context *con,int id);
+long ast_sched_when(struct ast_sched_context *con,int id);
/*!
* \brief Convenience macro for objects and reference (add)
@@ -307,112 +331,14 @@
} while(0)
/*!
- * \brief An opaque type representing a scheduler thread
- *
- * The purpose of the ast_sched_thread API is to provide a common implementation
- * of the case where a module wants to have a dedicated thread for handling the
- * scheduler.
- */
-struct ast_sched_thread;
-
-/*!
- * \brief Create a scheduler with a dedicated thread
- *
- * This function should be used to allocate a scheduler context and a dedicated
- * thread for processing scheduler entries. The thread is started immediately.
- *
- * \retval NULL error
- * \retval non-NULL a handle to the scheduler and its dedicated thread.
- */
-struct ast_sched_thread *ast_sched_thread_create(void);
-
-/*!
- * \brief Destroy a scheduler and its thread
- *
- * This function is used to destroy a scheduler context and the dedicated thread
- * that was created for handling scheduler entries. Any entries in the scheduler
- * that have not yet been processed will be thrown away. Once this function is
- * called, the handle must not be used again.
- *
- * \param st the handle to the scheduler and thread
- *
- * \return NULL for convenience
- */
-struct ast_sched_thread *ast_sched_thread_destroy(struct ast_sched_thread *st);
-
-/*!
- * \brief Add a scheduler entry
- *
- * \param st the handle to the scheduler and thread
- * \param when the number of ms in the future to run the task. A value <= 0
- * is treated as "run now".
- * \param cb the function to call when the scheduled time arrives
- * \param data the parameter to pass to the scheduler callback
- *
- * \retval -1 Failure
- * \retval >=0 Sched ID of added task
- */
-int ast_sched_thread_add(struct ast_sched_thread *st, int when, ast_sched_cb cb,
- const void *data);
-
-/*!
- * \brief Add a variable reschedule time scheduler entry
- *
- * \param st the handle to the scheduler and thread
- * \param when the number of ms in the future to run the task. A value <= 0
- * is treated as "run now".
- * \param cb the function to call when the scheduled time arrives
- * \param data the parameter to pass to the scheduler callback
- * \param variable If this value is non-zero, then the scheduler will use the return
- * value of the scheduler as the amount of time in the future to run the
- * task again. Normally, a return value of 0 means do not re-schedule, and
- * non-zero means re-schedule using the time provided when the scheduler
- * entry was first created.
- *
- * \retval -1 Failure
- * \retval >=0 Sched ID of added task
- */
-int ast_sched_thread_add_variable(struct ast_sched_thread *st, int when, ast_sched_cb cb,
- const void *data, int variable);
-
-/*!
- * \brief Get the scheduler context for a given ast_sched_thread
- *
- * This function should be used only when direct access to the scheduler context
- * is required. Its use is discouraged unless necessary. The cases where
- * this is currently required is when you want to take advantage of one of the
- * AST_SCHED macros.
- *
- * \param st the handle to the scheduler and thread
- *
- * \return the sched_context associated with an ast_sched_thread
- */
-struct sched_context *ast_sched_thread_get_context(struct ast_sched_thread *st);
-
-/*!
- * \brief Delete a scheduler entry
- *
- * This uses the AST_SCHED_DEL macro internally.
- *
- * \param st the handle to the scheduler and thread
- * \param id scheduler entry id to delete
+ * \brief Start a thread for processing scheduler entries
+ *
+ * \param con the scheduler context this thread will manage
*
* \retval 0 success
* \retval non-zero failure
*/
-#define ast_sched_thread_del(st, id) ({ \
- struct sched_context *__tmp_context = ast_sched_thread_get_context(st); \
- AST_SCHED_DEL(__tmp_context, id); \
-})
-
-/*!
- * \brief Force re-processing of the scheduler context
- *
- * \param st the handle to the scheduler and thread
- *
- * \return nothing
- */
-void ast_sched_thread_poke(struct ast_sched_thread *st);
+int ast_sched_start_thread(struct ast_sched_context *con);
#if defined(__cplusplus) || defined(c_plusplus)
}
Modified: trunk/include/asterisk/udptl.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/udptl.h?view=diff&rev=299091&r1=299090&r2=299091
==============================================================================
--- trunk/include/asterisk/udptl.h (original)
+++ trunk/include/asterisk/udptl.h Mon Dec 20 11:15:54 2010
@@ -57,7 +57,7 @@
typedef int (*ast_udptl_callback)(struct ast_udptl *udptl, struct ast_frame *f, void *data);
-struct ast_udptl *ast_udptl_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *in);
[... 963 lines stripped ...]
More information about the asterisk-commits
mailing list