From ec4d737ef61f741a824702642828222914f6d94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Thu, 16 Mar 2017 14:34:18 +0100 Subject: [PATCH 1/2] Make incremental builder counter atomic --- src/fsharp/vs/IncrementalBuild.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fsharp/vs/IncrementalBuild.fs b/src/fsharp/vs/IncrementalBuild.fs index ec58257132..39fadd52cb 100755 --- a/src/fsharp/vs/IncrementalBuild.fs +++ b/src/fsharp/vs/IncrementalBuild.fs @@ -1367,7 +1367,7 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach let assertNotDisposed() = if disposed then System.Diagnostics.Debug.Assert(false, "IncrementalBuild object has already been disposed!") - let mutable referenceCount = 0 + let referenceCount = ref 0 //---------------------------------------------------- // START OF BUILD TASK FUNCTIONS @@ -1666,17 +1666,17 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach member this.IncrementUsageCount() = assertNotDisposed() - referenceCount <- referenceCount + 1 + System.Threading.Interlocked.Increment(referenceCount) |> ignore { new System.IDisposable with member x.Dispose() = this.DecrementUsageCount() } member this.DecrementUsageCount() = assertNotDisposed() - referenceCount <- referenceCount - 1 - if referenceCount = 0 then + System.Threading.Interlocked.Decrement(referenceCount) |> ignore + if !referenceCount = 0 then disposed <- true disposeCleanupItem() - member __.IsAlive = referenceCount > 0 + member __.IsAlive = !referenceCount > 0 member __.TcConfig = tcConfig member __.FileParsed = fileParsed.Publish @@ -1901,5 +1901,5 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach | Some builder -> builder.IncrementUsageCount() | None -> { new System.IDisposable with member __.Dispose() = () } - member builder.IsBeingKeptAliveApartFromCacheEntry = (referenceCount >= 2) + member builder.IsBeingKeptAliveApartFromCacheEntry = (!referenceCount >= 2) From 49345cb047273fc0a30a0f5e99ee788cb2bfef54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Thu, 16 Mar 2017 18:04:46 +0100 Subject: [PATCH 2/2] Small fixes --- src/fsharp/vs/IncrementalBuild.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fsharp/vs/IncrementalBuild.fs b/src/fsharp/vs/IncrementalBuild.fs index 39fadd52cb..0f28cf6038 100755 --- a/src/fsharp/vs/IncrementalBuild.fs +++ b/src/fsharp/vs/IncrementalBuild.fs @@ -1367,7 +1367,7 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach let assertNotDisposed() = if disposed then System.Diagnostics.Debug.Assert(false, "IncrementalBuild object has already been disposed!") - let referenceCount = ref 0 + let mutable referenceCount = 0 //---------------------------------------------------- // START OF BUILD TASK FUNCTIONS @@ -1666,17 +1666,17 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach member this.IncrementUsageCount() = assertNotDisposed() - System.Threading.Interlocked.Increment(referenceCount) |> ignore + System.Threading.Interlocked.Increment(&referenceCount) |> ignore { new System.IDisposable with member x.Dispose() = this.DecrementUsageCount() } member this.DecrementUsageCount() = assertNotDisposed() - System.Threading.Interlocked.Decrement(referenceCount) |> ignore - if !referenceCount = 0 then + let currentValue = System.Threading.Interlocked.Decrement(&referenceCount) + if currentValue = 0 then disposed <- true disposeCleanupItem() - member __.IsAlive = !referenceCount > 0 + member __.IsAlive = referenceCount > 0 member __.TcConfig = tcConfig member __.FileParsed = fileParsed.Publish @@ -1901,5 +1901,5 @@ type IncrementalBuilder(ctokCtor: CompilationThreadToken, frameworkTcImportsCach | Some builder -> builder.IncrementUsageCount() | None -> { new System.IDisposable with member __.Dispose() = () } - member builder.IsBeingKeptAliveApartFromCacheEntry = (!referenceCount >= 2) + member builder.IsBeingKeptAliveApartFromCacheEntry = (referenceCount >= 2)