[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] libvob org/nongnu/libvob/AbstractUpdateManager....
From: |
Tuomas J. Lukka |
Subject: |
[ff-cvs] libvob org/nongnu/libvob/AbstractUpdateManager.... |
Date: |
Sun, 07 Sep 2003 08:20:23 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Branch:
Changes by: Tuomas J. Lukka <address@hidden> 03/09/07 08:20:23
Modified files:
org/nongnu/libvob: AbstractUpdateManager.java
org/nongnu/libvob/impl/gl: GLVobCoorderBase.java
org/nongnu/libvob/util: Background.java
PrioritizeBackground.java
PriorityQueue.java ThreadBackground.java
vob/util : faildefs.py
Added files:
org/nongnu/libvob/util: DumbPriorityQueue.java
LifoPriorityQueue.java
test/vob/util : dumbpriorityqueue.test lifopriorityqueue.test
vob/util : priorityqueuetest.py
Removed files:
test/vob/util : priorityqueue.test
Log message:
Commit from arch: split priority queue interface, two implementations
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/AbstractUpdateManager.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.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/DumbPriorityQueue.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/util/LifoPriorityQueue.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/util/Background.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/PrioritizeBackground.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/PriorityQueue.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/ThreadBackground.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/test/vob/util/dumbpriorityqueue.test?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/test/vob/util/lifopriorityqueue.test?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/util/priorityqueuetest.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/util/faildefs.py.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.8
libvob/org/nongnu/libvob/AbstractUpdateManager.java:1.9
--- libvob/org/nongnu/libvob/AbstractUpdateManager.java:1.8 Mon Sep 1
06:20:31 2003
+++ libvob/org/nongnu/libvob/AbstractUpdateManager.java Sun Sep 7 08:20:22 2003
@@ -25,9 +25,12 @@
/*
* Written by Tuomas Lukka and Rauli Ruohonen
*/
+
package org.nongnu.libvob;
import org.nongnu.libvob.util.UpdateTimer;
import org.nongnu.libvob.util.PriorityQueue;
+import org.nongnu.libvob.util.DumbPriorityQueue;
+import org.nongnu.libvob.util.LifoPriorityQueue;
import java.util.*;
import java.util.List;
import java.awt.*;
@@ -46,7 +49,7 @@
*/
public abstract class AbstractUpdateManager implements Runnable,
org.nongnu.libvob.util.Background {
-public static final String rcsid = "$Id: AbstractUpdateManager.java,v 1.8
2003/09/01 10:20:31 tjl Exp $";
+public static final String rcsid = "$Id: AbstractUpdateManager.java,v 1.9
2003/09/07 12:20:22 tjl Exp $";
public static boolean dbg = false;
private static void pa(String s) {
System.err.println("AbstractUpdateManager: "+s); }
@@ -355,7 +358,10 @@
*/
protected abstract boolean handleEvents(boolean waitForEvent);
- static private PriorityQueue queue = new PriorityQueue();
+ // XXX Should use Lifo but Fenfire code is not yet ready
+ // for that
+ // static private PriorityQueue queue = new LifoPriorityQueue();
+ static private PriorityQueue queue = new DumbPriorityQueue();
/** Run a given task in the main thread at some point
* in the future.
@@ -373,6 +379,11 @@
// Implement vob.util.Background
public void addTask(Runnable r, float priority) {
doWhenIdle(r, priority);
+ }
+ public void removeTask(Runnable r) {
+ synchronized(queue) {
+ queue.remove(r);
+ }
}
abstract protected void interruptEventloop() ;
Index: libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.java
diff -u libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.java:1.1
libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.java:1.2
--- libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.java:1.1 Tue Aug 5
06:08:09 2003
+++ libvob/org/nongnu/libvob/impl/gl/GLVobCoorderBase.java Sun Sep 7
08:20:22 2003
@@ -36,14 +36,14 @@
* and GLVobCoorder proper inherits from that.
*/
public abstract class GLVobCoorderBase extends AffineVobCoorder {
-public static final String rcsid = "$Id: GLVobCoorderBase.java,v 1.1
2003/08/05 10:08:09 tjl Exp $";
+public static final String rcsid = "$Id: GLVobCoorderBase.java,v 1.2
2003/09/07 12:20:22 tjl Exp $";
public static boolean dbg = false;
private static void pa(String s) { System.err.println(s); }
- float[] floats = new float[10000*2];
+ float[] floats = new float[80000];
int nfloats = 0;
- int[] inds = new int[5000*2];
+ int[] inds = new int[20000];
int ninds = 1; // zero is special (the root)
public void activate(int cs) {
Index: libvob/org/nongnu/libvob/util/Background.java
diff -u libvob/org/nongnu/libvob/util/Background.java:1.2
libvob/org/nongnu/libvob/util/Background.java:1.3
--- libvob/org/nongnu/libvob/util/Background.java:1.2 Sun Aug 31 08:27:36 2003
+++ libvob/org/nongnu/libvob/util/Background.java Sun Sep 7 08:20:22 2003
@@ -41,11 +41,18 @@
*/
public interface Background {
- /** Add a new task to be run in the background thread.
+ /** Add a new task to be run in the background.
* 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) ;
+
+ /** Remove the given task from the queue.
+ * Due to synchronization issues, this does not guarantee that the given
+ * task will not be run -- some implementations may have that property,
+ * others may not.
+ */
+ public void removeTask(Runnable r);
}
Index: libvob/org/nongnu/libvob/util/PrioritizeBackground.java
diff -u libvob/org/nongnu/libvob/util/PrioritizeBackground.java:1.1
libvob/org/nongnu/libvob/util/PrioritizeBackground.java:1.2
--- libvob/org/nongnu/libvob/util/PrioritizeBackground.java:1.1 Mon Sep 1
06:20:31 2003
+++ libvob/org/nongnu/libvob/util/PrioritizeBackground.java Sun Sep 7
08:20:22 2003
@@ -15,4 +15,7 @@
public void addTask(Runnable r, float priority) {
background.addTask(r, priority + priorityOffset);
}
+ public void removeTask(Runnable r) {
+ background.removeTask(r);
+ }
}
Index: libvob/org/nongnu/libvob/util/PriorityQueue.java
diff -u libvob/org/nongnu/libvob/util/PriorityQueue.java:1.1
libvob/org/nongnu/libvob/util/PriorityQueue.java:1.2
--- libvob/org/nongnu/libvob/util/PriorityQueue.java:1.1 Sun Mar 9
08:13:14 2003
+++ libvob/org/nongnu/libvob/util/PriorityQueue.java Sun Sep 7 08:20:22 2003
@@ -3,20 +3,20 @@
*
* Copyright (c) 2003, Tuomas J. Lukka
*
- * This file is part of Gzz.
+ * This file is part of Libvob.
*
- * Gzz is free software; you can redistribute it and/or modify it under
+ * Libvob is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
- * Gzz is distributed in the hope that it will be useful, but WITHOUT
+ * Libvob is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with Gzz; if not, write to the Free
+ * Public License along with Libvob; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
@@ -31,69 +31,26 @@
/** A simple implementation of a priority queue, for background
* jobs.
- * N.B. the current implementation is not the most efficient
- * possible one,
- * by far.
* <p>
- * This class is not synchronized!
+ * This interface and its implementations are not synchronized,
+ * analogous to java.util Containers!
*/
-
-public class PriorityQueue {
-
- /** Compare two objects using the jobPriority value
- * as primary and hash code as secondary code.
- */
- private class Comp implements Comparator {
- public int compare(Object o1, Object o2) {
- Float p1 = (Float)jobPriority.get(o1);
- Float p2 = (Float)jobPriority.get(o2);
- float f1 = p1.floatValue();
- float f2 = p2.floatValue();
- if(f1 < f2) return -1;
- if(f1 > f2) return 1;
- int i1 = o1.hashCode();
- int i2 = o2.hashCode();
- if(i1 < i2) return -1;
- if(i1 > i2) return 1;
- return 0;
- }
- }
-
- /** Job object to Float (the priority).
- */
- private Map jobPriority = new HashMap();
-
- /** Set of jobs, to be compared by their priorities.
- */
- private TreeSet jobs = new TreeSet(new Comp());
-
-
+public interface PriorityQueue {
/** Add a job to run.
* If the job has already been added, set the priority
* to the lower value (more important) of the two.
*/
- public void add(Object job, float priority) {
- Float prevprio = (Float)jobPriority.get(job);
- if(prevprio != null) {
- if(priority >= prevprio.intValue()) return;
- // Now, in order not to corrupt the TreeSet,
- // we must FIRST remove the element, then change
- // the priority and then re-add it after the priority
- // has been changed.
- jobs.remove(job);
- }
- jobPriority.put(job, new Float(priority));
- jobs.add(job);
- }
+ void add(Object job, float priority) ;
+
+ /** Remove a job from the queue.
+ */
+ void remove(Object job) ;
/** Get the most important (with lowest numeric priority) job and remove
* it from this queue.
+ * If there are several jobs with the same importance,
+ * no guarantee is made of which job is returned.
+ * Subclasses *may* make their own guarantees about this.
*/
- public Object getAndRemoveLowest() {
- if(jobs.isEmpty()) return null;
- Object j = jobs.first();
- jobs.remove(j);
- jobPriority.remove(j);
- return j;
- }
+ Object getAndRemoveLowest() ;
}
Index: libvob/org/nongnu/libvob/util/ThreadBackground.java
diff -u libvob/org/nongnu/libvob/util/ThreadBackground.java:1.1
libvob/org/nongnu/libvob/util/ThreadBackground.java:1.2
--- libvob/org/nongnu/libvob/util/ThreadBackground.java:1.1 Sun Aug 31
08:27:37 2003
+++ libvob/org/nongnu/libvob/util/ThreadBackground.java Sun Sep 7 08:20:22 2003
@@ -37,12 +37,21 @@
public static boolean dbg = false;
final static void pa(String s) { System.out.println(s); }
- private PriorityQueue queue = new PriorityQueue();
+ // XXX Should use Lifo but Fenfire code is not yet ready
+ // for that
+ // private PriorityQueue queue = new LifoPriorityQueue();
+ private PriorityQueue queue = new DumbPriorityQueue();
public void addTask(Runnable r, float priority) {
synchronized(queue) {
queue.add(r, priority);
queue.notifyAll();
+ }
+ }
+
+ public void removeTask(Runnable r) {
+ synchronized(queue) {
+ queue.remove(r);
}
}
Index: libvob/vob/util/faildefs.py
diff -u libvob/vob/util/faildefs.py:1.1 libvob/vob/util/faildefs.py:1.2
--- libvob/vob/util/faildefs.py:1.1 Thu May 15 17:38:34 2003
+++ libvob/vob/util/faildefs.py Sun Sep 7 08:20:23 2003
@@ -29,9 +29,9 @@
def failIfApprox(delta, first, second, msg = None):
failIf(abs(first-second) <= delta, msg)
def failUnlessEqual(first, second, msg = None):
- assert first == second, msg
+ assert first == second, (first, second, msg)
def failIfEqual(first, second, msg = None):
- assert first != second, msg
+ assert first != second, (first, second, msg)
def failIf(expr, msg = None):
assert not expr, msg
def failUnless(expr, msg = None):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] libvob org/nongnu/libvob/AbstractUpdateManager....,
Tuomas J. Lukka <=