Skip to content

Commit

Permalink
Index: Monitor.Enter/Exit in all places
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 18, 2024
1 parent f69b07e commit 342335a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/FSharp.Data.Adaptive/Datastructures/Index.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ type Index private(real : IndexNode) =
member private x.Value = real

member x.After() =
lock real (fun () ->
Monitor.Enter real
let res =
let next = real.Next
if next <> real.Root then
lock next (fun () ->
next.RefCount <- next.RefCount + 1
)
Monitor.Enter next
next.RefCount <- next.RefCount + 1
Monitor.Exit next
next |> Index
else
real.InsertAfter() |> Index
)
Monitor.Exit real
res

member x.Before() =
let prev = real.Prev
Expand Down Expand Up @@ -200,9 +202,9 @@ type Index private(real : IndexNode) =
if next = r then
l.InsertAfter() |> Index
else
lock next (fun () ->
next.RefCount <- next.RefCount + 1
)
Monitor.Enter next
next.RefCount <- next.RefCount + 1
Monitor.Exit next
next |> Index

Monitor.Exit l
Expand Down

0 comments on commit 342335a

Please sign in to comment.