Skip to content

Commit

Permalink
debug Destructor #131
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Nov 15, 2019
1 parent 6a606a8 commit 7d1f9b1
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 98 deletions.
6 changes: 3 additions & 3 deletions FreeSql.DbContext/DbContext/DbContext.cs
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Threading;

namespace FreeSql
{
Expand Down Expand Up @@ -200,11 +201,10 @@ internal class ExecCommandInfo
#endregion

~DbContext() => this.Dispose();
bool _isdisposed = false;
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
_isdisposed = true;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
_actions.Clear();
Expand Down
6 changes: 3 additions & 3 deletions FreeSql.DbContext/DbSet/DbSet.cs
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;

namespace FreeSql
{
Expand Down Expand Up @@ -36,11 +37,10 @@ protected virtual ISelect<TEntity> OrmSelect(object dywhere)
}

~DbSet() => this.Dispose();
bool _isdisposed = false;
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
_isdisposed = true;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
this._dicUpdateTimes.Clear();
Expand Down
10 changes: 2 additions & 8 deletions FreeSql.DbContext/Repository/DataFilter/DataFilter.cs
Expand Up @@ -144,10 +144,7 @@ public bool IsEnabled(string filterName)
return _filters.TryGetValue(filterName, out var tryfi) ? tryfi.IsEnabled : false;
}

~DataFilter()
{
this.Dispose();
}
~DataFilter() => this.Dispose();
public void Dispose()
{
_filters.Clear();
Expand All @@ -169,10 +166,7 @@ public class FluentDataFilter : IDisposable
return this;
}

~FluentDataFilter()
{
this.Dispose();
}
~FluentDataFilter() => this.Dispose();
public void Dispose()
{
_filters.Clear();
Expand Down
6 changes: 3 additions & 3 deletions FreeSql.DbContext/Repository/Repository/BaseRepository.cs
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

namespace FreeSql
Expand Down Expand Up @@ -42,11 +43,10 @@ protected BaseRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter,
}

~BaseRepository() => this.Dispose();
bool _isdisposed = false;
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
_isdisposed = true;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
_dbsetPriv?.Dispose();
Expand Down
22 changes: 12 additions & 10 deletions FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
Expand Up @@ -105,18 +105,20 @@ public void Rollback()

public DbContext.EntityChangeReport EntityChangeReport { get; } = new DbContext.EntityChangeReport();

~UnitOfWork()
{
this.Dispose();
}
bool _isdisposed = false;
~UnitOfWork() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
_isdisposed = true;
this.Rollback();
this.Close();
GC.SuppressFinalize(this);
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
this.Rollback();
this.Close();
}
finally
{
GC.SuppressFinalize(this);
}
}
}
}
Expand Up @@ -120,14 +120,11 @@ public void Transaction(Action handler, TimeSpan timeout)
}
}

~AdoProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~AdoProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
Transaction2[] trans = null;
Expand Down
Expand Up @@ -10,6 +10,7 @@
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FreeSql.Internal.CommonProvider
Expand Down Expand Up @@ -38,11 +39,10 @@ public abstract partial class Select0Provider<TSelect, T1> : ISelect0<TSelect, T
protected List<LambdaExpression> _whereCascadeExpression = new List<LambdaExpression>();
protected List<GlobalFilter.Item> _whereGlobalFilter;

bool _isDisponse = false;
int _disposeCounter;
~Select0Provider()
{
if (_isDisponse) return;
_isDisponse = false;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
_where.Clear();
_params.Clear();
_tables.Clear();
Expand Down
10 changes: 4 additions & 6 deletions Providers/FreeSql.Provider.MySql/MySqlProvider.cs
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
using System.Threading;

namespace FreeSql.MySql
{
Expand Down Expand Up @@ -73,14 +74,11 @@ public MySqlProvider(string masterConnectionString, string[] slaveConnectionStri

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~MySqlProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~MySqlProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
14 changes: 6 additions & 8 deletions Providers/FreeSql.Provider.Odbc/Default/OdbcProvider.cs
@@ -1,10 +1,11 @@
using FreeSql.Internal;
using FreeSql.Internal.CommonProvider;
using FreeSql.Odbc.Default;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using FreeSql.Odbc.Default;
using System.Threading;

namespace FreeSql.Odbc.Default
{
Expand Down Expand Up @@ -86,14 +87,11 @@ public OdbcProvider(string masterConnectionString, string[] slaveConnectionStrin

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OdbcProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OdbcProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
try
{
(this.Ado as AdoProvider)?.Dispose();
Expand Down
10 changes: 4 additions & 6 deletions Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlProvider.cs
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
using System.Threading;

namespace FreeSql.Odbc.MySql
{
Expand Down Expand Up @@ -51,14 +52,11 @@ public OdbcMySqlProvider(string masterConnectionString, string[] slaveConnection

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OdbcMySqlProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OdbcMySqlProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
10 changes: 4 additions & 6 deletions Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleProvider.cs
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading;

namespace FreeSql.Odbc.Oracle
{
Expand Down Expand Up @@ -52,14 +53,11 @@ public OdbcOracleProvider(string masterConnectionString, string[] slaveConnectio

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OdbcOracleProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OdbcOracleProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
Expand Up @@ -2,6 +2,7 @@
using FreeSql.Internal.CommonProvider;
using System;
using System.Collections.Generic;
using System.Threading;

namespace FreeSql.Odbc.PostgreSQL
{
Expand Down Expand Up @@ -49,14 +50,11 @@ public OdbcPostgreSQLProvider(string masterConnectionString, string[] slaveConne

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OdbcPostgreSQLProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OdbcPostgreSQLProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
Expand Up @@ -2,6 +2,7 @@
using FreeSql.Internal.CommonProvider;
using System;
using System.Collections.Generic;
using System.Threading;

namespace FreeSql.Odbc.SqlServer
{
Expand Down Expand Up @@ -57,14 +58,11 @@ public OdbcSqlServerProvider(string masterConnectionString, string[] slaveConnec

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OdbcSqlServerProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OdbcSqlServerProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
10 changes: 4 additions & 6 deletions Providers/FreeSql.Provider.Oracle/OracleProvider.cs
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading;

namespace FreeSql.Oracle
{
Expand Down Expand Up @@ -47,14 +48,11 @@ public OracleProvider(string masterConnectionString, string[] slaveConnectionStr

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~OracleProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~OracleProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down
10 changes: 4 additions & 6 deletions Providers/FreeSql.Provider.PostgreSQL/PostgreSQLProvider.cs
Expand Up @@ -11,6 +11,7 @@
using System.Linq.Expressions;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;

namespace FreeSql.PostgreSQL
{
Expand Down Expand Up @@ -100,14 +101,11 @@ public PostgreSQLProvider(string masterConnectionString, string[] slaveConnectio

public GlobalFilter GlobalFilter { get; } = new GlobalFilter();

~PostgreSQLProvider()
{
this.Dispose();
}
bool _isdisposed = false;
~PostgreSQLProvider() => this.Dispose();
int _disposeCounter;
public void Dispose()
{
if (_isdisposed) return;
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
(this.Ado as AdoProvider)?.Dispose();
}
}
Expand Down

0 comments on commit 7d1f9b1

Please sign in to comment.