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

View File

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