Exemplo n.º 1
0
/// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
const String GFXPrimitiveBuffer::describeSelf() const
{
#if defined(TORQUE_DEBUG) && defined(TORQUE_ENABLE_PROFILER)  
   return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s", 
      mIndexCount, mPrimitiveCount, getRefCount(), mDebugCreationPath.c_str());
#else      
   return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s", 
      mIndexCount, mPrimitiveCount, getRefCount(), "");
#endif   
}
Exemplo n.º 2
0
void Client::releaseConfig(Config* config)
{
    _impl->server->releaseConfig(config);
    if (!disconnectServer(_impl->server))
        LBERROR << "Client::disconnectServer failed" << std::endl;
    _impl->server = 0;
    exitLocal();

    LBASSERTINFO(getRefCount() == 1, "Client still referenced by "
                                         << getRefCount() - 1);
}
Exemplo n.º 3
0
Animation::Animation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, unsigned int type)
    : _controller(Game::getInstance()->getAnimationController()), _id(id), _duration(0), _defaultClip(NULL), _clips(NULL)
{
    createChannel(target, propertyId, keyCount, keyTimes, keyValues, keyInValue, keyOutValue, type);
    // Release the animation because a newly created animation has a ref count of 1 and the channels hold the ref to animation.
    release();
    assert(getRefCount() == 1);
}
Exemplo n.º 4
0
bool Object :: remove()
 { if(getRefCount() < 2)
    { LOG_DEBUG("%s: Remove destructor id - %i", getClassName(), getId());
      delete this;
      return true;
    }
   return false;
 }
