Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ReaderLock.java

00001 class ReaderLock extends Signaller 
00002 {
00003      WriterPreferenceReadWriteLock wprw;
00004      
00005      public ReaderLock(WriterPreferenceReadWriteLock wprw)
00006      {
00007           this.wprw = wprw;
00008      }
00009      
00010      public void acquire ()
00011      {
00012           java.lang.Object ie = null;
00013           synchronized (this)
00014           {
00015                if (!this.wprw.startReadFromNewReader())
00016                {
00017                     for (; true; )
00018                     {
00019                          try {
00020                               this.wait();
00021                               if (this.wprw.startReadFromWaitingReader())
00022                               {
00023                                    return;
00024                               }
00025                          }
00026                          catch (java.lang.InterruptedException ex) {
00027                               this.wprw.cancelledWaitingReader();
00028                               ie = ex;
00029                               break;
00030                          }
00031                     }
00032                }
00033           }
00034           if (ie != null)
00035           {
00036                this.wprw.writerLock_.signalWaiters();
00037                throw ((java.lang.Throwable) ie);
00038           }
00039      }
00040      
00041      public boolean attempt (int msecs)
00042      {
00043           java.lang.Object ie = null;
00044           synchronized (this)
00045           {
00046                if (msecs <= 0)
00047                {
00048                     return this.wprw.startRead();
00049                } else
00050                {
00051                     if (this.wprw.startReadFromNewReader())
00052                     {
00053                          return true;
00054                     } else
00055                     {
00056                          int waitTime = msecs;
00057                          int start = java.lang.System.currentTimeMillis();
00058                          for (; true; )
00059                          {
00060                               try {
00061                                    this.wait(waitTime);
00062                               }
00063                               catch (java.lang.InterruptedException ex) {
00064                                    this.wprw.cancelledWaitingReader();
00065                                    ie = ex;
00066                                    break;
00067                               }
00068                               if (this.wprw.startReadFromWaitingReader())
00069                               {
00070                                    return true;
00071                               } else
00072                               {
00073                                    waitTime = (msecs - (java.lang.System.currentTimeMillis() - start));
00074                                    if (waitTime <= 0)
00075                                    {
00076                                         this.wprw.cancelledWaitingReader();
00077                                         break;
00078                                    }
00079                               }
00080                          }
00081                     }
00082                }
00083           }
00084           this.wprw.writerLock_.signalWaiters();
00085           if (ie != null)
00086           {
00087                throw ((java.lang.Throwable) ie);
00088           } else
00089           {
00090                return false;
00091           }
00092      }
00093      
00094      public void release ()
00095      {
00096           Signaller s = this.wprw.endRead();
00097           if (s != null)
00098           {
00099                s.signalWaiters();
00100           }
00101      }
00102      
00103      synchronized void signalWaiters ()
00104      {
00105           this.notifyAll();
00106      }
00107 }

Generated at Thu Feb 7 06:53:41 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001