[svn-commits] russell: branch russell/sched_thread r140413 - in /team/russell/sched_thread:...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Aug 28 21:40:39 CDT 2008


Author: russell
Date: Thu Aug 28 21:40:38 2008
New Revision: 140413

URL: http://svn.digium.com/view/asterisk?view=rev&rev=140413
Log:
More conversion to move the scheduler into its own thread ...

Modified:
    team/russell/sched_thread/channels/chan_sip.c
    team/russell/sched_thread/include/asterisk/sched.h
    team/russell/sched_thread/main/sched.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=140413&r1=140412&r2=140413
==============================================================================
--- team/russell/sched_thread/channels/chan_sip.c (original)
+++ team/russell/sched_thread/channels/chan_sip.c Thu Aug 28 21:40:38 2008
@@ -10188,7 +10188,9 @@
 	} else {
 		sip_poke_peer(peer, 0);
 	}
-	AST_SCHED_REPLACE(peer->expire, sched, (expire + 10) * 1000, expire_register, peer);
+	/* XXX refcount not handled, will be fixed in another branch */
+	sched_thread_del(sched, peer->expire);
+	peer->expire = sched_thread_add(sched, (expire + 10) * 1000, expire_register, peer);
 	register_peer_exten(peer, TRUE);
 }
 
@@ -10316,12 +10318,12 @@
 	if (ast_strlen_zero(curi) && ast_strlen_zero(expires)) {
 		/* If we have an active registration, tell them when the registration is going to expire */
 		if (peer->expire > -1 && !ast_strlen_zero(peer->fullcontact))
-			pvt->expiry = ast_sched_when(sched, peer->expire);
+			pvt->expiry = sched_thread_when(sched, peer->expire);
 		return PARSE_REGISTER_QUERY;
 	} else if (!strcasecmp(curi, "*") || !expire) {	/* Unregister this peer */
 		/* This means remove all registrations and return OK */
 		memset(&peer->addr, 0, sizeof(peer->addr));
-		AST_SCHED_DEL(sched, peer->expire);
+		sched_thread_del(sched, peer->expire);
 
 		destroy_association(peer);
 		
@@ -10378,13 +10380,13 @@
 	if (!ast_strlen_zero(curi) && ast_strlen_zero(peer->username))
 		ast_copy_string(peer->username, curi, sizeof(peer->username));
 
-	AST_SCHED_DEL(sched, peer->expire);
+	sched_thread_del(sched, peer->expire);
 	if (expire > max_expiry)
 		expire = max_expiry;
 	if (expire < min_expiry)
 		expire = min_expiry;
 	peer->expire = peer->is_realtime && !ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS) ? -1 :
-		ast_sched_add(sched, (expire + 10) * 1000, expire_register, peer);
+		sched_thread_add(sched, (expire + 10) * 1000, expire_register, peer);
 	pvt->expiry = expire;
 	snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expire, peer->username, peer->fullcontact);
 	/* Saving TCP connections is useless, we won't be able to reconnect 
@@ -13135,7 +13137,7 @@
 		ast_cli(fd, "  Dynamic      : %s\n", cli_yesno(peer->host_dynamic));
 		ast_cli(fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
 		ast_cli(fd, "  MaxCallBR    : %d kbps\n", peer->maxcallbitrate);
-		ast_cli(fd, "  Expire       : %ld\n", ast_sched_when(sched, peer->expire));
+		ast_cli(fd, "  Expire       : %ld\n", sched_thread_when(sched, peer->expire));
 		ast_cli(fd, "  Insecure     : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE)));
 		ast_cli(fd, "  Nat          : %s\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT)));
 		ast_cli(fd, "  ACL          : %s\n", cli_yesno(peer->ha != NULL));
@@ -13240,7 +13242,7 @@
 		astman_append(s, "MaxCallBR: %d kbps\r\n", peer->maxcallbitrate);
 		astman_append(s, "Dynamic: %s\r\n", peer->host_dynamic?"Y":"N");
 		astman_append(s, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, ""));
-		astman_append(s, "RegExpire: %ld seconds\r\n", ast_sched_when(sched, peer->expire));
+		astman_append(s, "RegExpire: %ld seconds\r\n", sched_thread_when(sched, peer->expire));
 		astman_append(s, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE)));
 		astman_append(s, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT)));
 		astman_append(s, "ACL: %s\r\n", (peer->ha?"Y":"N"));
@@ -13332,7 +13334,7 @@
 		return NULL;
 	}
 	ast_cli(a->fd, "\n");
-	ast_sched_report(sched, cbuf, sizeof(cbuf), &cbnames);
+	ast_sched_report(sched_thread_get_context(sched), cbuf, sizeof(cbuf), &cbnames);
 	ast_cli(a->fd, "%s", cbuf);
 	return CLI_SUCCESS;
 }
@@ -15194,7 +15196,9 @@
 
 	/* Acknowledge sequence number - This only happens on INVITE from SIP-call */
 	/* Don't auto congest anymore since we've gotten something useful back */
