Skip to content

Commit

Permalink
Fix race during prepare_runtime. (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed May 12, 2022
1 parent 9395005 commit 26ff040
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,24 +490,24 @@ static void prepare_runtime(int* ret)
{
// Lock and check if the needed export was already acquired.
enter_lock(&_prepare_lock);
if (get_managed_export_fptr)
return;

char_t buffer[DNNE_MAX_PATH];
const char_t assembly_filename[] = DNNE_STR(DNNE_TOSTRING(DNNE_ASSEMBLY_NAME)) DNNE_STR(".dll");
const char_t* assembly_path = NULL;
int rc = get_current_dir_filepath(DNNE_ARRAY_SIZE(buffer), buffer, DNNE_ARRAY_SIZE(assembly_filename), assembly_filename, &assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);
if (!get_managed_export_fptr)
{
char_t buffer[DNNE_MAX_PATH];
const char_t assembly_filename[] = DNNE_STR(DNNE_TOSTRING(DNNE_ASSEMBLY_NAME)) DNNE_STR(".dll");
const char_t* assembly_path = NULL;
int rc = get_current_dir_filepath(DNNE_ARRAY_SIZE(buffer), buffer, DNNE_ARRAY_SIZE(assembly_filename), assembly_filename, &assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);

// Load HostFxr and get exported hosting functions.
rc = load_hostfxr(assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);
// Load HostFxr and get exported hosting functions.
rc = load_hostfxr(assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);

// Initialize and start the runtime.
rc = init_dotnet(assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);
// Initialize and start the runtime.
rc = init_dotnet(assembly_path);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, rc, &_prepare_lock);

assert(get_managed_export_fptr != NULL);
assert(get_managed_export_fptr != NULL);
}
exit_lock(&_prepare_lock);
}

Expand Down
7 changes: 4 additions & 3 deletions test/ExportingAssembly/ExportingAssembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RollForward>Major</RollForward>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Disable warnings about missing comments -->
<NoWarn>1591</NoWarn>

<!--
Defining RID(s) in the project enable specifying the bitness of the native binary.
See repository readme.md for more details.
Expand All @@ -22,9 +26,6 @@
<DnneCompilerCommand Condition="'$(BuildWithGCC)'=='true'">gcc</DnneCompilerCommand>
<DnneCompilerCommand Condition="'$(BuildWithGPP)'=='true'">g++</DnneCompilerCommand>
<DnneCompilerCommand Condition="'$(BuildWithClangPP)'=='true'">clang++</DnneCompilerCommand>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Disable warnings about missing comments -->
<NoWarn>1591</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(TestNuPkg)' == 'true' AND '$(RefLocalBuild)'=='true'">
Expand Down
4 changes: 2 additions & 2 deletions test/test.proj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

<Target Name="Build">
<Message Text="Building dnne-pkg" Importance="high" />
<Exec Command="dotnet build $([MSBuild]::NormalizePath($(DnnePkgDir)))" />
<Exec Command="dotnet build $([MSBuild]::NormalizePath($(DnnePkgDir))) -c $(Configuration)" />

<Message Text="Building ExportingAssembly" Importance="high" />
<Exec Command="dotnet build $([MSBuild]::NormalizePath($(ExportingAssemblyDir)))" />
<Exec Command="dotnet build $([MSBuild]::NormalizePath($(ExportingAssemblyDir))) -c $(Configuration)" />

<Message Text="Generating ImportingProcess" Importance="high" />
<Exec Command="cmake -S &quot;$([MSBuild]::NormalizePath($(ImportingProcessDir)))&quot; -B &quot;$([MSBuild]::NormalizePath($(NativeBuildDir)))&quot;" />
Expand Down

0 comments on commit 26ff040

Please sign in to comment.