当前位置: 首页>>代码示例>>C++>>正文


C++ free_block函数代码示例

本文整理汇总了C++中free_block函数的典型用法代码示例。如果您正苦于以下问题:C++ free_block函数的具体用法?C++ free_block怎么用?C++ free_block使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了free_block函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: quit_agent

bool quit_agent(int argc, char *argv[]) {
    op_ptr op = op_list;
    word_t w;
    while (op) {
	op_ptr ele = op;
	op = ele->next;
	free_block(ele, sizeof(op_ele));
    }
    if (router_fd_array)
	free_array(router_fd_array, nrouters, sizeof(int));
    /* Free any pending operations */
    chunk_ptr msg;
    keyvalue_iterstart(operator_table);
    while (keyvalue_removenext(operator_table, NULL, (word_t *) &msg)) {
	chunk_free(msg);
    }
    keyvalue_free(operator_table);
    keyvalue_iterstart(deferred_operand_table);
    while (keyvalue_removenext(deferred_operand_table, NULL, &w)) {
	operand_ptr ls = (operand_ptr) w;
	while (ls) {
	    chunk_free(ls->operand);
	    operand_ptr ele = ls;
	    ls = ls->next;
	    free_block(ele, sizeof(operand_ele));
	}
    }
    keyvalue_free(deferred_operand_table);
    chunk_deinit();
    return true;
}
开发者ID:rebryant,项目名称:Cloud-BDD,代码行数:31,代码来源:agent.c

示例2: initiate_free_list

void initiate_free_list() {
    free_block(0);
    uint max_inode_block = 1 + curr_superblock.isize;
    int i;
    for(i = curr_superblock.fsize - 1; i > max_inode_block; i--) {
        free_block(i);
    }
}
开发者ID:Blizzardking,项目名称:FileSystem,代码行数:8,代码来源:block.c

示例3: work_run

void* work_run(void* arg) {
    printf("create pthread %d\n", pthread_self());

    BufBlock_t* block = NULL;
    BufBlock_t* new_block = NULL;

    Reactor* reactor = (Reactor*) arg;

    while (!stop) {
        reactor->handle_events(1000);

        //将接收到的协议 串行处理
        while ((block=g_receive_queue.pop_queue()) != NULL) {
            char* send_data;
            int send_len = 0;

            int ret_code = dll.handle_process((char*)block->page_base, block->buf_head.len, &send_data, &send_len, &(block->buf_head.sk));

            new_block = alloc_block(send_len);
            new_block->buf_head = block->buf_head;
            new_block->buf_head.len = send_len;
            memcpy(new_block->page_base, send_data, send_len);

            free_block(block);
            if (send_len != 0 && g_server_conf.need_free_send_buf) {
                free(send_data);
            }

            if (ret_code == -1) { //关闭链接
                PUSH_ERRMSG(FIN_BLOCK);
            }
            else if (send_len == 0 || send_len > 8388608) { //长度不对
                LOG4CPLUS_INFO(log4cplus::Logger::getRoot(), "socket fd="<<new_block->buf_head.sk.socket<<" send too large pkg");
                PUSH_ERRMSG(CLEAR_BLOCK);
            }
            else if (send_len > 0) {
                new_block->buf_head.buf_type = DATA_BLOCK;
                if (1 == ret_code) {
                    new_block->buf_head.buf_type |= FIN_BLOCK;
                }

                if (stop) {
                    return ((void *)0);
                }

                HandlerBase* h = reactor->get_handler(new_block->buf_head.sk.socket);
                if (NULL == h) {
                    free_block(new_block);
                    continue;
                }

                if (!h->push_buf(new_block)) {
                    free_block(new_block);
                }
            }
        }
    }
}
开发者ID:kentguan,项目名称:moonserver,代码行数:58,代码来源:workthread.hpp

示例4: testsAllocationBlocks

