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