Warning: session_start(): open(/var/lib/php/sessions/sess_l4boqsdl82mb3htc0qsc0r3ds9, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
static class ReliableSingleThread implements Runnable {
O runnable;
S name = "Single Thread";
bool cancelBeforeTrigger; // always cancel running thread and wait for it to end before starting new operation
F0 enter; // optional ownership marker, e.g. for DynModules
bool trigger;
Thread thread;
WeakReference threadBeingCancelled;
*(O *runnable) {}
void trigger() { go(); }
synchronized void go() {
if (cancelBeforeTrigger) cancel();
trigger = true;
if (!running()) {
temp callF(enter);
thread = startThread(name, r {
temp callF(enter);
_run();
});
}
}
public void run() { go(); }
void get() { go(); } // so you can use the ! syntax
synchronized bool running() { ret thread != null; }
// use only if this is the last time you trigger this
void triggerAndWait() {
trigger();
while (running()) sleep(1);
}
void _run() ctex {
while licensed {
synchronized(this) {
if (!trigger) {
thread = null;
break;
}
Thread oldThread = getWeakRef(threadBeingCancelled);
if (oldThread != null && oldThread != currentThread())
oldThread.join();
trigger = false;
}
pcallF(runnable);
}
}
synchronized void cancel() {
if (thread == null) ret;
threadBeingCancelled = new WeakReference(thread);
cancelAndInterruptThread(thread);
thread = null;
}
void cancelAndTrigger() {
cancel();
trigger();
}
synchronized bool triggered() { ret trigger; }
void cleanMeUp { cancel(); }
selfType cancelBeforeTrigger() {
cancelBeforeTrigger = true;
this;
}
}