void testsAllocationBlocks(){
    
    printf("Volume %s plein\n", (isVolFull() == 0) ? "NON ":"");
    printf("Espace restant : %d/%d (1 bloc reserve au superbloc)\n", volFreeSpace(), MBR.volumes[currentVol].size);
    
    disp_freelist();
    
    int newBlock;
    while( (newBlock = new_block()) > 0){
        printf("Allocation du bloc %04d.\n", newBlock); // pour un volume de 10 240o, on pourra allouer 39 blocs (1 bloc réservé pour superblock) 40*256o=10240o
        printf("Espace restant : %d\n\n", volFreeSpace());
    }
    printf("Allocation impossible : err %d\n", newBlock);
    printf("Espace restant : %d/%d\n", volFreeSpace(), MBR.volumes[currentVol].size);
    
    printf("Volume %splein.\n", (isVolFull() == 0) ? "NON ":"");
    
    printf("Liberation de le moitie des blocs du volume.\n");
    unsigned int i;
    for (i = 1; i < MBR.volumes[currentVol].size/2; i++) // Libération de blocs contingüs.
        free_block(i);
        
    disp_freelist();
        
    // ré-allocation de 2 blocs
    for(unsigned int i = 0;i<2 && (newBlock = new_block()) > 0;i++){
        printf("Allocation du bloc %04d.\n", newBlock);
        printf("Espace restant : %d\n\n", volFreeSpace());
    }
    
    // libération de blocs au hasard
    unsigned int blockToFree[] = { 10, 15 };
    unsigned int blockToFreeCount = 2;
    for (i = 0; i < blockToFreeCount; i++){
        printf("Liberation du bloc n %d - statut : %d\n", blockToFree[i], free_block(blockToFree[i]));
        printf("Permier bloc libre : %u\n", currentSuperblock.firstFree);
        printf("Espace restant : %d/%d\n", volFreeSpace(), MBR.volumes[currentVol].size);
        printf("Volume %s plein\n", (isVolFull() == 0) ? "NON ":"");
    }
    
    disp_freelist();
    
    // ré-allocation de 2 blocs
    for(unsigned int i = 0;i<2 && (newBlock = new_block()) > 0;i++){
        printf("Allocation du bloc %04d.\n", newBlock);
        printf("Espace restant : %d\n\n", volFreeSpace());
    }
    
    // affichage freelist
    disp_freelist();
    
    printf("Permier bloc libre : %u\n", currentSuperblock.firstFree);
    printf("Espace restant : %d/%d\n", volFreeSpace(), MBR.volumes[currentVol].size);
    printf("Volume %s plein\n", (isVolFull() == 0) ? "NON ":"");
}
开发者ID:ABeaujet,项目名称:ASEa,代码行数:55,代码来源:TP8.c

示例5: buddy_free_blob

void buddy_free_blob(struct chunked_blob *blob, size_t _unused)
{
	int i;
	int orders[CHUNKS_COUNT];
	value_size_to_block_sizes(blob->size, orders);

	for (i = CHUNKS_COUNT-1; i > 0; i--) {
		if (orders[i] < 0)
			continue;
		free_block(blob->other_chunks[i-1], orders[i]);
	}
	free_block(blob, orders[0]);
}
开发者ID:alk,项目名称:buddy-experiment,代码行数:13,代码来源:buddy-experiment.c

示例6: free_ind

static void free_ind(int dev,int block) {
	struct buffer_head * bh;
	unsigned short * p;
	int i;
	if (!block) return;
	if ((bh=bread(dev,block))) {
		p = (unsigned short *) bh->b_data;
		for (i = 0; i < 512; i++,p++) {
			if (*p) free_block(dev,*p);
    }
		brelse(bh);
	}
	free_block(dev,block);
}
开发者ID:wangxuemin,项目名称:coding,代码行数:14,代码来源:truncate.c

示例7: free_block

/* Deze methode zet het blok op index op vrij, indien mogelijk fuseert het
 * met omringende vrije blokken. */
void free_block(long index){
	long prev = get_prev(index);
	long next = get_next(index);
	
	if(!get_free(index)){
		/* Zet het blok op vrij. */
		set_free(index, 1);
		mem[0] -= get_length(index);
	}
	
	/* Voeg vorige blok samen met het huidige als deze vrij is als een groot
	 * vrij blok. */
	if(prev != 0 && get_free(prev)){
		set_length(prev, get_length(prev) + get_length(index) + ADMIN_SIZE);
		set_next(prev, next);
		
		if(next != 0){
			set_prev(next, prev);
		}
		
		mem[1] -= ADMIN_SIZE;
	}
	
	/* Voeg volgende blok samen met het huidige als deze vrij is als een 
	 * groot vrij blok. */
	if(next != 0 && get_free(next)){
		free_block(next);
	}
}
开发者ID:TomPeerdeman,项目名称:OS2012,代码行数:31,代码来源:mem-func.c

