Fix code styling

This commit is contained in:
konsoletyper 2015-02-10 22:10:06 +04:00
parent b69b5b9219
commit 857ed9754e
2 changed files with 24 additions and 42 deletions

View File

@ -17,40 +17,35 @@ package org.teavm.classlib.java.lang;
import org.teavm.dom.browser.Window;
import org.teavm.javascript.spi.Async;
import org.teavm.javascript.spi.Rename;
import org.teavm.javascript.spi.Superclass;
import org.teavm.jso.JS;
import org.teavm.jso.JSArray;
import org.teavm.jso.JSFunctor;
import org.teavm.jso.JSObject;
import org.teavm.platform.Platform;
import org.teavm.platform.async.AsyncCallback;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
@Superclass("")
public class TObject {
private static final Window window = (Window)JS.getGlobal();
private TThread owner;
private TObject monitorLock;
private int monitorCount=0;
private int monitorCount;
private JSArray<NotifyListener> notifyListeners;
private final Window window = (Window)JS.getGlobal();
@JSFunctor
private static interface NotifyListener extends JSObject{
interface NotifyListener extends JSObject {
void handleNotify();
}
static void monitorEnter(TObject o){
if ( o.monitorLock == null ){
if (o.monitorLock == null ){
o.monitorLock = new TObject();
}
while (o.owner != null && o.owner != TThread.currentThread() ){
while (o.owner != null && o.owner != TThread.currentThread()) {
try {
o.monitorLock.wait();
} catch (InterruptedException ex) {
@ -59,13 +54,11 @@ public class TObject {
}
o.owner = TThread.currentThread();
o.monitorCount++;
}
static void monitorExit(TObject o){
o.monitorCount--;
if ( o.monitorCount == 0 && o.monitorLock != null){
if (o.monitorCount == 0 && o.monitorLock != null) {
o.owner = null;
o.monitorLock.notifyAll();
}
@ -131,22 +124,20 @@ public class TObject {
public final void notifyAll0(){
if (notifyListeners != null){
JSArray<NotifyListener> listeners = window.newArray();
while (notifyListeners.getLength() > 0 ){
while (notifyListeners.getLength() > 0) {
listeners.push(notifyListeners.shift());
}
while ( listeners.getLength() > 0 ){
while (listeners.getLength() > 0) {
listeners.shift().handleNotify();
}
}
}
@Rename("wait")
public final void wait0(long timeout) throws TInterruptedException{
try {
wait(timeout, 0);
} catch ( InterruptedException ex){
} catch (InterruptedException ex) {
throw new TInterruptedException();
}
}
@ -155,15 +146,13 @@ public class TObject {
@Rename("wait")
public native final void wait0(long timeout, int nanos) throws TInterruptedException;
@Rename("wait")
public final void wait0(long timeout, int nanos, final AsyncCallback<Void> callback){
if ( notifyListeners == null ){
public final void wait0(long timeout, int nanos, final AsyncCallback<Void> callback) {
if (notifyListeners == null) {
notifyListeners = window.newArray();
}
final TThread currentThread = TThread.currentThread();
notifyListeners.push(new NotifyListener(){
notifyListeners.push(new NotifyListener() {
@Override
public void handleNotify() {
TThread.setCurrentThread(currentThread);
@ -172,9 +161,7 @@ public class TObject {
} finally {
TThread.setCurrentThread(TThread.getMainThread());
}
}
});
}

View File

@ -27,7 +27,6 @@ import org.teavm.platform.async.AsyncCallback;
* @author Alexey Andreev
*/
public class TThread extends TObject implements TRunnable {
private static Window window = (Window)JS.getGlobal();
private static TThread mainThread = new TThread(TString.wrap("main"));
private static TThread currentThread = mainThread;
@ -73,8 +72,6 @@ public class TThread extends TObject implements TRunnable {
activeCount--;
setCurrentThread(mainThread);
}
}
static void setCurrentThread(TThread thread){
@ -136,13 +133,11 @@ public class TThread extends TObject implements TRunnable {
return TObject.holdsLock(obj);
}
@Async
public static native void sleep(long millis) throws TInterruptedException;
private static void sleep(long millis, final AsyncCallback<Void> callback) {
final TThread current = currentThread();
window.setTimeout(new TimerHandler() {
@Override public void onTimer() {
setCurrentThread(current);