3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00
z3/src/api/java/IDecRefQueue.java
Christoph M. Wintersteiger 4bed5183f8 Made DRQ objects public in Java and .NET APIs.
Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
2015-01-30 21:58:43 -06:00

72 lines
1.2 KiB
Java

/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
IDecRefQueue.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import java.util.LinkedList;
public abstract class IDecRefQueue
{
protected Object m_lock = new Object();
protected LinkedList<Long> m_queue = new LinkedList<Long>();
protected int m_move_limit;
protected IDecRefQueue()
{
m_move_limit = 1024;
}
protected IDecRefQueue(int move_limit)
{
m_move_limit = move_limit;
}
public void setLimit(int l) { m_move_limit = l; }
protected abstract void incRef(Context ctx, long obj);
protected abstract void decRef(Context ctx, long obj);
protected void incAndClear(Context ctx, long o)
{
incRef(ctx, o);
if (m_queue.size() >= m_move_limit)
clear(ctx);
}
protected void add(long o)
{
if (o == 0)
return;
synchronized (m_lock)
{
m_queue.add(o);
}
}
protected void clear(Context ctx)
{
synchronized (m_lock)
{
for (Long o : m_queue)
decRef(ctx, o);
m_queue.clear();
}
}
}