Exemplo n.º 5
0
//==============================================================================
AutoPtr<SynchronizedObject> Writer::getLock() const
{
	// Note: As we are returning a AutoPtr, it is imperative that
	// our reference count is not zero if the lock is pointing
	// at this object
	SynchronizedObject* pLock = m_rpLock;
	QC_DBG_ASSERT((Writer*) pLock != this || getRefCount());
	return pLock;
}
void IndexFileDeleter::incRef(const vector<string>& files) {
  int32_t size = files.size();
  for(int32_t i=0;i<size;i++) {
    const string& fileName = files[i];
    RefCount* rc = getRefCount(fileName.c_str());
    if (infoStream != NULL && VERBOSE_REF_COUNTS) {
      message(string("  IncRef \"") + fileName + "\": pre-incr count is " + Misc::toString((int32_t)rc->count));
    }
    rc->IncRef();
  }
}
Exemplo n.º 7
0
void Client::exitClient()
{
    _impl->queue.flush();
    bool ret = exitLocal();
    LBINFO << "Exit " << lunchbox::className( this ) << " process used "
           << getRefCount() << std::endl;

    if( !eq::exit( ))
        ret = false;
    ::exit( ret ? EXIT_SUCCESS : EXIT_FAILURE );
}
void IndexFileDeleter::decRef(const string& fileName) {
  RefCount* rc = getRefCount(fileName.c_str());
  if (infoStream != NULL && VERBOSE_REF_COUNTS) {
    message(string("  DecRef \"") + fileName + "\": pre-decr count is " + Misc::toString((int32_t)rc->count));
  }
  if (0 == rc->DecRef()) {
    // This file is no int32_t64_ter referenced by any past
    // commit point32_ts nor by the in-memory SegmentInfos:
    deleteFile(fileName.c_str());
    refCounts.remove((char*)fileName.c_str());
  }
}
/****************************************************************************
Desc:	Get a new block using an exising or newly allocated block from
		the cache.  Initializes the block.  May be leaf or non-leaf
		but NOT the root block.
****************************************************************************/
RCODE F_BtreeRoot::newBlk(
    F_BtreeBlk **	ppBlk,
    eDynRSetBlkTypes		eBlkType)
{
    RCODE			rc = NE_FLM_OK;
    FLMUINT		uiLRUValue = (FLMUINT)~0;
    FLMUINT		uiPos;
    FLMUINT		uiLRUPos = 0;
    F_BtreeBlk *	pNewBlk;

    for (uiPos = 0; uiPos < FBTREE_CACHE_BLKS; uiPos++)
    {

        // The ref count is used for pinning the block.

        if (getRefCount() == 1 &&
                uiLRUValue > m_CacheBlks[uiPos].uiLRUValue)
        {
            uiLRUValue = m_CacheBlks[uiPos].uiLRUValue;
            uiLRUPos = uiPos;
        }

        // use the first hole.

        if (m_CacheBlks[uiPos].pBlk == NULL)
        {
            uiLRUPos = uiPos;
            break;
        }
    }
    uiPos = uiLRUPos;
    if (RC_BAD( rc = newCacheBlk( uiPos, &pNewBlk, eBlkType)))
    {
        goto Exit;
    }

    pNewBlk->blkAddr( newBlkAddr());
    m_CacheBlks[uiPos].uiBlkAddr = pNewBlk->blkAddr();
    m_CacheBlks[uiPos].uiLRUValue = m_uiLRUCount++;

    pNewBlk->entryCount(0);
    pNewBlk->lemBlk(  FBTREE_END);
    pNewBlk->nextBlk( FBTREE_END);
    pNewBlk->prevBlk( FBTREE_END);
    *ppBlk = pNewBlk;

Exit:

    return( rc);
}
void IndexFileDeleter::incRef(SegmentInfos* segmentInfos, bool isCommit) {
  int32_t size = segmentInfos->size();
  for(int32_t i=0;i<size;i++) {
    SegmentInfo* segmentInfo = segmentInfos->info(i);
    if (segmentInfo->dir == directory) {
      incRef(segmentInfo->files());
    }
  }

  if (isCommit) {
    // Since this is a commit point32_t, also incref its
    // segments_N file:
    getRefCount(segmentInfos->getCurrentSegmentFileName().c_str())->IncRef();
  }
}
Exemplo n.º 11
0
int32 String::checkToClearAndAlloc(int32 nNewLength)
{
    if (getRefCount() <= 1)
    {
        internalAlloc(nNewLength);
    }
    else
    {
        release();
        
        internalAlloc(nNewLength);
    }
    
    return nNewLength;
}
Exemplo n.º 12
0
IpcMessageRefCount CmpMessageObj::decrRefCount() 
{
  if (getRefCount()==1) 
    {
      if (h_) 
	{
          destroyMe();
	  h_->deallocateMemory(this);
        }
      else
	delete this;
      return 0;
    }

  return IpcMessageObj::decrRefCount();
}
Exemplo n.º 13
0
IpcMessageRefCount ExEspMsgObj::decrRefCount()
{
  if (getRefCount() == 1)
    {
      // IpcMessageObj::decrRefCount() would delete the object by calling
      // global operator delete (since IpcMessageObj doesn't have an
      // operator delete). However, if we code the "delete this" statement
      // in this context we will pick up the correct operator delete.
      delete this;
      return 0;
    }
  else
    {
      // normal case, object won't be deleted
      return IpcMessageObj::decrRefCount();
    }
}
Exemplo n.º 14
0
bool Application::exit()
{
    bool retVal = true;
    if( _impl )
        retVal = _impl->exit();

    if( !exitLocal( ))
        retVal = false;

    if( !eq::exit( ))
        retVal = false;

    exitErrors();
    delete _impl;
    _impl = 0;

    LBASSERTINFO( getRefCount() == 1, this->getRefCount( ));
    return retVal;
}
Exemplo n.º 15
0
int32 String::checkToCopyAndAlloc(int32 nNewLength)
{
    if (getRefCount() <= 1)
    {
        internalAlloc(nNewLength);
    }
    else
    {
        XCHAR * pStrOld = m_pString;
        int32 nOldLength = getLength();
        
        release();
        
        internalAlloc(nNewLength);
        xMemoryCopy(m_pString, pStrOld, sizeof(XCHAR)*nOldLength);
    }
    
    return nNewLength;
}
IndexFileDeleter::IndexFileDeleter(Directory* directory, IndexDeletionPolicy* policy,
  SegmentInfos* segmentInfos, std::ostream* infoStream, DocumentsWriter* docWriter):
  refCounts( RefCountsType(true,true) ), commits(CommitsType(true))
{
	this->docWriter = docWriter;
	this->infoStream = infoStream;

	if (infoStream != NULL)
	  message( string("init: current segments file is \"") + segmentInfos->getCurrentSegmentFileName() + "\"; deletionPolicy=" + policy->getObjectName());

	this->policy = policy;
	this->directory = directory;
  CommitPoint* currentCommitPoint = NULL;

	// First pass: walk the files and initialize our ref
	// counts:
	int64_t currentGen = segmentInfos->getGeneration();
	const IndexFileNameFilter* filter = IndexFileNameFilter::getFilter();

	vector<string> files;
  if ( !directory->list(&files) )
	  _CLTHROWA(CL_ERR_IO, (string("cannot read directory ") + directory->toString() + ": list() returned NULL").c_str());


	for(size_t i=0;i<files.size();i++) {

	  string& fileName = files.at(i);

    if (filter->accept(NULL, fileName.c_str()) && fileName.compare(IndexFileNames::SEGMENTS_GEN) != 0) {

	    // Add this file to refCounts with initial count 0:
	    getRefCount(fileName.c_str());

	    if ( strncmp(fileName.c_str(), IndexFileNames::SEGMENTS, strlen(IndexFileNames::SEGMENTS)) == 0 ) {

	      // This is a commit (segments or segments_N), and
	      // it's valid (<= the max gen).  Load it, then
	      // incref all files it refers to:
	      if (SegmentInfos::generationFromSegmentsFileName(fileName.c_str()) <= currentGen) {
	        if (infoStream != NULL) {
	          message("init: load commit \"" + fileName + "\"");
	        }
	        SegmentInfos sis;
          bool failed = false;
	        try {
	          sis.read(directory, fileName.c_str());
	        } catch (CLuceneError& e) {
            if ( e.number() != CL_ERR_IO ){
              throw e;
            }
	          // LUCENE-948: on NFS (and maybe others), if
	          // you have writers switching back and forth
	          // between machines, it's very likely that the
	          // dir listing will be stale and will claim a
	          // file segments_X exists when in fact it
	          // doesn't.  So, we catch this and handle it
	          // as if the file does not exist
	          if (infoStream != NULL) {
	            message("init: hit FileNotFoundException when loading commit \"" + fileName + "\"; skipping this commit point32_t");
	          }
	          failed = true;
	        }
	        if (!failed) {
	          CommitPoint* commitPoint = _CLNEW CommitPoint(this,&sis);
	          if (sis.getGeneration() == segmentInfos->getGeneration()) {
	            currentCommitPoint = commitPoint;
	          }
	          commits.push_back(commitPoint);
	          incRef(&sis, true);
	        }
	      }
	    }
	  }
	}

	if (currentCommitPoint == NULL) {
	  // We did not in fact see the segments_N file
	  // corresponding to the segmentInfos that was passed
	  // in.  Yet, it must exist, because our caller holds
	  // the write lock.  This can happen when the directory
	  // listing was stale (eg when index accessed via NFS
	  // client with stale directory listing cache).  So we
	  // try now to explicitly open this commit point32_t:
	  SegmentInfos sis;
	  try {
	    sis.read(directory, segmentInfos->getCurrentSegmentFileName().c_str());
	  } catch (CLuceneError& e) {
      if ( e.number() == CL_ERR_IO ){
	      _CLTHROWA(CL_ERR_CorruptIndex, "failed to locate current segments_N file");
      }
	  }
	  if (infoStream != NULL)
	    message("forced open of current segments file " + segmentInfos->getCurrentSegmentFileName());
	  currentCommitPoint = _CLNEW CommitPoint(this,&sis);
    commits.push_back(currentCommitPoint);
	  incRef(&sis, true);
	}

	// We keep commits list in sorted order (oldest to newest):
  	std::sort(commits.begin(), commits.end(), CommitPoint::sort);

	// Now delete anything with ref count at 0.  These are
	// presumably abandoned files eg due to crash of
	// IndexWriter.
  RefCountsType::iterator it = refCounts.begin();
	while(it != refCounts.end()) {
    char* fileName = it->first;
    RefCount* rc = it->second;
	  if (0 == rc->count) {
	    if (infoStream != NULL) {
	      message( string("init: removing unreferenced file \"") + fileName + "\"");
	    }
	    deleteFile(fileName);
	  }
    it++;
	}

	// Finally, give policy a chance to remove things on
	// startup:
	policy->onInit(commits);

	// It's OK for the onInit to remove the current commit
	// point; we just have to checkpoint our in-memory
	// SegmentInfos to protect those files that it uses:
	if (currentCommitPoint->deleted) {
	  checkpoint(segmentInfos, false);
	}

	deleteCommits();
}
void
SharedObject::deleteIfZeroRefCount() const {
    if(getRefCount() == 0) {
        delete this;
    }
}
Exemplo n.º 18
0
void Texture::init() {

    if ( texturaCarregada == false ) {

        if (pathFile.compare("FRAME_BUFFER") != 0) {

            SDL_Surface *pImage = IMG_Load ( pathFile.c_str() );
            if ( pImage == nullptr )
                throw ExceptionChimera ( ExceptionCode::READ, "Falha ao ler arquivo:" + pathFile );

            // Create The Texture
            glGenTextures ( 1, ( GLuint* ) &idTexture);

            // Load in texture
            glBindTexture ( GL_TEXTURE_2D, idTexture ); // Typical Texture Generation Using Data From The Bitmap

            height = pImage->h;
            width = pImage->w;

            // Generate The Texture
            if ( pImage->format->Amask != 0 ) {
                glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, pImage->w, pImage->h, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pImage->pixels );
            } else {
                glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, pImage->w, pImage->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pImage->pixels );
            }

            // Nearest Filtering
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

            SDL_FreeSurface ( pImage );

        } else {

            glBindTexture(GL_TEXTURE_2D, idTexture);

           	glGenFramebuffers(1, &depthMapFBO);
            glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, idTexture, 0);
            glDrawBuffer(GL_NONE);
            glReadBuffer(GL_NONE);

            glBindFramebuffer(GL_FRAMEBUFFER, 0);

        }

        texturaCarregada = true;
        printf("Texture Name: %s id: %u num instancia: %d\n", getName().c_str(), idTexture, getRefCount());
    }
}
Exemplo n.º 19
0
void simpRecord::decrementRefCount(){
	rec->refCount = getRefCount()-1;
//	return(rec->refCount);
}