[asterisk-commits] russell: branch russell/sched_thread r140415 - /team/russell/sched_thread/cha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 28 22:15:13 CDT 2008


Author: russell
Date: Thu Aug 28 22:15:13 2008
New Revision: 140415

URL: http://svn.digium.com/view/asterisk?view=rev&rev=140415
Log:
Finish first draft of putting SIP scheduler processing in a dedicated thread.
It runs and hasn't crashed yet, but the only load is just a few registrations.

Modified:
    team/russell/sched_thread/channels/chan_sip.c

Modified: team/russell/sched_thread/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/sched_thread/channels/chan_sip.c?view=diff&rev=140415&r1=140414&r2=140415
==============================================================================
--- team/russell/sched_thread/channels/chan_sip.c (original)
+++ team/russell/sched_thread/channels/chan_sip.c Thu Aug 28 22:15:13 2008
@@ -15756,10 +15756,13 @@
 		r->refresh= (int) expires_ms / 1000;
 		
 		/* Schedule re-registration before we expire */
-		AST_SCHED_REPLACE_UNREF(r->expire, sched, expires_ms, sip_reregister, r, 
-								registry_unref(_data,"unref in REPLACE del fail"), 
-								registry_unref(r,"unref in REPLACE add fail"), 
-								registry_addref(r,"The Addition side of REPLACE")); 
+		if (!sched_thread_del(sched, r->expire)) {
+			registry_unref(r, "");
+		}
+		r->expire = sched_thread_add(sched, expires_ms, sip_reregister, registry_addref(r, ""));
+		if (r->expire == -1) {
+			registry_unref(r, "");
+		}
 		/* it is clear that we would not want to destroy the registry entry if we just
 		   scheduled a callback and recorded it in there! */
 		/* since we never bumped the count, we shouldn't decrement it! registry_unref(r, "unref registry ptr r"); if this gets deleted, p->registry will be a bad pointer! */ 
@@ -15809,9 +15812,8 @@
 	p->needdestroy = 1;
 
 	/* Try again eventually */
-	AST_SCHED_REPLACE(peer->pokeexpire, sched,
-		is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK,
-		sip_poke_peer_s, peer);
+	sched_thread_del(sched, peer->pokeexpire);
+	peer->pokeexpire = sched_thread_add(sched, is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
 	/* unref_peer(peer, "unref relatedpeer ptr var at end of handle_response_peerpoke"); */
 }
 
@@ -17187,7 +17189,7 @@
 			ast_string_field_set(p, theirtag, NULL);
 			for (pkt = p->packets; pkt; pkt = pkt->next) {
 				if (pkt->seqno == p->icseq && pkt->method == SIP_INVITE) {
-					AST_SCHED_DEL(sched, pkt->retransid);
+					sched_thread_del(sched, pkt->retransid);
 				}
 			}
 			return transmit_invite(p, SIP_INVITE, 1, 3);
@@ -19595,6 +19597,7 @@
 
 		pthread_testcancel();
 		/* Wait for sched or io */
+		res = 1000;
 		res = ast_io_wait(io, res);
 		if (res > 20)
 			ast_debug(1, "chan_sip: ast_io_wait ran %d all at once\n", res);
@@ -19641,7 +19644,7 @@
 	}
 
 	if (p->stimer->st_active == TRUE) {
-		AST_SCHED_DEL(sched, p->stimer->st_schedid);
+		sched_thread_del(sched, p->stimer->st_schedid);
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 		start_session_timer(p);
 	}
@@ -19658,7 +19661,7 @@
 
 	if (p->stimer->st_active == TRUE) {
 		p->stimer->st_active = FALSE;
-		AST_SCHED_DEL(sched, p->stimer->st_schedid);
+		sched_thread_del(sched, p->stimer->st_schedid);
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 	}
 }
@@ -19946,8 +19949,8 @@
 	peer->lastms = -1;
 	ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
 	/* Try again quickly */
-	AST_SCHED_REPLACE(peer->pokeexpire, sched, 
-		DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
+	sched_thread_del(sched, peer->pokeexpire);
+	peer->pokeexpire = sched_thread_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
 	return 0;
 }
 
@@ -19964,7 +19967,7 @@
 	if ((!peer->maxms && !force) || !peer->addr.sin_addr.s_addr) {
 		/* IF we have no IP, or this isn't to be monitored, return
 		  immediately after clearing things out */
-		AST_SCHED_DEL(sched, peer->pokeexpire);
+		sched_thread_del(sched, peer->pokeexpire);
 		
 		peer->lastms = 0;
 		if (peer->call) {
@@ -20007,7 +20010,7 @@
 	build_callid_pvt(p);
 	ao2_t_link(dialogs, p, "Linking in under new name");
 
-	AST_SCHED_DEL(sched, peer->pokeexpire);
+	sched_thread_del(sched, peer->pokeexpire);
 	
 	if (p->relatedpeer)
 		p->relatedpeer = unref_peer(p->relatedpeer,"unsetting the relatedpeer field in the dialog, before it is set to something else.");
@@ -20023,7 +20026,10 @@
 	if (xmitres == XMIT_ERROR) {
 		sip_poke_noanswer(peer);	/* Immediately unreachable, network problems */
 	} else if (!force) {
-		AST_SCHED_REPLACE(peer->pokeexpire, sched, peer->maxms * 2, sip_poke_noanswer, peer);
+		if (peer->pokeexpire > -1) {
+			sched_thread_del(sched, peer->pokeexpire);
+		}
+		peer->pokeexpire = sched_thread_add(sched, peer->maxms * 2, sip_poke_noanswer, peer);
 	}
 	dialog_unref(p, "unref dialog at end of sip_poke_peer, obtained from sip_alloc, just before it goes out of scope");
 	return 0;
@@ -20880,7 +20886,7 @@
 				peer->host_dynamic = TRUE;
 			} else {
 				/* Non-dynamic.  Make sure we become that way if we're not */
-				AST_SCHED_DEL(sched, peer->expire);
+				sched_thread_del(sched, peer->expire);
 				peer->host_dynamic = FALSE;
 				srvlookup = v->value;
 			}
@@ -22420,7 +22426,10 @@
 	while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {
 		ao2_lock(peer);
 		ms += 100;
-		AST_SCHED_REPLACE(peer->pokeexpire, sched, ms, sip_poke_peer_s, peer);
+		if (peer->pokeexpire > -1) {
+			sched_thread_del(sched, peer->pokeexpire);
+		}
+		peer->pokeexpire = sched_thread_add(sched, ms, sip_poke_peer_s, peer);
 		ao2_unlock(peer);
 		unref_peer(peer, "toss iterator peer ptr");
 	}
@@ -22440,10 +22449,13 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
 		ASTOBJ_WRLOCK(iterator);
 		ms += regspacing;
-		AST_SCHED_REPLACE_UNREF(iterator->expire, sched, ms, sip_reregister, iterator, 
-								registry_unref(_data, "REPLACE sched del decs the refcount"),
-								registry_unref(iterator, "REPLACE sched add failure decs the refcount"),
-								registry_addref(iterator, "REPLACE sched add incs the refcount"));
+		if (iterator->expire > -1 && !sched_thread_del(sched, iterator->expire)) {
+			registry_unref(iterator, "");
+		}
+		iterator->expire = sched_thread_add(sched, ms, sip_reregister, registry_addref(iterator, ""));
+		if (iterator->expire == -1) {
+			registry_unref(iterator, "");
+		}
 		ASTOBJ_UNLOCK(iterator);
 	} while (0)
 	);




More information about the asterisk-commits mailing list