示例8: i915_mem_free

int i915_mem_free(struct drm_device *dev, void *data,
		  struct drm_file *file_priv)
{
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct drm_i915_mem_free *memfree = data;
	struct mem_block *block, **heap;

	if (!dev_priv) {
		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
		return -EINVAL;
	}

	heap = get_heap(dev_priv, memfree->region);
	if (!heap || !*heap)
		return -EFAULT;

	block = find_block(*heap, memfree->region_offset);
	if (!block)
		return -EFAULT;

	if (block->file_priv != file_priv)
		return -EPERM;

	mark_block(dev, block, 0);
	free_block(block);
	return 0;
}
开发者ID:jobi,项目名称:drm-psb,代码行数:27,代码来源:i915_mem.c

示例9: free_dcr

/*
 * Free up all aspects of the given dcr -- i.e. dechain it,
 *  release allocated memory, zap pointers, ...
 */
void free_dcr(DCR *dcr)
{
   JCR *jcr;

   P(dcr->m_mutex);
   jcr = dcr->jcr;

   locked_detach_dcr_from_dev(dcr);

   if (dcr->block) {
      free_block(dcr->block);
   }

   if (dcr->rec) {
      free_record(dcr->rec);
   }

   if (jcr && jcr->dcr == dcr) {
      jcr->dcr = NULL;
   }

   if (jcr && jcr->read_dcr == dcr) {
      jcr->read_dcr = NULL;
   }

   V(dcr->m_mutex);

   pthread_mutex_destroy(&dcr->m_mutex);
   pthread_mutex_destroy(&dcr->r_mutex);

   delete dcr;
}
开发者ID:yunnet,项目名称:bareos,代码行数:36,代码来源:acquire.c

示例10: BlockHeapDestroy

/*! \brief Completely free()s a BlockHeap.  Use for cleanup.
 * \param bh Pointer to the BlockHeap to be destroyed
 * \return 0 if successful, 1 if bh == NULL
 */
int
BlockHeapDestroy(BlockHeap *bh)
{
  Block *walker = NULL, *next = NULL;

  if (bh == NULL)
    return 1;

  for (walker = bh->base; walker != NULL; walker = next)
  {
    next = walker->next;
    free_block(walker->elems, walker->alloc_size);

    if (walker != NULL)
      free(walker);
  }

  if (heap_list == bh)
    heap_list = bh->next;
  else {
    BlockHeap *prev;

    for (prev = heap_list; prev->next != bh; prev = prev->next)
      /* nothing */ ;
    prev->next = bh->next;
  }

  free(bh);
  return 0;
}
开发者ID:mdharris,项目名称:ircd,代码行数:34,代码来源:balloc.c

示例11: radeon_mem_free

int radeon_mem_free( DRM_IOCTL_ARGS )
{
	DRM_DEVICE;
	drm_radeon_private_t *dev_priv = dev->dev_private;
	drm_radeon_mem_free_t memfree;
	struct mem_block *block, **heap;

	if ( !dev_priv ) {
		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
		return DRM_ERR(EINVAL);
	}

	DRM_COPY_FROM_USER_IOCTL( memfree, (drm_radeon_mem_free_t *)data,
				  sizeof(memfree) );

	heap = get_heap( dev_priv, memfree.region );
	if (!heap || !*heap)
		return DRM_ERR(EFAULT);
	
	block = find_block( *heap, memfree.region_offset );
	if (!block)
		return DRM_ERR(EFAULT);

	if (block->pid != DRM_CURRENTPID)
		return DRM_ERR(EPERM);

	free_block( block );	
	return 0;
}
开发者ID:gvsurenderreddy,项目名称:theqvd,代码行数:29,代码来源:radeon_mem.c

示例12: file_truncate_blocks

// Remove any blocks currently used by file 'f',
// but not necessary for a file of size 'newsize'.
// For both the old and new sizes, figure out the number of blocks required,
// and then clear the blocks from new_nblocks to old_nblocks.
// If the new_nblocks is no more than NDIRECT, and the indirect block has
// been allocated (f->f_indirect != 0), then free the indirect block too.
// (Remember to clear the f->f_indirect pointer so you'll know
// whether it's valid!)
// Do not change f->f_size.
static void
file_truncate_blocks(struct File *f, off_t newsize)
{
	int r;
	uint32_t bno, old_nblocks, new_nblocks;

	// Hint: Use file_clear_block and/or free_block.
	for (old_nblocks = 0; old_nblocks < f->f_size; old_nblocks += BLKSIZE)
		;
	old_nblocks /= BLKSIZE;
	for (new_nblocks = 0; new_nblocks < newsize; new_nblocks += BLKSIZE)
		;
	new_nblocks /= BLKSIZE;
	cprintf("truncate from %d[%d] -> %d[%d].\n", f->f_size, new_nblocks, f->f_size, old_nblocks);
	for (bno = new_nblocks; bno <= old_nblocks; bno++)
		if ((r = file_clear_block(f, bno)) < 0)
			panic("file clear block error: %e\n", r);

	// Yeah, we need to clear the extra block as well
	if (new_nblocks < NDIRECT) {
		if (f->f_indirect != 0) {
			free_block(f->f_indirect);
			f->f_indirect = 0;
		}
		while (new_nblocks < NDIRECT)
			f->f_direct[new_nblocks++] = 0;
	}
}
开发者ID:AlexandrSalin,项目名称:mit-jos,代码行数:37,代码来源:fs.c

示例13: if

 int StackAllocator::free_head()
 {
   int err = OB_SUCCESS;
   Block* head = NULL;
   if (NULL == allocator_)
   {
     err = OB_NOT_INIT;
   }
   else if (NULL == head_ || (top_ -= head_->pos_) < 0)
   {
     err = OB_ERR_UNEXPECTED;
   }
   else
   {
     head = head_;
     head_ = head_->next_;
   }
   if (OB_SUCCESS != err)
   {}
   else if (OB_SUCCESS != (err = free_block(head)))
   {
     TBSYS_LOG(ERROR, "free_block()=>%d", err);
   }
   return err;
 }
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:25,代码来源:ob_stack_allocator.cpp

示例14: file_truncate_blocks

// Remove any blocks currently used by file 'f',
// but not necessary for a file of size 'newsize'.
// For both the old and new sizes, figure out the number of blocks required,
// and then clear the blocks from new_nblocks to old_nblocks.
// If the new_nblocks is no more than NDIRECT, and the indirect block has
// been allocated (f->f_indirect != 0), then free the indirect block too.
// (Remember to clear the f->f_indirect pointer so you'll know
// whether it's valid!)
// Do not change f->f_size.
static void
file_truncate_blocks(struct File *f, off_t newsize)
{
	int r, i;
	uint32_t old_nblocks, new_nblocks;

	// Hint: Use file_clear_block and/or free_block.
	// LAB 5: Your code here.

	if(newsize >= f->f_size)
		return;
	
	new_nblocks = newsize/BLKSIZE;
	if (newsize % BLKSIZE)
		new_nblocks++;
	
	old_nblocks = f->f_size/BLKSIZE;
	if (f->f_size % BLKSIZE)
		old_nblocks++;
	
	for(i=new_nblocks; i<old_nblocks; i++)
		if((r = file_clear_block(f, i)) < 0)
			panic("file_truncate_blocks - couldn't free blocks!");

	if(new_nblocks <= NDIRECT && old_nblocks > NDIRECT){
		free_block(f->f_indirect);				
		f->f_indirect = 0;
	}
	return;
}	
开发者ID:ren85,项目名称:jos2006,代码行数:39,代码来源:fs.c

示例15: free_block

static void free_block(struct k_mem_pool *p, int level, size_t *lsizes, int bn)
{
	int i, key, lsz = lsizes[level];
	void *block = block_ptr(p, lsz, bn);

	key = irq_lock();

	set_free_bit(p, level, bn);

	if (level && partner_bits(p, level, bn) == 0xf) {
		for (i = 0; i < 4; i++) {
			int b = (bn & ~3) + i;

			clear_free_bit(p, level, b);
			if (b != bn &&
			    block_fits(p, block_ptr(p, lsz, b), lsz)) {
				sys_dlist_remove(block_ptr(p, lsz, b));
			}
		}

		irq_unlock(key);
		free_block(p, level-1, lsizes, bn / 4); /* tail recursion! */
		return;
	}

	if (block_fits(p, block, lsz)) {
		sys_dlist_append(&p->levels[level].free_list, block);
	}

	irq_unlock(key);
}
开发者ID:bigdinotech,项目名称:zephyr,代码行数:31,代码来源:mempool.c


注:本文中的free_block函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。