public override void Unlock() { if (locked_count <= 0) { throw new ApplicationException("locked_count <= 0"); } if (locked_count == 1) { Unisys.Close(this.fs); this.fs = IntPtr.Zero; } locked_count--; }
public override void Lock() { if (locked_count == 0) { IO.MakeDirIfNotExists(Env.UnixMutantDir); Unisys.Permissions perm = Unisys.Permissions.S_IRUSR | Unisys.Permissions.S_IWUSR | Unisys.Permissions.S_IRGRP | Unisys.Permissions.S_IWGRP | Unisys.Permissions.S_IROTH | Unisys.Permissions.S_IWOTH; IntPtr f = Unisys.Open(filename, Unisys.OpenFlags.O_CREAT, (int)perm); if (f.ToInt64() < 0) { throw new IOException("Open failed."); } if (Unisys.FLock(f, Unisys.LockOperations.LOCK_EX) == -1) { throw new IOException("FLock failed."); } this.fs = f; locked_count++; } }