Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.radio.thread.script

<<Changes
	<<12/12/01; 7:15:10 PM by DW
		<<Another rewrite of the rescheduler. This time we don't need topofloopticks at all. Didn't need a resynch routine either. It seems to work. Heh. Said that before. ;->
	<<12/12/01; 1:36:25 PM by DW
		<<Another attempt at getting the drifting to stop.
			<<This time the drift could come in when system.temp.radio.misc.flThreadSleeps is set false. It would reset topofloopticks, when you don't want it to be reset. So ironically, the topofloopticks value is set at the end of the loop, just before you come up to the top, if you're not staying awake to help get the user a faster upstream or somesuch.
	<<12/12/01; 9:45:16 AM by DW
		<<After last night's changes the thread would "drift" and not run at even increments of 10 seconds. This makes debugging a very difficult thing to do, so I added code to be sure that we synch up to the clock correctly.
	<<12/11/01; 9:48:46 PM by DW
		<<I just found a longstanding bug here. The code that sleeps was quite complex, and was not working.
		<<It would often loop three or four times every ten seconds. I simplified the calculation, and now it loops just once. This basically triples the speed of the app at doing its background maintenence.
	<<12/11/01; 10:21:05 AM by DW
		<<radio.thread.script is smarter about going to sleep
			<<If it sees that there's work queued up for it to do, it can just loop around to the top and do another pass. An example of this is the writing of directory.opml. The need to do this is detected by the upstreamer, and it adds an item to system.temp.radio.recentlyChangedFolders, which will be picked up by radio.thread.agents.saveChangedDirectories. 
			<<How it works. A new global, system.temp.radio.misc.flThreadSleeps, set on each pass in radio.thread.script, it can be turned off by any code that runs in an agent. This keeps the dirty details out of radio.thread.script.
		<<Moved the starting up code outside the loop. 
	<<12/9/01; 3:57:50 PM by DW
		<<Set system.temp.radio.misc.idThread, unconditionally, every time through the loop. This makes it possible for other code to wake up the thread.
	<<12/1/01; 8:15:31 PM by DW
		<<Deleted code that does nightly updates. 
		<<It's been moved to radio.thread.agents.nightlyUpdates.
	<<10/18/01; 2:35:00 AM by JES
		<<Do automatic nightly update of Radio.root, respecting pref at user.radio.prefs.flUpdateDatabaseNightly. Only read the hotlist, and global glossary if online.
	<<10/18/01; 1:58:22 AM by JES
		<<Respect new prefs for overnight tasks: user.radio.prefs.flReloadHotlistNightly, user.radio.prefs.flReadGlobalGlossaryNightly
	<<8/10/01; 5:54:32 PM by JES
		<<Reload the hotlist at the minute past midnight specified by user.radio.settings.minuteToDoNightlyTasks.
	<<5/2/01; 10:06:47 AM by DW
		<<Created.

bundle { //thread doesn't start running until the app is finished starting up
	while system.temp.Frontier.startingUp { //wait for startup to finish
		thread.sleepTicks (6)}}; //wait 0.1sec

loop {
	radio.init (); //make sure all initializations have been performed
	system.temp.radio.misc.idThread = thread.getCurrentId ();
	system.temp.radio.misc.flThreadSleeps = true;
	bundle { //run all the scripts in the agents sub-table
		local (adr, startticks);
		for adr in @radio.thread.agents {
			startticks = clock.ticks ();
			try {adr^ ()};
			local (adrticks = @system.temp.radio.stats.agentsTicks.[nameof (adr^)]);
			local (ctticks = clock.ticks () - startticks);
			if defined (adrticks^) {
				adrticks^ = adrticks^ + ctticks}
			else {
				adrticks^ = ctticks}}};
	bundle { //reschedule
		if system.temp.radio.misc.flThreadSleeps {
			local (oneloopticks = user.radio.prefs.thread.secsBetweenChecks * 60);
			local (sleepticks = oneloopticks - ((clock.ticks () + oneloopticks) % oneloopticks) + 60);
			thread.sleepTicks (sleepticks)}}}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.