-	AST_SCHED_DEL_UNREF(sched, p->initid, dialog_unref(p, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr"));
+	if (sched_thread_del(sched, p->initid)) {
+		dialog_unref(p, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
+	}
 
 	/* RFC3261 says we must treat every 1xx response (but not 100)
 	   that we don't recognize as if it was 183.
@@ -15496,7 +15500,7 @@
 				/* Reset the flag after a while 
 				 */
 				int wait = 3 + ast_random() % 5;
-				p->waitid = ast_sched_add(sched, wait, sip_reinvite_retry, dialog_ref(p, "passing dialog ptr into sched structure based on waitid for sip_reinvite_retry.")); 
+				p->waitid = sched_thread_add(sched, wait, sip_reinvite_retry, dialog_ref(p, "passing dialog ptr into sched structure based on waitid for sip_reinvite_retry.")); 
 				ast_log(LOG_WARNING, "just did sched_add waitid(%d) for sip_reinvite_retry for dialog %s in handle_response_invite\n", p->waitid, p->callid);
 				ast_debug(2, "Reinvite race. Waiting %d secs before retry\n", wait);
 			}
@@ -15633,7 +15637,7 @@
 		break;
 	case 403:	/* Forbidden */
 		ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname);
-		AST_SCHED_DEL(sched, r->timeout);
+		sched_thread_del(sched, r->timeout);
 		r->regstate = REG_STATE_NOAUTH;
 		p->needdestroy = 1;
 		break;
@@ -15643,7 +15647,7 @@
 		if (r->call)
 			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 404");
 		r->regstate = REG_STATE_REJECTED;
-		AST_SCHED_DEL(sched, r->timeout);
+		sched_thread_del(sched, r->timeout);
 		break;
 	case 407:	/* Proxy auth */
 		if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) {
@@ -15658,7 +15662,7 @@
 	case 423:	/* Interval too brief */
 		r->expiry = atoi(get_header(req, "Min-Expires"));
 		ast_log(LOG_WARNING, "Got 423 Interval too brief for service %s@%s, minimum is %d seconds\n", p->registry->username, p->registry->hostname, r->expiry);
-		AST_SCHED_DEL(sched, r->timeout);
+		sched_thread_del(sched, r->timeout);
 		r->timeout = -1;
 		if (r->call) {
 			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 423");
@@ -15680,7 +15684,7 @@
 		if (r->call)
 			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 479");
 		r->regstate = REG_STATE_REJECTED;
-		AST_SCHED_DEL(sched, r->timeout);
+		sched_thread_del(sched, r->timeout);
 		break;
 	case 200:	/* 200 OK */
 		if (!r) {
@@ -15697,7 +15701,7 @@
 		if (r->timeout > -1) {
 			ast_debug(1, "Cancelling timeout %d\n", r->timeout);
 		}
-		AST_SCHED_DEL(sched, r->timeout);
+		sched_thread_del(sched, r->timeout);
 		if (r->call)
 			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 200");
 		p->registry = registry_unref(p->registry, "unref registry entry p->registry");
@@ -15707,7 +15711,7 @@
 		
 		/* set us up for re-registering */
 		/* figure out how long we got registered for */
-		AST_SCHED_DEL(sched, r->expire);
+		sched_thread_del(sched, r->expire);
 		
 		/* according to section 6.13 of RFC, contact headers override
 		   expires headers, so check those first */
@@ -19591,17 +19595,9 @@
 
 		pthread_testcancel();
 		/* Wait for sched or io */
-		res = ast_sched_wait(sched);
-		if ((res < 0) || (res > 1000))
-			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);
-		ast_mutex_lock(&monlock);
-		res = ast_sched_runq(sched);
-		if (res >= 20)
-			ast_debug(1, "chan_sip: ast_sched_runq ran %d all at once\n", res);
-		ast_mutex_unlock(&monlock);
 	}
 
 	/* Never reached */
@@ -19676,7 +19672,7 @@
 		return;
 	}
 
-	p->stimer->st_schedid  = ast_sched_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, p);
+	p->stimer->st_schedid  = sched_thread_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, p);
 	if (p->stimer->st_schedid < 0) {
 		ast_log(LOG_ERROR, "ast_sched_add failed.\n");
 	}
@@ -22459,7 +22455,6 @@
 	time_t start_poke, end_poke;
 	
 	reload_config(reason);
-	ast_sched_dump(sched);
 
 	start_poke = time(0);
 	/* Prune peers who still are supposed to be deleted */
@@ -22643,8 +22638,6 @@
 	struct ast_context *con;
 	struct ao2_iterator i;
 
-	ast_sched_dump(sched);
-	
 	/* First, take us out of the channel type list */
 	ast_channel_unregister(&sip_tech);
 

Modified: team/russell/sched_thread/include/asterisk/sched.h
URL: http://svn.digium.com/view/asterisk/team/russell/sched_thread/include/asterisk/sched.h?view=diff&rev=140413&r1=140412&r2=140413
==============================================================================
--- team/russell/sched_thread/include/asterisk/sched.h (original)
+++ team/russell/sched_thread/include/asterisk/sched.h Thu Aug 28 21:40:38 2008
@@ -289,6 +289,8 @@
 /*! XXX I hate this and want it to go away eventually */
 struct sched_context *sched_thread_get_context(struct sched_thread *st);
 
+long sched_thread_when(struct sched_thread *st, int id);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/russell/sched_thread/main/sched.c
URL: http://svn.digium.com/view/asterisk/team/russell/sched_thread/main/sched.c?view=diff&rev=140413&r1=140412&r2=140413
==============================================================================
--- team/russell/sched_thread/main/sched.c (original)
+++ team/russell/sched_thread/main/sched.c Thu Aug 28 21:40:38 2008
@@ -117,6 +117,11 @@
 	}
 
 	return NULL;
+}
+
+long sched_thread_when(struct sched_thread *st, int id)
+{
+	return ast_sched_when(st->context, id);
 }
 
 struct sched_context *sched_thread_get_context(struct sched_thread *st)




More information about the svn-commits mailing list