[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] libvob ./test.py org/nongnu/libvob/AbstractUpda...
From: |
Tuomas J. Lukka |
Subject: |
[ff-cvs] libvob ./test.py org/nongnu/libvob/AbstractUpda... |
Date: |
Sun, 31 Aug 2003 08:27:37 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Branch:
Changes by: Tuomas J. Lukka <address@hidden> 03/08/31 08:27:37
Modified files:
. : test.py
org/nongnu/libvob: AbstractUpdateManager.java
org/nongnu/libvob/gl: MipzipMemoryConsumer.java
org/nongnu/libvob/util: Background.java UpdateTimer.java
Added files:
org/nongnu/libvob/util: ThreadBackground.java
Log message:
Abstracting background further, for superlazies
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/test.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/AbstractUpdateManager.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/util/ThreadBackground.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/util/Background.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/util/UpdateTimer.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: libvob/org/nongnu/libvob/AbstractUpdateManager.java
diff -u libvob/org/nongnu/libvob/AbstractUpdateManager.java:1.6
libvob/org/nongnu/libvob/AbstractUpdateManager.java:1.7
--- libvob/org/nongnu/libvob/AbstractUpdateManager.java:1.6 Sat Aug 23
09:25:22 2003
+++ libvob/org/nongnu/libvob/AbstractUpdateManager.java Sun Aug 31 08:27:36 2003
@@ -40,11 +40,13 @@
* <p>
* Currently, GZigZag is single-threaded very strongly, so you can't
* allow anything to happen while the UpdateManager is working.
- * </pre>
+ * <p>
+ * This class implements Background to allow background tasks to be run
+ * in the OpenGL-using thread with the common API.
*/
-public abstract class AbstractUpdateManager implements Runnable {
-public static final String rcsid = "$Id: AbstractUpdateManager.java,v 1.6
2003/08/23 13:25:22 tjl Exp $";
+public abstract class AbstractUpdateManager implements Runnable,
org.nongnu.libvob.util.Background {
+public static final String rcsid = "$Id: AbstractUpdateManager.java,v 1.7
2003/08/31 12:27:36 tjl Exp $";
public static boolean dbg = false;
private static void pa(String s) {
System.err.println("AbstractUpdateManager: "+s); }
@@ -354,6 +356,8 @@
/** Run a given task in the main thread at some point
* in the future.
+ * This static method implements the Background
+ * method addTask.
* @see gzz.util.Background#addTask
*/
public static void doWhenIdle(Runnable r, float priority) {
@@ -362,6 +366,10 @@
queue.notifyAll();
}
instance.interruptEventloop();
+ }
+ // Implement vob.util.Background
+ public void addTask(Runnable r, float priority) {
+ doWhenIdle(r, priority);
}
abstract protected void interruptEventloop() ;
Index: libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java
diff -u libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java:1.2
libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java:1.3
--- libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java:1.2 Mon Jun 16
12:16:30 2003
+++ libvob/org/nongnu/libvob/gl/MipzipMemoryConsumer.java Sun Aug 31
08:27:36 2003
@@ -29,7 +29,7 @@
package org.nongnu.libvob.gl;
import org.nongnu.libvob.memory.*;
import org.nongnu.libvob.*;
-import org.nongnu.libvob.util.Background;
+import org.nongnu.libvob.util.ThreadBackground;
/** An adapter between MipzipLoader and MemoryConsumer.
*/
@@ -53,7 +53,7 @@
int level = Math.max(lb, lq);
mipzip.setGoalBaseLevel(level,
- Background.getDefaultInstance(),
+ ThreadBackground.getDefaultInstance(),
priority);
return mipzip.getMemory(level);
Index: libvob/org/nongnu/libvob/util/Background.java
diff -u libvob/org/nongnu/libvob/util/Background.java:1.1
libvob/org/nongnu/libvob/util/Background.java:1.2
--- libvob/org/nongnu/libvob/util/Background.java:1.1 Wed Mar 26 13:13:25 2003
+++ libvob/org/nongnu/libvob/util/Background.java Sun Aug 31 08:27:36 2003
@@ -2,6 +2,7 @@
Background.java
*
* Copyright (c) 2001, Ted Nelson and Tuomas Lukka
+ * Copyright (c) 2003, Tuomas J. Lukka
*
* This file is part of Gzz.
*
@@ -39,65 +40,12 @@
* will run again.
*/
-public class Background {
- public static boolean dbg = false;
- final static void pa(String s) { System.out.println(s); }
-
- private PriorityQueue queue = new PriorityQueue();
-
+public interface Background {
/** Add a new task to be run in the background thread.
* If the task has already been added, and has not
* been started, the priority will be set to the lower number
* (higher priority) of the two, but the task will only
* be run once.
*/
- public void addTask(Runnable r, float priority) {
- synchronized(queue) {
- queue.add(r, priority);
- queue.notifyAll();
- }
- }
-
- /** Add a new task to run with priority 0.
- */
- public void addTask(Runnable r) {
- addTask(r, 0);
- }
-
- private Thread bgThread = new Thread() {
- public void run() {
- try {
- while(true) {
- Runnable r;
- synchronized(queue) {
- r = (Runnable)queue.getAndRemoveLowest();
- if(r == null) {
- queue.wait();
- continue;
- }
- }
- if(dbg) pa("BG: Going to run "+r);
- r.run();
- if(dbg) pa("BG: Did run "+r);
- }
- } catch(InterruptedException e) {
- pa("BG INTERRUPTED");
- throw new Error("Interrupted");
- }
- }
- };
-
- {
- bgThread.setDaemon(true);
- bgThread.setPriority(Thread.MIN_PRIORITY);
- bgThread.start();
- }
-
- private static Background defaultInstance = null;
- public static Background getDefaultInstance() {
- if(defaultInstance == null)
- defaultInstance = new Background();
- return defaultInstance;
- }
-
+ public void addTask(Runnable r, float priority) ;
}
Index: libvob/org/nongnu/libvob/util/UpdateTimer.java
diff -u libvob/org/nongnu/libvob/util/UpdateTimer.java:1.1
libvob/org/nongnu/libvob/util/UpdateTimer.java:1.2
--- libvob/org/nongnu/libvob/util/UpdateTimer.java:1.1 Sun Mar 9 08:13:14 2003
+++ libvob/org/nongnu/libvob/util/UpdateTimer.java Sun Aug 31 08:27:37 2003
@@ -33,7 +33,7 @@
* implement chgAfter()
*/
public class UpdateTimer {
-public static final String rcsid = "$Id: UpdateTimer.java,v 1.1 2003/03/09
13:13:14 tjl Exp $";
+public static final String rcsid = "$Id: UpdateTimer.java,v 1.2 2003/08/31
12:27:37 tjl Exp $";
public static boolean dbg = false;
private static void pa(String s) { System.err.println(s); }
@@ -73,6 +73,23 @@
};
+ /** Create a new UpdateTimer.
+ * @param r The runnable this timer will run when its timer expires.
+ */
+ public UpdateTimer(Runnable r) {
+ this.r = r;
+ t.setDaemon(true);
+ t.setPriority(Thread.NORM_PRIORITY);
+ t.start();
+ }
+
+ /** Request that the runnable this timer was constructed with
+ * should be run at the latest after the given number of milliseconds.
+ * Calling updateAfter a second time before the timer has
+ * triggered has no effect unless the time specified on the second time
+ * is shorter than the time remaining to the triggering specified
+ * on the first time.
+ */
public void updateAfter(int millis) {
long time = System.currentTimeMillis() + millis;
synchronized(this) {
@@ -85,16 +102,14 @@
}
}
+ /** Tell this timer that the triggered update already happened.
+ * If updateAfter has been called and the routine that would be triggered
+ * after the interval has been invoked anyway, the updateTimer's future
+ * invocation can be cancelled.
+ */
public void updated() {
updateSet = false; // access to one primitive type atomic
if(dbg) pa("UpdateAfter: "+this+" updated");
- }
-
- public UpdateTimer(Runnable r) {
- this.r = r;
- t.setDaemon(true);
- t.setPriority(Thread.NORM_PRIORITY);
- t.start();
}
Index: libvob/test.py
diff -u libvob/test.py:1.2 libvob/test.py:1.3
--- libvob/test.py:1.2 Thu May 15 17:38:34 2003
+++ libvob/test.py Sun Aug 31 08:27:36 2003
@@ -153,6 +153,8 @@
"""
def addTests(list, dirname, names):
+ if dirname[0] in [',', '{']: return
+ if len(dirname) > 2 and dirname[2] in [',', '{']: return
names = [n for n in names if fnmatch.fnmatch(n, '*.test')]
names = [os.path.join(dirname, name) for name in names]
list.extend(names)
@@ -163,6 +165,7 @@
os.path.walk(f, addTests, tests)
else:
tests.append(f)
+ print "Tests: ",tests
return tests
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] libvob ./test.py org/nongnu/libvob/AbstractUpda...,
Tuomas J. Lukka <=