Z3
src/api/java/IDecRefQueue.java
Go to the documentation of this file.
00001 
00018 package com.microsoft.z3;
00019 
00020 import java.util.LinkedList;
00021 
00022 abstract class IDecRefQueue
00023 {
00024         protected Object m_lock = new Object();
00025         protected LinkedList<Long> m_queue = new LinkedList<Long>();
00026         protected final int m_move_limit = 1024;
00027 
00028         protected abstract void incRef(Context ctx, long obj);
00029 
00030         protected abstract void decRef(Context ctx, long obj);
00031 
00032         protected void incAndClear(Context ctx, long o)
00033         {
00034                 incRef(ctx, o);
00035                 if (m_queue.size() >= m_move_limit)
00036                         clear(ctx);
00037         }
00038 
00039         protected void add(long o)
00040         {
00041                 if (o == 0)
00042                         return;
00043 
00044                 synchronized (m_lock)
00045                 {
00046                         m_queue.add(o);
00047                 }
00048         }
00049 
00050         protected void clear(Context ctx)
00051         {
00052                 synchronized (m_lock)
00053                 {
00054                         for (Long o : m_queue)
00055                                 decRef(ctx, o);
00056                         m_queue.clear();
00057                 }
00058         }
00059 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines