コード例 #1
0
 @cli.System.Security.SecuritySafeCriticalAttribute.Annotation
 void release(FileDescriptor fd, long pos, long size) throws IOException {
     FileStream fs = (FileStream)fd.getStream();
     if (WINDOWS)
     {
         int ERROR_NOT_LOCKED = 158;
         OVERLAPPED o = new OVERLAPPED();
         o.OffsetLow = (int)pos;
         o.OffsetHigh = (int)(pos >> 32);
         int result = UnlockFileEx(fs.get_SafeFileHandle(), 0, (int)size, (int)(size >> 32), o);
         if (result == 0 && Marshal.GetLastWin32Error() != ERROR_NOT_LOCKED)
         {
             throw new IOException("Release failed");
         }
     }
     else
     {
         try
         {
             if (false) throw new cli.System.ArgumentOutOfRangeException();
             if (false) throw new cli.System.IO.IOException();
             if (false) throw new cli.System.ObjectDisposedException("");
             fs.Unlock(pos, size);
         }
         catch (cli.System.IO.IOException x)
         {
             if (!NotLockedHack.isErrorNotLocked(x))
             {
                 throw new IOException(x.getMessage());
             }
         }
         catch (cli.System.ArgumentOutOfRangeException
             | cli.System.ObjectDisposedException x)
         {
             throw new IOException(x.getMessage());
         }
     }
 }
コード例 #2
0
 @cli.System.Security.SecuritySafeCriticalAttribute.Annotation
 int lock(FileDescriptor fd, boolean blocking, long pos, long size,
          boolean shared) throws IOException
 {
     FileStream fs = (FileStream)fd.getStream();
     if (WINDOWS)
     {
         int LOCKFILE_FAIL_IMMEDIATELY = 1;
         int LOCKFILE_EXCLUSIVE_LOCK = 2;
         int ERROR_LOCK_VIOLATION = 33;
         int flags = 0;
         OVERLAPPED o = new OVERLAPPED();
         o.OffsetLow = (int)pos;
         o.OffsetHigh = (int)(pos >> 32);
         if (!blocking)
         {
             flags |= LOCKFILE_FAIL_IMMEDIATELY;
         }
         if (!shared)
         {
             flags |= LOCKFILE_EXCLUSIVE_LOCK;
         }
         int result = LockFileEx(fs.get_SafeFileHandle(), flags, 0, (int)size, (int)(size >> 32), o);
         if (result == 0)
         {
             int error = Marshal.GetLastWin32Error();
             if (!blocking && error == ERROR_LOCK_VIOLATION)
             {
                 return NO_LOCK;
             }
             throw new IOException("Lock failed");
         }
         return LOCKED;
     }
     else
     {
         try
         {
             if (false) throw new cli.System.ArgumentOutOfRangeException();
             for (;;)
             {
                 try
                 {
                     if (false) throw new cli.System.IO.IOException();
                     if (false) throw new cli.System.ObjectDisposedException("");
                     fs.Lock(pos, size);
                     return shared ? RET_EX_LOCK : LOCKED;
                 }
                 catch (cli.System.IO.IOException x)
                 {
                     if (!blocking)
                     {
                         return NO_LOCK;
                     }
                     cli.System.Threading.Thread.Sleep(100);
                 }
                 catch (cli.System.ObjectDisposedException x)
                 {
                     throw new IOException(x.getMessage());
                 }
             }
         }
         catch (cli.System.ArgumentOutOfRangeException x)
         {
             throw new IOException(x.getMessage());
         }
     }
 }