示例#1
0
文件: TObject.java 项目: leobm/teavm
 @Override
 protected Object clone() throws TCloneNotSupportedException {
   if (!(this instanceof TCloneable)
       && Platform.getPlatformObject(this).getPlatformClass().getMetadata().getArrayItem()
           == null) {
     throw new TCloneNotSupportedException();
   }
   Object result = Platform.clone(this);
   Platform.getPlatformObject(result).setId(Platform.nextObjectId());
   return result;
 }
示例#2
0
文件: TObject.java 项目: leobm/teavm
 @Override
 public void interrupted() {
   if (performed) {
     return;
   }
   performed = true;
   if (timerId >= 0) {
     Platform.killSchedule(timerId);
     timerId = -1;
   }
   Platform.postpone(() -> callback.error(new TInterruptedException()));
 }
示例#3
0
文件: TObject.java 项目: leobm/teavm
  @Sync
  static void monitorExit(final TObject o, int count) {
    if (o.isEmptyMonitor() || o.monitor.owner != TThread.currentThread()) {
      throw new TIllegalMonitorStateException();
    }
    o.monitor.count -= count;
    if (o.monitor.count > 0) {
      return;
    }

    o.monitor.owner = null;
    if (!o.monitor.enteringThreads.isEmpty()) {
      Platform.postpone(
          () -> {
            if (o.isEmptyMonitor() || o.monitor.owner != null) {
              return;
            }
            if (!o.monitor.enteringThreads.isEmpty()) {
              o.monitor.enteringThreads.remove().run();
            }
          });
    } else {
      o.isEmptyMonitor();
    }
  }
示例#4
0
文件: TObject.java 项目: leobm/teavm
 public final void waitImpl(long timeout, int nanos, final AsyncCallback<Void> callback) {
   final NotifyListenerImpl listener = new NotifyListenerImpl(this, callback, monitor.count);
   monitor.notifyListeners.add(listener);
   if (timeout > 0 || nanos > 0) {
     listener.timerId =
         Platform.schedule(
             listener, timeout >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) timeout);
   }
   monitorExit(this, monitor.count);
 }
示例#5
0
文件: TObject.java 项目: leobm/teavm
 @Override
 public void run() {
   if (performed) {
     return;
   }
   performed = true;
   if (timerId >= 0) {
     Platform.killSchedule(timerId);
     timerId = -1;
   }
   TThread.setCurrentThread(currentThread);
   monitorEnterWait(obj, lockCount, callback);
 }
示例#6
0
文件: TObject.java 项目: leobm/teavm
 @Sync
 @Rename("notifyAll")
 public final void notifyAll0() {
   if (!holdsLock(this)) {
     throw new TIllegalMonitorStateException();
   }
   PlatformQueue<NotifyListener> listeners = monitor.notifyListeners;
   while (!listeners.isEmpty()) {
     NotifyListener listener = listeners.remove();
     if (!listener.expired()) {
       Platform.postpone(listener);
     }
   }
 }
示例#7
0
文件: TObject.java 项目: leobm/teavm
 public Monitor() {
   this.owner = TThread.currentThread();
   enteringThreads = Platform.createQueue();
   notifyListeners = Platform.createQueue();
 }
示例#8
0
文件: TObject.java 项目: leobm/teavm
 int identity() {
   return Platform.getPlatformObject(this).getId();
 }
示例#9
0
文件: TObject.java 项目: leobm/teavm
 @Rename("getClass")
 public final TClass<?> getClass0() {
   return TClass.getClass(Platform.getPlatformObject(this).getPlatformClass());
 }
示例#10
0
文件: TObject.java 项目: leobm/teavm
 @Rename("<init>")
 private void init() {
   Platform.getPlatformObject(this).setId(Platform.nextObjectId());
 }