Z3
IDecRefQueue.java
Go to the documentation of this file.
1 
18 package com.microsoft.z3;
19 
20 import java.util.LinkedList;
21 
22 public abstract class IDecRefQueue
23 {
24  protected Object m_lock = new Object();
25  protected LinkedList<Long> m_queue = new LinkedList<Long>();
26  protected int m_move_limit;
27 
28  protected IDecRefQueue()
29  {
30  m_move_limit = 1024;
31  }
32 
33  protected IDecRefQueue(int move_limit)
34  {
35  m_move_limit = move_limit;
36  }
37 
38  public void setLimit(int l) { m_move_limit = l; }
39 
40  protected abstract void incRef(Context ctx, long obj);
41 
42  protected abstract void decRef(Context ctx, long obj);
43 
44  protected void incAndClear(Context ctx, long o)
45  {
46  incRef(ctx, o);
47  if (m_queue.size() >= m_move_limit)
48  clear(ctx);
49  }
50 
51  protected void add(long o)
52  {
53  if (o == 0)
54  return;
55 
56  synchronized (m_lock)
57  {
58  m_queue.add(o);
59  }
60  }
61 
62  protected void clear(Context ctx)
63  {
64  synchronized (m_lock)
65  {
66  for (Long o : m_queue)
67  decRef(ctx, o);
68  m_queue.clear();
69  }
70  }
71 }
void incAndClear(Context ctx, long o)
abstract void incRef(Context ctx, long obj)
LinkedList< Long > m_queue
abstract void decRef(Context ctx, long obj)