Package quicktime.std.clocks

Source Code of quicktime.std.clocks.CBRunner$MRJIdler

/*     */ package quicktime.std.clocks;
/*     */
/*     */ import java.security.AccessController;
/*     */ import java.security.PrivilegedAction;
/*     */ import quicktime.QTCallbackManagement;
/*     */ import quicktime.QTObject;
/*     */ import quicktime.QTRuntimeException;
/*     */ import quicktime.QTSession;
/*     */
/*     */ final class CBRunner
/*     */   implements Runnable
/*     */ {
/*   8 */   private static int activeCallbacks = 0;
/*     */   private static Thread idleThread;
/*     */   private static int nCBThreads;
/*     */   private static String privActStrCached;
/*     */   private Thread cbThread;
/*     */   private CBMethodClosure mMethodClosure;
/*     */   private QTCallBack cb;
/*  79 */   private boolean callbackDone = false;
/*     */   private int callBackTimeBase;
/*  81 */   private boolean notified = false;
/*     */   private boolean executing;
/*     */
/*     */   CBRunner(QTCallBack paramQTCallBack)
/*     */   {
/*  27 */     this.cb = paramQTCallBack;
/*     */
/*  29 */     this.callBackTimeBase = GetCallBackTimeBase(QTObject.ID(paramQTCallBack));
/*     */
/*  40 */     this.mMethodClosure = new CBMethodClosure(this, "callBackProc", "(II)V", 960);
/*     */
/*  42 */     privActStrCached = "CBThread-" + nCBThreads++ + "-";
/*  43 */     if ((paramQTCallBack instanceof TimeCallBack))
/*  44 */       privActStrCached += "TC";
/*  45 */     else if ((paramQTCallBack instanceof TimeJumpCallBack))
/*  46 */       privActStrCached += "TJ";
/*  47 */     else if ((paramQTCallBack instanceof RateCallBack))
/*  48 */       privActStrCached += "RC";
/*  49 */     else if ((paramQTCallBack instanceof ExtremesCallBack)) {
/*  50 */       privActStrCached += "EC";
/*     */     }
/*  52 */     if (QTSession.getJavaVersion() == 65537) {
/*  53 */       this.cbThread = new Thread(this, privActStrCached);
/*     */     }
/*     */     else
/*     */     {
/*  66 */       this.cbThread = ((Thread)new Object()
/*     */       {
/*     */         Object doPrivelegedAction()
/*     */         {
/*  58 */           return AccessController.doPrivileged(new PrivilegedAction()
/*     */           {
/*     */             public Object run() {
/*  61 */               return new Thread(CBRunner.this, CBRunner.privActStrCached);
/*     */             }
/*     */           });
/*     */         }
/*     */       }
/*  66 */       .doPrivelegedAction());
/*     */     }
/*  68 */     this.cbThread.setPriority(10);
/*  69 */     this.cbThread.start();
/*     */   }
/*     */
/*     */   final void cleanup()
/*     */   {
/*  85 */     this.callbackDone = true;
/*  86 */     if (QTSession.isCurrentOS(1)) {
/*  87 */       activeCallbacks -= 1;
/*  88 */       if (activeCallbacks < 1) {
/*  89 */         idleThread = null;
/*  90 */         activeCallbacks = 0;
/*     */       }
/*     */     }
/*  93 */     doNotify();
/*     */   }
/*     */
/*     */   final int getClosure()
/*     */   {
/* 101 */     if (this.mMethodClosure != null) {
/* 102 */       return this.mMethodClosure.getClosure();
/*     */     }
/* 104 */     throw new QTRuntimeException("No Method Closure object created");
/*     */   }
/*     */
/*     */   private final void callBackProc(int paramInt1, int paramInt2) {
/* 108 */     doNotify();
/*     */   }
/*     */
/*     */   public void run() {
/* 112 */     doWait();
/* 113 */     if (!this.callbackDone) {
/*     */       while (true)
/*     */       {
/* 116 */         this.notified = false;
/*     */
/* 118 */         synchronized (QTSession.terminationLock()) {
/* 119 */           if (QTSession.isInitialized())
/*     */           {
/* 121 */             if (this.callbackDone) {
/*     */               break;
/*     */             }
/* 124 */             this.cb.timeWhenCalledMsecs = GetTimeBaseTime(this.callBackTimeBase, 1000, 0);
/* 125 */             this.cb.rateWhenCalled = (GetTimeBaseEffectiveRate(this.callBackTimeBase) / 65536.0F);
/*     */
/* 128 */             if (this.cb.rateWhenCalled < 0.0F) {
/* 129 */               this.cb.timeWhenCalledMsecs += 1;
/*     */             }
/* 131 */             if (this.callbackDone) {
/*     */               break;
/*     */             }
/* 134 */             this.executing = true;
/* 135 */             this.cb.execute();
/*     */           } else {
/* 137 */             break;
/*     */           }
/*     */         }
/* 140 */         if (!this.callbackDone)
/*     */         {
/* 143 */           doWait();
/*     */
/* 145 */           if (!this.notified) {
/* 146 */             break;
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 151 */     if (this.cb.upp == this) {
/* 152 */       this.cb.upp = null;
/*     */     }
/* 154 */     this.cbThread = null;
/* 155 */     this.mMethodClosure = null;
/*     */   }
/*     */
/*     */   private synchronized void doWait() {
/* 159 */     this.executing = false;
/* 160 */     if ((this.notified) || (this.callbackDone))
/* 161 */       return;
/*     */     try
/*     */     {
/* 164 */       wait();
/* 165 */       this.notified = true;
/*     */     } catch (InterruptedException localInterruptedException) {
/* 167 */       this.notified = false;
/*     */     }
/*     */   }
/*     */
/*     */   synchronized void doNotify() {
/* 172 */     if (this.executing) {
/* 173 */       this.notified = true;
/* 174 */       return;
/*     */     }
/* 176 */     this.notified = true;
/* 177 */     notifyAll();
/*     */   }
/*     */   private static native int GetTimeBaseEffectiveRate(int paramInt);
/*     */
/*     */   private static native int GetTimeBaseTime(int paramInt1, int paramInt2, int paramInt3);
/*     */
/*     */   private static native int GetCallBackTimeBase(int paramInt);
/*     */
/*     */   static class CBMethodClosure {
/*     */     Object mContext;
/*     */
/*     */     CBMethodClosure(Object paramObject, String paramString1, String paramString2, int paramInt) {
/* 189 */       this.mContext = paramObject;
/*     */
/* 191 */       AccessController.doPrivileged(new PrivilegedAction() { private final String val$methodName;
/*     */         private final String val$methodSignature;
/*     */
/* 193 */         public Object run() { QTCallbackManagement.registerForCallback(CBRunner.CBMethodClosure.this.mContext, this.val$methodName, this.val$methodSignature);
/* 194 */           return null; }
/*     */       });
/*     */     }
/*     */
/*     */     void dispose()
/*     */     {
/* 200 */       AccessController.doPrivileged(new PrivilegedAction() {
/*     */         public Object run() {
/* 202 */           QTCallbackManagement.unregisterForCallback(CBRunner.CBMethodClosure.this.mContext);
/* 203 */           return null;
/*     */         } } );
/*     */     }
/*     */
/*     */     int getClosure() {
/* 208 */       return this.mContext.hashCode();
/*     */     }
/*     */   }
/*     */
/*     */   static class MRJIdler
/*     */     implements Runnable
/*     */   {
/*     */     public void run()
/*     */     {
/*     */       try
/*     */       {
/*  15 */         while (CBRunner.activeCallbacks >= 1)
/*     */         {
/*  17 */           Thread.sleep(10L);
/*     */         }
/*     */       } catch (InterruptedException localInterruptedException) {  }
/*     */
/*  20 */       CBRunner.access$102(null);
/*     */     }
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\QTJava.zip
* Qualified Name:     quicktime.std.clocks.CBRunner
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of quicktime.std.clocks.CBRunner$MRJIdler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.