mirror of
https://github.com/Z3Prover/z3
synced 2025-04-26 18:45:33 +00:00
remove DecRefQueue, use Z3_enable_concurrent_dec_ref (#6332)
The notion of reference counted contexts never worked. The reference count to a context only ends up being 0 if the GC kicks in and disposes the various z3 objects. A call to Dispose on Context should free up all resources associated with that context. In exchange none of the resources are allowed any other operation than DecRef. The invocations of DecRef are protected by a lock and test on the context that the native pointer associated with the context is non-zero. Dispose sets the native pointer to zero. Z3_enable_concurrent_dec_ref ensures that: - calls to decref are thread safe. Other threads can operate on the context without interference. The Z3_context ensures that - z3objects allocated, but not disposed during the lifetime of Z3_context are freed when Z3_context is deleted (it triggers a debug warning, but this is now benign).
This commit is contained in:
parent
3c8c80bbac
commit
edeeded4ea
17 changed files with 114 additions and 460 deletions
|
@ -107,34 +107,18 @@ namespace Microsoft.Z3
|
|||
Debug.Assert(ctx != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DecRefQueue
|
||||
/// </summary>
|
||||
internal class DecRefQueue : IDecRefQueue
|
||||
{
|
||||
public DecRefQueue() : base() { }
|
||||
public DecRefQueue(uint move_limit) : base(move_limit) { }
|
||||
internal override void IncRef(Context ctx, IntPtr obj)
|
||||
{
|
||||
Native.Z3_tactic_inc_ref(ctx.nCtx, obj);
|
||||
}
|
||||
|
||||
internal override void DecRef(Context ctx, IntPtr obj)
|
||||
{
|
||||
Native.Z3_tactic_dec_ref(ctx.nCtx, obj);
|
||||
}
|
||||
};
|
||||
|
||||
internal override void IncRef(IntPtr o)
|
||||
{
|
||||
Context.Tactic_DRQ.IncAndClear(Context, o);
|
||||
base.IncRef(o);
|
||||
Native.Z3_tactic_inc_ref(Context.nCtx, o);
|
||||
}
|
||||
|
||||
internal override void DecRef(IntPtr o)
|
||||
{
|
||||
Context.Tactic_DRQ.Add(o);
|
||||
base.DecRef(o);
|
||||
lock (Context)
|
||||
{
|
||||
if (Context.nCtx != IntPtr.Zero)
|
||||
Native.Z3_tactic_dec_ref(Context.nCtx, o);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue