Ejemplo n.º 1
0
  @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();
    }
  }
Ejemplo n.º 2
0
 static void monitorEnter(TObject o, int count) {
   if (o.monitor == null) {
     o.monitor = new Monitor();
   }
   if (o.monitor.owner == null) {
     o.monitor.owner = TThread.currentThread();
   }
   if (o.monitor.owner != TThread.currentThread()) {
     monitorEnterWait(o, count);
   } else {
     o.monitor.count += count;
   }
 }
Ejemplo n.º 3
0
 static void monitorEnterWait(
     final TObject o, final int count, final AsyncCallback<Void> callback) {
   final TThread thread = TThread.currentThread();
   if (o.monitor == null) {
     o.monitor = new Monitor();
     TThread.setCurrentThread(thread);
     o.monitor.count += count;
     callback.complete(null);
     return;
   } else if (o.monitor.owner == null) {
     o.monitor.owner = thread;
     TThread.setCurrentThread(thread);
     o.monitor.count += count;
     callback.complete(null);
     return;
   }
   o.monitor.enteringThreads.add(
       () -> {
         TThread.setCurrentThread(thread);
         o.monitor.owner = thread;
         o.monitor.count += count;
         callback.complete(null);
       });
 }