Skip to content

Commit

Permalink
Update Win binaries from latest master. Env file on Windows grows on …
Browse files Browse the repository at this point in the history
…demand, which is somewhat slower but much more usable.
  • Loading branch information
buybackoff committed Sep 2, 2018
1 parent e438a4e commit 3c27625
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Binary file modified lib/out/w64/bin/libspreads_lmdb.dll.compressed
Binary file not shown.
9 changes: 7 additions & 2 deletions src/Spreads.LMDB/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,23 @@ public void Read(Action<ReadOnlyTransaction, object> readAction, object state)
/// A thread can only use one transaction at a time, plus any child transactions. Each transaction belongs to one thread.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Do not use in async code: A thread can only use one transaction at a time, plus any child transactions. Each transaction belongs to one thread.")]
public Transaction BeginTransaction(TransactionBeginFlags flags = TransactionBeginFlags.ReadWrite)
{
if (((int)flags & (int)TransactionBeginFlags.ReadOnly) != 0)
{
throw new InvalidOperationException("Use BeginReadOnlyTransaction for readonly transactions");
ThrowShouldUseReadOnlyTxn();
}
var impl = TransactionImpl.Create(this, flags);
var txn = new Transaction(impl);
return txn;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowShouldUseReadOnlyTxn()
{
throw new InvalidOperationException("Use BeginReadOnlyTransaction for readonly transactions");
}

/// <summary>
/// ReadOnlyTransaction transaction must be disposed ASAP to avoid LMDB environment growth and allocating garbage.
/// </summary>
Expand Down
34 changes: 29 additions & 5 deletions src/Spreads.LMDB/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal Transaction(TransactionImpl txn)
/// All cursors opened within the transaction will be closed by this call.
/// The cursors and transaction handle will be freed and must not be used again after this call.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Commit()
{
_impl.Commit();
Expand All @@ -38,11 +39,13 @@ public void Commit()
/// All cursors opened within the transaction will be closed by this call.
/// The cursors and transaction handle will be freed and must not be used again after this call.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Abort()
{
_impl.Abort();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
_impl.Dispose();
Expand All @@ -63,6 +66,7 @@ internal ReadOnlyTransaction(TransactionImpl txn)
_impl = txn;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
_impl.Dispose();
Expand Down Expand Up @@ -265,29 +269,49 @@ internal static void ThrowlTransactionIsReadOnly(string message = null)
public bool IsReadOnly
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _readHandle != null; }
get => _readHandle != null;
}

/// <summary>
/// Current transaction state.
/// </summary>
internal TransactionState State => _state;
internal TransactionState State
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _state;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Commit()
{
if (_state != TransactionState.Active)
{
throw new InvalidOperationException("Transaction state is not active for commit");
ThrowTxNotActiveOnCommit();
}

if (IsReadOnly)
{
throw new InvalidOperationException("Cannot commit readonly transaction");
ThrowTxReadOnlyOnCommit();
}

NativeMethods.AssertExecute(NativeMethods.mdb_txn_commit(_writeHandle));
_state = TransactionState.Commited;
}


[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowTxNotActiveOnCommit()
{
throw new InvalidOperationException("Transaction state is not active for commit");
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowTxReadOnlyOnCommit()
{
throw new InvalidOperationException("Cannot commit readonly transaction");
}


public void Abort()
{
if (_state != TransactionState.Active)
Expand Down

0 comments on commit 3c27625

Please sign in to comment.