[asterisk-commits] tilghman: trunk r100497 - in /trunk: channels/ include/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jan 27 17:14:49 CST 2008


Author: tilghman
Date: Sun Jan 27 17:14:48 2008
New Revision: 100497

URL: http://svn.digium.com/view/asterisk?view=rev&rev=100497
Log:
With the switch to the ast_sched_replace* API in trunk, we lose the correction
that was just merged from 1.4, so this is a changeover to those APIs to use the
macro versions, so that we properly detect errors from ast_sched_del, instead
of simply ignoring the return values.

Modified:
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/include/asterisk/sched.h

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=100497&r1=100496&r2=100497
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Sun Jan 27 17:14:48 2008
@@ -1094,14 +1094,12 @@
 #define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__)
 #endif
 
-static int iax2_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data)
-{
-	int res;
-
-	res = ast_sched_replace(old_id, con, when, callback, data);
+static int iax2_sched_replace(int id, struct sched_context *con, int when, ast_sched_cb callback, const void *data)
+{
+	AST_SCHED_REPLACE(id, con, when, callback, data);
 	signal_condition(&sched_lock, &sched_cond);
 
-	return res;
+	return id;
 }
 
 static int iax2_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data)

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=100497&r1=100496&r2=100497
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sun Jan 27 17:14:48 2008
@@ -2810,8 +2810,7 @@
 		siptimer_a = pkt->timer_t1 * 2;
 
 	/* Schedule retransmission */
-	pkt->retransid = ast_sched_replace_variable(pkt->retransid, sched, 
-		siptimer_a, retrans_pkt, pkt, 1);
+	AST_SCHED_REPLACE_VARIABLE(pkt->retransid, sched, siptimer_a, retrans_pkt, pkt, 1);
 	if (sipdebug)
 		ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id  #%d\n", pkt->retransid);
 
@@ -3627,8 +3626,7 @@
 		/* Cache peer */
 		ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
 		if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
-			peer->expire = ast_sched_replace(peer->expire, sched, 
-				global_rtautoclear * 1000, expire_register, (void *) peer);
+			AST_SCHED_REPLACE(peer->expire, sched, global_rtautoclear * 1000, expire_register, (void *) peer);
 		}
 		ASTOBJ_CONTAINER_LINK(&peerl,peer);
 	} else {
@@ -4085,8 +4083,7 @@
 		p->invitestate = INV_CALLING;
 	
 		/* Initialize auto-congest time */
-		p->initid = ast_sched_replace(p->initid, sched, p->timer_b, 
-			auto_congest, dialog_ref(p));
+		AST_SCHED_REPLACE(p->initid, sched, p->timer_b, auto_congest, dialog_ref(p));
 	}
 
 	return res;
@@ -8979,8 +8976,7 @@
 			 * probably DNS.  We need to reschedule a registration try */
 			sip_destroy(p);
 			if (r->timeout > -1) {
-				r->timeout = ast_sched_replace(r->timeout, sched, 
-					global_reg_timeout * 1000, sip_reg_timeout, r);
+				AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
 				ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
 			} else {
 				r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r);
@@ -9035,7 +9031,7 @@
 	if (auth == NULL)  {
 		if (r->timeout > -1)
 			ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout);
-		r->timeout = ast_sched_replace(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
+		AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
 		ast_debug(1, "Scheduled a registration timeout for %s id  #%d \n", r->hostname, r->timeout);
 	}
 
@@ -9414,12 +9410,10 @@
 	peer->addr.sin_port = htons(port);
 	if (sipsock < 0) {
 		/* SIP isn't up yet, so schedule a poke only, pretty soon */
-		peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, 
-			ast_random() % 5000 + 1, sip_poke_peer_s, peer);
+		AST_SCHED_REPLACE(peer->pokeexpire, sched, ast_random() % 5000 + 1, sip_poke_peer_s, peer);
 	} else
 		sip_poke_peer(peer);
-	peer->expire = ast_sched_replace(peer->expire, sched, 
-		(expiry + 10) * 1000, expire_register, peer);
+	AST_SCHED_REPLACE(peer->expire, sched, (expiry + 10) * 1000, expire_register, peer);
 	register_peer_exten(peer, TRUE);
 }
 
@@ -14776,7 +14770,7 @@
 		r->refresh= (int) expires_ms / 1000;
 
 		/* Schedule re-registration before we expire */
-		r->expire = ast_sched_replace(r->expire, sched, expires_ms, sip_reregister, r); 
+		AST_SCHED_REPLACE(r->expire, sched, expires_ms, sip_reregister, r); 
 		registry_unref(r);
 	}
 	return 1;
@@ -14824,7 +14818,7 @@
 	p->needdestroy = 1;
 
 	/* Try again eventually */
-	peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched,
+	AST_SCHED_REPLACE(peer->pokeexpire, sched,
 		is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK,
 		sip_poke_peer_s, peer);
 }
@@ -18545,7 +18539,7 @@
 	peer->lastms = -1;
 	ast_device_state_changed("SIP/%s", peer->name);
 	/* Try again quickly */
-	peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, 
+	AST_SCHED_REPLACE(peer->pokeexpire, sched, 
 		DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
 	return 0;
 }
@@ -18607,7 +18601,7 @@
 	if (xmitres == XMIT_ERROR)
 		sip_poke_noanswer(peer);	/* Immediately unreachable, network problems */
 	else {
-		peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, 
+		AST_SCHED_REPLACE(peer->pokeexpire, sched, 
 			peer->maxms * 2, sip_poke_noanswer, peer);
 	}
 
@@ -20964,8 +20958,7 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
 		ASTOBJ_WRLOCK(iterator);
 		ms += 100;
-		iterator->pokeexpire = ast_sched_replace(iterator->pokeexpire, 
-			sched, ms, sip_poke_peer_s, iterator);
+		AST_SCHED_REPLACE(iterator->pokeexpire, sched, ms, sip_poke_peer_s, iterator);
 		ASTOBJ_UNLOCK(iterator);
 	} while (0)
 	);
@@ -20985,7 +20978,7 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
 		ASTOBJ_WRLOCK(iterator);
 		ms += regspacing;
-		iterator->expire = ast_sched_replace(iterator->expire, 
+		AST_SCHED_REPLACE(iterator->expire, 
 			sched, ms, sip_reregister, iterator);
 		ASTOBJ_UNLOCK(iterator);
 	} while (0)

Modified: trunk/include/asterisk/sched.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/sched.h?view=diff&rev=100497&r1=100496&r2=100497
==============================================================================
--- trunk/include/asterisk/sched.h (original)
+++ trunk/include/asterisk/sched.h Sun Jan 27 17:14:48 2008
@@ -44,6 +44,19 @@
 			ast_log(LOG_WARNING, "Unable to cancel schedule ID %d.  This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
 		id = -1; \
 	} while (0);
+
+#define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \
+	do { \
+		int _count = 0; \
+		while (id > -1 && ast_sched_del(sched, id) && _count++ < 10) \
+			usleep(1); \
+		if (_count == 10) \
+			ast_log(LOG_WARNING, "Unable to cancel schedule ID %d.  This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
+		id = ast_sched_add_variable(sched, when, callback, data, variable); \
+	} while (0);
+
+#define AST_SCHED_REPLACE(id, sched, when, callback, data) \
+		AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0)
 
 struct sched_context;
 




More information about the asterisk-commits mailing list