--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/AbstractWaitableRunnable.java Mon Aug 20 16:01:53 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/AbstractWaitableRunnable.java Mon Aug 20 16:02:15 2012 +0200
@@ -2,22 +2,29 @@
* An abstract implementation of {@link WaitableRunnable}
public abstract class AbstractWaitableRunnable implements WaitableRunnable {
private final Object mutex = new Object();
+ * Boolean indicating if we have run. private boolean wasRun = false;
+ * Counter counting how many objects are waiting for us to run. private int waitForRunning = 0;
@@ -29,7 +36,10 @@
protected void executionFinished() {
- protected abstract void execute();;
+ * Executes the task that should be run. + protected abstract void execute(); public void waitFor() throws InterruptedException {
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/PurpleThread.java Mon Aug 20 16:01:53 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/PurpleThread.java Mon Aug 20 16:02:15 2012 +0200
@@ -7,12 +7,12 @@
* This is the main thread of libpurple. It is used internally to execute
* libpurple functions that can be called from everywhere, because libpurple is
public class PurpleThread {
- private final BlockingQueue<WaitableRunnable> waiting = new LinkedBlockingQueue<WaitableRunnable>();
+ private final BlockingQueue<WaitableRunnable> waiting = + new LinkedBlockingQueue<WaitableRunnable>(); private final Object purpleMutex = new Object();
private final Object lastScheduledMutex = new Object();
private WaitableRunnable lastScheduled;
@@ -27,7 +27,7 @@
* really short calls. This method blocks until the thread is in a safe
* state and returns a mutex to you. There may be other tasks scheduled
* between you got the mutex and you got the lock.
* @return A synchronisation mutex.
* @throws InterruptedException
@@ -46,6 +46,11 @@
+ * This class is the main loop of the purple thread. private class PurpleThreadRunner implements Runnable {
@@ -64,16 +69,22 @@
} catch (InterruptedException e) {
System.out.println("Purple thread was interrupted,"
- + " but is continuing.");
+ + " but is continuing."); System.err.println("Purple thread catched throwable: "
t.printStackTrace(System.err);
+ * Schedules a waitable runnable to be run somewhere in the future. + * The runnable to schedule. public void schedule(WaitableRunnable r) {
synchronized (lastScheduledMutex) {
@@ -81,23 +92,55 @@
+ * Schedules a normal runnable and waits for its execution. + * The runnable to schedule. + * @throws InterruptedException + * If the current thread was interrupted while waiting. public void scheduleAndWaitFor(Runnable r) throws InterruptedException {
WaitableRunnableRunner waitable = new WaitableRunnableRunner(r);
scheduleAndWaitFor(waitable);
+ * Schedules a waitable runnable and waits for its execution. + * The waitable runnable to schedule. + * @throws InterruptedException + * If the current thread was interrupted while waiting. + * @see {@link #scheduleAndWaitFor(Runnable)} public void scheduleAndWaitFor(WaitableRunnable waitable)
- throws InterruptedException {
+ throws InterruptedException { - public void scheduleAndWaitForUninterruptable(WaitableRunnable r) {
+ * Schedules a runnable and waits for its execution. If the thread is + * interrupted, it just continues to wait. + * The normal runnable to schedule. + public void scheduleAndWaitForUninterruptable(Runnable r) { WaitableRunnableRunner waitable = new WaitableRunnableRunner(r);
scheduleAndWaitForUninterruptable(waitable);
- private void scheduleAndWaitForUninterruptable(WaitableRunnableRunner waitable) {
+ * Schedules a waitable runnable and waits for its execution. If the thread + * is interrupted, it just continues to wait. + * The waitable runnable to schedule. + * @see #scheduleAndWaitForUninterruptable(Runnable) + public void scheduleAndWaitForUninterruptable(WaitableRunnable waitable) { boolean finished = false;
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/WaitableRunnableRunner.java Mon Aug 20 16:01:53 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/thread/WaitableRunnableRunner.java Mon Aug 20 16:02:15 2012 +0200
@@ -2,9 +2,8 @@
* A runnable we can wait for. We might use an object pool for this.
public class WaitableRunnableRunner extends AbstractWaitableRunnable {