Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d572ea

Browse files
Use a ConcurrentDictionary to remember which calls did work (#1147)
1 parent b84a28d commit 9d572ea

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

‎src/FirebirdSql.Data.FirebirdClient/Client/Native/FbClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static IFbClient Create(string dllName)
8383
{
8484
result = BuildFbClient(dllName);
8585
cache.Add(dllName, result);
86-
ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(() => result.fb_shutdown(0, 0)));
86+
ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(nameof(IFbClient.fb_shutdown),() => result.fb_shutdown(0, 0)));
8787
return result;
8888
}
8989
finally

‎src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ public override void Execute(int timeout, IDescriptorFiller descriptorFiller)
371371
descriptorFiller.Fill(_parameters, 0);
372372

373373
ClearStatusVector();
374-
NativeHelpers.CallIfExists(() =>
375-
{
376-
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
377-
_database.ProcessStatusVector(_statusVector);
378-
});
374+
NativeHelpers.CallIfExists(
375+
nameof(IFbClient.fb_dsql_set_timeout),
376+
() =>
377+
{
378+
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
379+
_database.ProcessStatusVector(_statusVector);
380+
});
379381

380382
ClearStatusVector();
381383

@@ -441,11 +443,13 @@ public override async ValueTask ExecuteAsync(int timeout, IDescriptorFiller desc
441443
await descriptorFiller.FillAsync(_parameters, 0, cancellationToken).ConfigureAwait(false);
442444

443445
ClearStatusVector();
444-
NativeHelpers.CallIfExists(() =>
445-
{
446-
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
447-
_database.ProcessStatusVector(_statusVector);
448-
});
446+
NativeHelpers.CallIfExists(
447+
nameof(IFbClient.fb_dsql_set_timeout),
448+
() =>
449+
{
450+
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
451+
_database.ProcessStatusVector(_statusVector);
452+
});
449453

450454
ClearStatusVector();
451455

‎src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@
1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

1818
using System;
19+
using System.Collections.Concurrent;
1920

2021
namespace FirebirdSql.Data.Common;
2122

2223
internal static class NativeHelpers
2324
{
24-
public static void CallIfExists(Action action)
25+
private static readonly ConcurrentDictionary<string, bool> _cache = new ConcurrentDictionary<string, bool>(StringComparer.Ordinal);
26+
27+
public static void CallIfExists(string actionId, Action action)
2528
{
26-
try
29+
if (!_cache.TryGetValue(actionId, out var executionAllowed))
30+
{
31+
try
32+
{
33+
action();
34+
_cache.TryAdd(actionId, true);
35+
}
36+
catch (EntryPointNotFoundException)
37+
{
38+
_cache.TryAdd(actionId, false);
39+
}
40+
}
41+
else if (executionAllowed)
2742
{
2843
action();
2944
}
30-
catch (EntryPointNotFoundException)
31-
{ }
3245
}
3346
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /