예제 #1
0
void HttpCache::clean()
{
    CacheElement *pData;
    iterator iterEnd = end();
    for (iterator iter = begin(); iter != iterEnd;)
    {
        pData = iter.second();
        if (pData->getRef() == 0)
        {
            long t = DateTime::s_curTime - pData->getLastAccess();
            if (t > CACHE_TIMEOUT)
            {
                iterator iterDel = iter;
                iter = next(iter);
                erase(iterDel);
                recycle(pData);
                continue;
            }
            else if (t > CACHE_DATA_TIMEOUT)
                pData->release();
        }
        iter = next(iter);
    }
    for (DirtyCacheList::iterator it = m_dirty.begin(); it != m_dirty.end();)
    {
        if (!(*it)->isInUse())
        {
            recycle(*it);
            it = m_dirty.erase(it);
        }
        else
            ++it;
    }
}
예제 #2
0
int
LogFlushTask::start()
{
    int rt = 0;

    m_pTimer = new MUTimer(MURegister::getInstance()->getEpoll(), this);

    rt = m_pTimer->create();

    if (-1 == rt) {
        ERROR_LOG("create timer error");
        recycle(m_pTimer);
        m_pTimer = NULL;
        return -1;
    }

    rt = m_pTimer->setTime(LOG_FLUSH_PERIOD,
                           LOG_FLUSH_PERIOD);

    if (-1 == rt) {
        ERROR_LOG("timer set time error");
        recycle(m_pTimer);
        m_pTimer = NULL;
        return -1;
    }

    return 0;
}
예제 #3
0
void test_object_life_cycle()
{
		Bird* bird = new(Bird);
		ff(bird, fly, nil);
		ff(bird, flyhigh, nil);
		ff(bird, singAsong, "a song from child");
		ff(bird, fatherAge, nil);
		//ff(bird, cannotResponseThis, nil);
		shift(bird, BirdModeA);
			ff(bird, modemethodC, nil);
		shift_back(bird);
		recycle(bird);
		//one create on delete

		Bird* bird2 = new(Bird);
		debug_log("bird2 pointer %p\n", bird2);
		Bird* bird3 = new(Bird);
		debug_log("bird2 pointer %p\n", bird3);
		Bird* bird31 = new(Bird);
		debug_log("bird2 pointer %p\n", bird31);

		info(Bird);
		info(BirdFather);
		info(BirdGrandFather);

		recycle(bird2);
		recycle(bird3);
		//release(&bird31);

		info(Bird);
		info(BirdFather);
		info(BirdGrandFather);

		Bird* b1=new(Bird);
		Bird* b2=new(Bird);

		info(Bird);
		info(BirdFather);
		info(BirdGrandFather);

		recycle(b1);
		recycle(b2);

		clear(Bird);
		clear(BirdFather);
		clear(BirdGrandFather);

		info(Bird);
		info(BirdFather);
		info(BirdGrandFather);

}
예제 #4
0
void HttpCache::releaseAll()
{
    dirtyAll();
    for (DirtyCacheList::iterator iter = m_dirty.begin();
         iter != m_dirty.end(); ++iter)
        recycle(*iter);
}
예제 #5
0
    /**
     * A request to recycle this message was received. Forward that request to
     * the connection message manager for processing. Errors and exceptions
     * from the manager's recycle member function should be passed back up the
     * call chain. The caller to message::recycle will deal with them.
     *
     * Recycle must *only* be called by the message shared_ptr's destructor.
     * Once recycled successfully, ownership of the memory has been passed to
     * another system and must not be accessed again.
     *
     * @return true if the message was successfully recycled, false otherwise.
     */
    bool recycle() {
        typename con_msg_manager::ptr shared = m_manager.lock();

        if (shared) {
            return shared->(recycle(this));
        } else {
            return false;
예제 #6
0
LogFlushTask::~LogFlushTask()
{
    if (NULL != m_pTimer) {
        recycle(m_pTimer);
        m_pTimer = NULL;
    }
}
예제 #7
0
int VMemBuf::shrinkBuf( long size )
{
/*
    if ( m_type == VMBUF_FILE_MAP )
    {
        if ( s_iMaxAnonMapBlocks - s_iCurAnonMapBlocks > s_iMaxAnonMapBlocks / 10 )
        {
            deallocate();
            if ( set( VMBUF_ANON_MAP , getBlockSize() ) == -1 )
                return -1;
            return 0;
        }

    }
*/
    if ( size < 0 )
        size = 0;
    if (( m_type == VMBUF_FILE_MAP )&&( m_fd != -1 ))
    {
        if ( m_curTotalSize > (unsigned long) size )
            ftruncate( m_fd, size );
    }
    BlockBuf * pBuf;
    while( m_curTotalSize > (size_t)size )
    {
        pBuf = m_bufList.pop_back();
        m_curTotalSize -= pBuf->getBlockSize();
        recycle( pBuf );
    }
    if ( !m_bufList.empty())
    {
        m_pCurWBlock = m_pCurRBlock = m_bufList.begin();
    }
    return 0;
}
예제 #8
0
/**
 * rig_protobuf_c_data_buffer_discard:
 * @buffer: the buffer to discard data from.
 * @max_discard: maximum number of bytes to discard.
 *
 * Removes up to @max_discard data from the beginning of the buffer,
 * and returns the number of bytes actually discarded.
 *
 * returns: number of bytes discarded.
 */
size_t
rig_protobuf_c_data_buffer_discard (ProtobufCDataBuffer *buffer,
                                    size_t max_discard)
{
  int rv = 0;
  CHECK_INTEGRITY (buffer);
  while (max_discard > 0 && buffer->first_frag)
    {
      ProtobufCDataBufferFragment *first = buffer->first_frag;
      if (first->buf_length <= max_discard)
	{
	  rv += first->buf_length;
	  max_discard -= first->buf_length;
	  buffer->first_frag = first->next;
	  if (!buffer->first_frag)
	    buffer->last_frag = NULL;
	  recycle (buffer->allocator, first);
	}
      else
	{
	  rv += max_discard;
	  first->buf_length -= max_discard;
	  first->buf_start += max_discard;
	  max_discard = 0;
	}
    }
  buffer->size -= rv;
  CHECK_INTEGRITY (buffer);
  return rv;
}
예제 #9
0
파일: Main.c 프로젝트: LinkinW/monkc
void testMonkC()
{
    //new a instance
    LittleBird* abird = new(LittleBird);
    LittleBird* bbird = new(LittleBird);
    release(bbird);

    //static call methods
    LittleBird_fly(abird, 0, nil);
    LittleBird_eat(abird, 0, nil);
    LittleBird_swim(abird,0, nil);
    
    //dynamic call methods
    ff(abird, fly, nil);
    ff(abird, swim, nil);
    ff(abird, eat, nil);
    ff(abird, yourName, nil);

    //call abs method
    ff(abird, hello_abs, nil);
    ff(abird, land_abs, nil);
    
    //dynamic call super class methods
    int fatherage = (int)ff(abird, getAge, nil);
    printf("my father age is : %d\n", fatherage);

    recycle(abird);
}
예제 #10
0
int my_rmdir (const TCHAR *name)
{
	struct my_opendir_s *od;
	int cnt;
	TCHAR tname[MAX_DPATH];

	/* SHFileOperation() ignores FOF_NORECURSION when deleting directories.. */
	od = my_opendir (name);
	if (!od) {
		SetLastError (ERROR_FILE_NOT_FOUND);
		return -1;
	}
	cnt = 0;
	while (my_readdir (od, tname)) {
		if (!_tcscmp (tname, _T(".")) || !_tcscmp (tname, _T("..")))
			continue;
		cnt++;
		break;
	}
	my_closedir (od);
	if (cnt > 0) {
		SetLastError (ERROR_CURRENT_DIRECTORY);
		return -1;
	}

	return recycle (name);
}
예제 #11
0
void
LogFlushTask::destroy(MUTimer *pChannel)
{
    m_pTimer = NULL;

    FATAL_LOG("log flush task, timer error");
    recycle();
}
예제 #12
0
void CgidConn::cleanUp()
{
    setConnector( NULL );
    setState( CLOSING );
    ::shutdown( getfd(), SHUT_RDWR );
//    close();
    recycle();
}
예제 #13
0
//=============================================================================
// Main execution
//=============================================================================
StatusCode TbPacketRecycler::execute() {

  for (unsigned int i = 0; i < m_nPlanes; ++i) {
    const std::string hitLocation = m_hitLocation + std::to_string(i);
    const std::string trgLocation = m_trgLocation + std::to_string(i);
    const std::string clusLocation = m_clusLocation + std::to_string(i);

    LHCb::TbHits* hits = getIfExists<LHCb::TbHits>(hitLocation);
    LHCb::TbTriggers* trgs = getIfExists<LHCb::TbTriggers>(trgLocation);
    LHCb::TbClusters* clusters = getIfExists<LHCb::TbClusters>(clusLocation);

    removeClusters(clusters);
    recycle(hits, m_streams[i]);
    recycle(trgs, m_streams[i]);
  }
  return StatusCode::SUCCESS;
}
예제 #14
0
void VaapiDecSurfacePool::recycle(VideoRenderBuffer * renderBuf)
{
    if (renderBuf < &m_renderBuffers[0]
        || renderBuf >= &m_renderBuffers[m_renderBuffers.size()]) {
        ERROR("recycle invalid render buffer");
        return;
    }
    recycle(renderBuf->surface, SURFACE_RENDERING);
}
예제 #15
0
CustomPostEffectShader::~CustomPostEffectShader() {
    if (program_ != 0) {
        recycle();
    }

    if (vaoID_ != 0) {
    	gl_delete.queueVertexArray(vaoID_);
    	vaoID_ = 0;
    }
}
예제 #16
0
void LsapiConn::cleanUp()
{
    setConnector( NULL );
    reset();
    if ( getState() == ABORT )
    {
        close();
    }
    recycle();
}
예제 #17
0
int HttpCache::dirty(CacheElement *data)
{
    assert(data);
    remove(data->getKey());
    if (data->isInUse())
        m_dirty.push_back(data);
    else
        recycle(data);
    return 0;
}
예제 #18
0
void
rig_protobuf_c_data_buffer_clear(ProtobufCDataBuffer *to_destroy)
{
  ProtobufCDataBufferFragment *at = to_destroy->first_frag;
  CHECK_INTEGRITY (to_destroy);
  while (at)
    {
      ProtobufCDataBufferFragment *next = at->next;
      recycle (to_destroy->allocator, at);
      at = next;
    }
}
예제 #19
0
파일: io.cpp 프로젝트: JoyZou/libevlite
int32_t IIOService::perform( sid_t sid, int32_t type, void * task, void (*recycle)(int32_t, void *) )
{
    int32_t rc = iolayer_perform(
            m_IOLayer, sid, type, task, recycle );

    if ( rc != 0 )
    {
        recycle( type, task );
    }

    return rc;
}
예제 #20
0
void CallbackQueue::removeObj(CallbackLinkedObj *pObj)
{
    if (!pObj)
        return;

    logState("removeObj()", pObj);
    if (pObj->next())
    {
        m_callbackObjList.remove(pObj);
        recycle(pObj);
    }
}
예제 #21
0
void EvtcbQue::removeObj(evtcbnode_s *pObj)
{
    if (!pObj)
        return;

    logState("removeObj()", pObj);
    if (pObj->next())
    {
        m_callbackObjList.remove(pObj);
        recycle(pObj);
    }
}
예제 #22
0
/*---------------------------------------------------------------------------*/
struct ip64_addrmap_entry *
ip64_addrmap_create(const uip_ip6addr_t *ip6addr,
                    uint16_t ip6port,
                    const uip_ip4addr_t *ip4addr,
                    uint16_t ip4port,
                    uint8_t protocol)
{
    struct ip64_addrmap_entry *m;

    check_age();
    m = memb_alloc(&entrymemb);
    if(m == NULL) {
        /* We could not allocate an entry, try to recycle one and try to
           allocate again. */
        if(recycle()) {
            m = memb_alloc(&entrymemb);
        }
    }
    if(m != NULL) {
        uip_ip4addr_copy(&m->ip4addr, ip4addr);
        m->ip4port = ip4port;
        uip_ip6addr_copy(&m->ip6addr, ip6addr);
        m->ip6port = ip6port;
        m->protocol = protocol;
        m->flags = FLAGS_NONE;
        m->ip6to4 = 1;
        m->ip4to6 = 0;
        timer_set(&m->timer, 0);

        /* Pick a new, unused local port. First make sure that the
           mapped_port number does not belong to any active connection. If
           so, we keep increasing the mapped_port until we're free. */
        {
            struct ip64_addrmap_entry *n;
            n = list_head(entrylist);
            while(n != NULL) {
                if(n->mapped_port == mapped_port) {
                    increase_mapped_port();
                    n = list_head(entrylist);
                } else {
                    n = list_item_next(m);
                }
            }
        }
        m->mapped_port = mapped_port;
        increase_mapped_port();

        list_add(entrylist, m);
        return m;
    }
    return NULL;
}
예제 #23
0
/**
 * rig_protobuf_c_data_buffer_destruct:
 * @to_destroy: the buffer to empty.
 *
 * Remove all fragments from a buffer, leaving it empty.
 * The buffer is guaranteed to not to be consuming any resources,
 * but it also is allowed to start using it again.
 */
void
rig_protobuf_c_data_buffer_reset(ProtobufCDataBuffer *to_destroy)
{
  ProtobufCDataBufferFragment *at = to_destroy->first_frag;
  CHECK_INTEGRITY (to_destroy);
  while (at)
    {
      ProtobufCDataBufferFragment *next = at->next;
      recycle (to_destroy->allocator, at);
      at = next;
    }
  to_destroy->first_frag = to_destroy->last_frag = NULL;
  to_destroy->size = 0;
}
예제 #24
0
    GLuint getNextTexture(const uvec2& size) {
        assert(QThread::currentThread() == qApp->thread());

        recycle();

        ++_activeTextureCount;
        auto sizeKey = uvec2ToUint64(size);
        assert(_textures.count(sizeKey));
        auto& textureSet = _textures[sizeKey];
        if (!textureSet.returnedTextures.empty()) {
            auto textureAndFence = textureSet.returnedTextures.front();
            textureSet.returnedTextures.pop_front();
            waitOnFence(static_cast<GLsync>(textureAndFence.second));
            return textureAndFence.first;
        }

        return createTexture(size);
    }
예제 #25
0
파일: Main.c 프로젝트: LinkinW/monkc
void testLemontea()
{
    
    MCString* mcstr = ff(new(MCString), initWithCString, "a MCString");
    ff(mcstr, add, " the second");
    ff(mcstr, add, " the third");
    ff(mcstr, add, " the forth\n");
    
    // int i;
    // for (i=0; i<100; i++) {
    //     int old = LOG_LEVEL;
    //     LOG_LEVEL = MC_ERROR_ONLY;
    //     ff(mcstr, add, " a piece of string");
    //     LOG_LEVEL = old;
    // }
    ff(mcstr, print, nil);
    release(mcstr);
    
    MCClock* mcclock = ff(new(MCClock), setTimeToNow, nil);
    ff(mcclock, printTime, nil);
    ff(mcclock, printCurrentGMTTime, nil);
    recycle(mcclock);

    MCFile* afile = MCFile_newReadWrite("mcfile.txt", 1);
    char buff[1024] = "this is a file";
    int res = call(afile, MCFile, writeToBegin, 8, buff, 64);
    printf("writeToBegin result: %d errno: %d\n", res, errno);
    call(afile, MCFile, printAttribute, nil);
    release(afile);

    MCCharBuffer* charbuff = CopyToCharBuffer(NewMCCharBuffer(64*sizeof(char)), 
    	"this is a stream make it longer to find out why it is cutted\n");
    MCString* mcstring = ff(new(MCString), initWithCString, 
    	"this is a stream make it longer to find out why it is cutted\n");
    MCStream* stream = ff(new(MCStream), newWithPath, readwrite_fullbuffered, "mcstream.txt");
    ff(stream, putCString, charbuff);
    ff(stream, putMCString, mcstring);

    release(stream);
    ReleaseMCBuffer(charbuff);
    release(mcstring);

}
예제 #26
0
int VMemBuf::convertFileBackedToInMemory()
{
    BlockBuf * pBlock;
    if ( m_type != VMBUF_FILE_MAP )
        return -1;
    if ( m_pCurWPos == (*m_pCurWBlock)->getBuf() )
    {
        if ( *m_pCurWBlock == m_bufList.back() )
        {
            m_bufList.pop_back();
            recycle( *m_pCurWBlock );
            if ( !m_bufList.empty() )
            {
                m_noRecycle = 1;
                s_iCurAnonMapBlocks += m_bufList.size();
                int i = 0;
                while( i < m_bufList.size())
                {
                    pBlock = m_bufList[i];
                    if ( !pBlock->getBuf() )
                    {
                        if ( remapBlock( pBlock, i * s_iBlockSize ) == -1 )
                            return -1;
                    }
                    ++i;
                }
            }
            unlink( m_sFileName.c_str() );
            ::close( m_fd );
            m_fd = -1;
            m_type = VMBUF_ANON_MAP;
            if ( !(pBlock = getAnonMapBlock( s_iBlockSize ) ))
                return -1;
            appendBlock( pBlock );
            if ( m_pCurRPos == m_pCurWPos )
                m_pCurRPos = (*m_pCurWBlock)->getBuf();
            m_pCurWPos = (*m_pCurWBlock)->getBuf();
            return 0;
        }
        
    }
    return -1;
}
예제 #27
0
/*
 * Find and recycle any disk archive vsn which are marked for recycling.
 * Always log remove actions as if recycling is occurring.
 */
void
RecycleDiskArchives(void)
{
	int vsn_i;

	if (cannot_recycle) {
		return;
	}

	if (*TraceFlags & (1 << TR_debug)) {
		traceDebug = B_TRUE;
	}

	if (*TraceFlags & (1 << TR_misc)) {
		traceMisc = B_TRUE;
	}

	for (vsn_i = 0; vsn_i < table_used; vsn_i++) {
		VSN_TABLE *vsn_entry = &vsn_table[vsn_permute[vsn_i]];

		/*
		 * If it's not disk media, skip it.
		 */
		if (IS_DISK_MEDIA(vsn_entry->media) == FALSE) {
			continue;
		}

		ignoreRecycling = B_FALSE;

		/*
		 * Disk media, check if it needs recycling.  Recycle
		 * this disk volume if is_recycling, 'c', flag is set.
		 */
		if (vsn_entry->needs_recycling == FALSE &&
		    vsn_entry->is_recycling == FALSE) {

			ignoreRecycling = B_TRUE;
		}

		recycle(vsn_entry);
	}
}
예제 #28
0
void CallbackQueue::run(CallbackLinkedObj *pFirstObj,
                        LsiSession *pSessionFilter)
{
    CallbackLinkedObj *pObj;
    CallbackLinkedObj *pObjNext;

    if (pFirstObj == NULL)
        pObj = (CallbackLinkedObj *)m_callbackObjList.begin();
    else
        pObj = pFirstObj;

    int count = m_callbackObjList.size();
    while (count > 0
           && pObj && pObj != (CallbackLinkedObj *)m_callbackObjList.end()
           && (!pSessionFilter || pObj->m_pSession == pSessionFilter))
    {
        pObjNext = (CallbackLinkedObj *)pObj->next();
        logState("run()", pObj);

        --count;

        m_callbackObjList.remove(pObj);

        assert(pObj->m_callback);
        if (pObj->m_callback)
            pObj->m_callback((lsi_session_t *)pObj->m_pSession, pObj->m_lParam,
                             pObj->m_pParam);
        else
            logState("run()][Error: NULL calback", pObj);

        /**
         * Comment: the above cb may release the data, so checking here to avoid
         * recycle again!
         */
        recycle(pObj);
        pObj = pObjNext;
    }
    assert((pFirstObj && pSessionFilter) || (count == 0));
}
예제 #29
0
/**
 * session is a filter. If NULL, run all in queue
 */
void EvtcbQue::run(evtcbhead_t *session)
{
    evtcbnode_s *pObj;
    evtcbnode_s *pObjNext;

    if (session == NULL)
        pObj = (evtcbnode_s *)m_callbackObjList.begin();
    else
        pObj = session->evtcb_head;

    assert(m_callbackObjList.size() > 0
           || (m_callbackObjList.begin() ==
               m_callbackObjList.end())); //WRONG state!!!


    while (m_callbackObjList.size() > 0
           && pObj && pObj != (evtcbnode_s *)m_callbackObjList.end()
           && (!session || pObj->m_pSession == session))
    {
        pObjNext = (evtcbnode_s *)pObj->next();
        logState("run()", pObj);

        m_callbackObjList.remove(pObj);

        if (pObj->m_pSession)
            pObj->m_pSession->evtcb_head = NULL;


        assert(pObj->m_callback);
        if (pObj->m_callback)
            pObj->m_callback(pObj->m_pSession, pObj->m_lParam,
                             pObj->m_pParam);
        else
            logState("run()][Error: NULL calback", pObj);

        recycle(pObj);
        pObj = pObjNext;
    }
}
예제 #30
0
/**
 * rig_protobuf_c_data_buffer_read:
 * @buffer: the buffer to read data from.
 * @data: buffer to fill with up to @max_length bytes of data.
 * @max_length: maximum number of bytes to read.
 *
 * Removes up to @max_length data from the beginning of the buffer,
 * and writes it to @data.  The number of bytes actually read
 * is returned.
 *
 * returns: number of bytes transferred.
 */
size_t
rig_protobuf_c_data_buffer_read(ProtobufCDataBuffer *buffer,
                                void *data,
                                size_t max_length)
{
  size_t rv = 0;
  size_t orig_max_length = max_length;
  CHECK_INTEGRITY (buffer);
  while (max_length > 0 && buffer->first_frag)
    {
      ProtobufCDataBufferFragment *first = buffer->first_frag;
      if (first->buf_length <= max_length)
	{
	  memcpy (data, rig_protobuf_c_data_buffer_fragment_start (first), first->buf_length);
	  rv += first->buf_length;
	  data = (char *) data + first->buf_length;
	  max_length -= first->buf_length;
	  buffer->first_frag = first->next;
	  if (!buffer->first_frag)
	    buffer->last_frag = NULL;
	  recycle (buffer->allocator, first);
	}
      else
	{
	  memcpy (data, rig_protobuf_c_data_buffer_fragment_start (first), max_length);
	  rv += max_length;
	  first->buf_length -= max_length;
	  first->buf_start += max_length;
	  data = (char *) data + max_length;
	  max_length = 0;
	}
    }
  buffer->size -= rv;
  assert (rv == orig_max_length || buffer->size == 0);
  CHECK_INTEGRITY (buffer);
  return rv;
}