Skip to content

Commit

Permalink
* fixed transaction bug
Browse files Browse the repository at this point in the history
* proper locking in WeakOutputSet
  • Loading branch information
krauthaufen committed Jan 16, 2020
1 parent 0ee70d0 commit 277aed2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.0.16
* fixed transaction bug
* proper locking in WeakOutputSet

### 0.0.15
* consistent equality everywhere
* DefaultEqualityComparer.SetProvider allows to override default equality before first use
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Data.Adaptive/Core/AdaptiveObject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module AdadptiveObjectExtensions =
static val mutable private _Callbacks : list<unit -> unit>

static member Add(action : unit -> unit) =
if AdaptiveObject.UnsafeEvaluationDepth <= 0 then action()
if AdaptiveObject.UnsafeEvaluationDepth <= 0 then transact action
elif isNull (AfterEvaluateCallbacks._Callbacks :> obj) then AfterEvaluateCallbacks._Callbacks <- [action]
else AfterEvaluateCallbacks._Callbacks <- action :: AfterEvaluateCallbacks._Callbacks

Expand Down
14 changes: 9 additions & 5 deletions src/FSharp.Data.Adaptive/Core/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,19 @@ and internal WeakOutputSet() =
)

member x.Clear() =
data <- Unchecked.defaultof<_>
setOps <- 0
lock x (fun () ->
data <- Unchecked.defaultof<_>
setOps <- 0
)

/// Indicates whether the set is (conservatively) known to be empty.
/// Note that we don't dereference any WeakReferences here.
member x.IsEmpty =
match data.Tag with
| 0 -> isNull data.Single
| _ -> false
lock x (fun () ->
match data.Tag with
| 0 -> isNull data.Single
| _ -> false
)

interface IWeakOutputSet with
member x.IsEmpty = x.IsEmpty
Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Data.Adaptive/Core/Transaction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type Transaction() =
else
e.EnterWrite()
try
outputCount <- 0

// if the element is already outOfDate we
// do not traverse the graph further.
if e.OutOfDate then
Expand Down Expand Up @@ -159,7 +161,6 @@ type Transaction() =

else
e.OutOfDate <- false
outputCount <- 0
// if Mark told us not to continue we're done here
()

Expand All @@ -169,7 +170,6 @@ type Transaction() =
// mark it upToDate again (since it would otherwise not be processed again)
e.Level <- max e.Level newLevel
e.OutOfDate <- false

q.Enqueue(e.Level, e)

finally
Expand Down Expand Up @@ -208,7 +208,7 @@ module Transaction =
| Some c -> Some c
| None -> None

let using (t : Transaction) (action : unit -> 'T) =
let useTransaction (t : Transaction) (action : unit -> 'T) =
let old = Transaction.Current
try
Transaction.Current <- Some t
Expand Down

0 comments on commit 277aed2

Please sign in to comment.