未验证 提交 bf96002e 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #26269 from sharwell/defer-initialization

Defer loading of SQLite binaries until they will be used
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.SolutionSize;
using Microsoft.CodeAnalysis.SQLite;
......@@ -17,11 +15,6 @@ namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices
/// </remarks>
public class SQLitePersistentStorageTests : AbstractPersistentStorageTests
{
static SQLitePersistentStorageTests()
{
Assert.True(SQLitePersistentStorageService.TryInitializeLibraries());
}
internal override IPersistentStorageService GetStorageService(IPersistentStorageLocationService locationService, ISolutionSizeTracker solutionSizeTracker, IPersistentStorageFaultInjector faultInjector)
=> new SQLitePersistentStorageService(_persistentEnabledOptionService, locationService, solutionSizeTracker, faultInjector);
......
......@@ -23,7 +23,7 @@ internal partial class SQLitePersistentStorageService : AbstractPersistentStorag
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
internal static bool TryInitializeLibraries() => s_initialized.Value;
private static bool TryInitializeLibraries() => s_initialized.Value;
private static readonly Lazy<bool> s_initialized = new Lazy<bool>(() => TryInitializeLibrariesLazy());
......@@ -88,6 +88,13 @@ protected override string GetDatabaseFilePath(string workingFolderPath)
protected override bool TryOpenDatabase(
Solution solution, string workingFolderPath, string databaseFilePath, out IPersistentStorage storage)
{
if (!TryInitializeLibraries())
{
// SQLite is not supported on the current platform
storage = null;
return false;
}
// try to get db ownership lock. if someone else already has the lock. it will throw
var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath);
if (dbOwnershipLock == null)
......
......@@ -28,13 +28,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
switch (database)
{
case StorageDatabase.SQLite:
if (!SQLitePersistentStorageService.TryInitializeLibraries())
{
break;
}
var locationService = workspaceServices.GetService<IPersistentStorageLocationService>();
if (locationService != null)
{
return new SQLitePersistentStorageService(optionService, locationService, _solutionSizeTracker);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册