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