Skip to content
Permalink
Browse files

[Core.IO] Disable LockFile code from macOS (not supported)

  • Loading branch information
xen2 committed Jan 14, 2019
1 parent cd609ad commit 661bd8513bb2e6aeae4e141c42322bc33568d8d7
Showing with 9 additions and 6 deletions.
  1. +9 −6 sources/core/Xenko.Core.Serialization/IO/Store.cs
@@ -15,6 +15,9 @@ namespace Xenko.Core.IO
/// <typeparam name="T">The type of elements in the store.</typeparam>
public abstract class Store<T> : IDisposable where T : new()
{
// macOS doesn't support Lock/Unlock (https://github.com/dotnet/corefx/issues/5964)
private static readonly bool LockEnabled = Platform.Type != PlatformType.macOS;

protected Stream stream;

protected int transaction;
@@ -130,7 +133,7 @@ private void SaveValues(IEnumerable<T> values, int currentTransaction)

// Acquire lock on end of file (for appending)
// This will prevent another thread from writing at the same time, or reading before it is flushed.
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.LockFile((FileStream)stream, indexStreamPosition, long.MaxValue - indexStreamPosition, true);

try
@@ -159,7 +162,7 @@ private void SaveValues(IEnumerable<T> values, int currentTransaction)
}
finally
{
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.UnlockFile((FileStream)stream, indexStreamPosition, long.MaxValue - indexStreamPosition);
}
}
@@ -176,7 +179,7 @@ private void SaveValue(T item, int currentTransaction)

// Acquire lock on end of file (for appending)
// This will prevent another thread from writing at the same time, or reading before it is flushed.
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.LockFile((FileStream)stream, indexStreamPosition, long.MaxValue - indexStreamPosition, true);

try
@@ -199,7 +202,7 @@ private void SaveValue(T item, int currentTransaction)
}
finally
{
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.UnlockFile((FileStream)stream, indexStreamPosition, long.MaxValue - indexStreamPosition);
}
}
@@ -272,7 +275,7 @@ public bool LoadNewValues()
// Note: Maybe we should release the lock quickly so that two threads can read at the same time?
// Or if the previously described case doesn't happen, maybe no lock at all is required?
// Otherwise, last possibility would be deterministic filesize (with size encoded at the beginning of each block).
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.LockFile((FileStream)stream, position, long.MaxValue - position, false);

try
@@ -284,7 +287,7 @@ public bool LoadNewValues()
finally
{
// Release the lock
if (stream is FileStream)
if (LockEnabled && stream is FileStream)
NativeLockFile.UnlockFile((FileStream)stream, position, long.MaxValue - position);
}

0 comments on commit 661bd85

Please sign in to comment.
You can’t perform that action at this time.