IndexedInstantiationInformation::~IndexedInstantiationInformation() {
  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    decrease(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
}
IndexedInstantiationInformation& IndexedInstantiationInformation::operator=(const IndexedInstantiationInformation& rhs) {

  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    decrease(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
  
  m_index = rhs.m_index;
  
  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    increase(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
  return *this;
}
Example #3
0
void ReferenceCountManager::decrease(uint& ref, uint targetId) {
  Q_ASSERT(ref > 0);
  Q_ASSERT(shouldDoDUChainReferenceCounting(this));
  Q_ASSERT(!oldReferences->findIndex(ReferenceCountItem(m_id, targetId)));
  uint refIndex = references->findIndex(ReferenceCountItem(m_id, targetId));
  Q_ASSERT(refIndex);
  --ref;
  references->deleteItem(refIndex);
  oldReferences->index(ReferenceCountItem(m_id, targetId));
}
Example #4
0
void ReferenceCountManager::increase(uint& ref, uint targetId) {
  Q_ASSERT(shouldDoDUChainReferenceCounting(this));
  Q_ASSERT(!references->findIndex(ReferenceCountItem(m_id, targetId)));
  ++ref;

  {
    int oldIndex = oldReferences->findIndex(ReferenceCountItem(m_id, targetId));
    if(oldIndex)
      oldReferences->deleteItem(oldIndex);
  }

  Q_ASSERT(references->index(ReferenceCountItem(m_id, targetId)));
}
Example #5
0
void KDevelop::enableDUChainReferenceCounting(void* start, unsigned int size)
{
  QMutexLocker lock(&refCountingLock);

  doReferenceCounting = true;

  if(refCountingFirstRangeStart && ((char*)refCountingFirstRangeStart) <= (char*)start && (char*)start < ((char*)refCountingFirstRangeStart) + refCountingFirstRangeExtent.first)
  {
    //Increase the count for the first range
    ++refCountingFirstRangeExtent.second;
  }else if(refCountingHasAdditionalRanges || refCountingFirstRangeStart)
  {
    //There is additional ranges in the ranges-structure. Add any new ranges there as well.
    QMap< void*, QPair<uint, uint> >::iterator it = refCountingRanges->upperBound(start);
    if(it != refCountingRanges->begin()) {
      --it;
      if(((char*)it.key()) <= (char*)start && (char*)start < ((char*)it.key()) + it.value().first)
      {
        //Contained, count up
      }else{
        it = refCountingRanges->end(); //Insert own item
      }
    }else if(it != refCountingRanges->end() && it.key() > start) {
      //The item is behind
      it = refCountingRanges->end();
    }

    if(it == refCountingRanges->end()) {
      QMap< void*, QPair<uint, uint> >::iterator inserted = refCountingRanges->insert(start, qMakePair(size, 1u));
      //Merge following ranges
      QMap< void*, QPair<uint, uint> >::iterator it = inserted;
      ++it;
      while(it != refCountingRanges->end() && it.key() < ((char*)start) + size) {

        inserted.value().second += it.value().second; //Accumulate count
        if(((char*)start) + size < ((char*)inserted.key()) + it.value().first) {
          //Update end position
          inserted.value().first = (((char*)inserted.key()) + it.value().first) - ((char*)start);
        }

        it = refCountingRanges->erase(it);
      }
    }else{
      ++it.value().second;
      if(it.value().first < size)
        it.value().first = size;
    }

    refCountingHasAdditionalRanges = true;
  }else{
    refCountingFirstRangeStart = start;
    refCountingFirstRangeExtent.first = size;
    refCountingFirstRangeExtent.second = 1;
  }

  Q_ASSERT(refCountingHasAdditionalRanges == (refCountingRanges && !refCountingRanges->isEmpty()));
#ifdef TEST_REFERENCE_COUNTING
  Q_ASSERT(shouldDoDUChainReferenceCounting(start));
  Q_ASSERT(shouldDoDUChainReferenceCounting(((char*)start + (size-1))));
#endif
}