예제 #1
0
void init_top(t_topology *top)
{
    top->name = NULL;
    init_atom(&(top->atoms));
    init_atomtypes(&(top->atomtypes));
    init_block(&top->cgs);
    init_block(&top->mols);
    init_blocka(&top->excls);
    open_symtab(&top->symtab);
}
예제 #2
0
void init_molinfo(t_molinfo *mol)
{
    mol->nrexcl     = 0;
    mol->excl_set   = FALSE;
    mol->bProcessed = FALSE;
    init_plist(mol->plist);
    init_block(&mol->cgs);
    init_block(&mol->mols);
    init_blocka(&mol->excls);
    init_atom(&mol->atoms);
}
예제 #3
0
파일: merge.cpp 프로젝트: CyberDem0n/allter
CMerge::CMerge(int fd, int blk_size, int mem_size) : _fd(fd), elemen_count(0), block_size(blk_size) {
	num_elements = (int) (lseek(_fd, 0, SEEK_END) / sizeof(uint64_t));
	num_blocks = (int) ((num_elements - 1) / block_size);
	blocks = new struct block[num_blocks + 1];
	buffer_size = (int) (mem_size / sizeof(uint64_t) / (num_blocks + 1)); // Buffer size (in elements)
	if (buffer_size == 0)
		buffer_size = 1;
	for (int i = 0; i < num_blocks; i++)
		init_block(i, block_size);
	init_block(num_blocks, num_elements - block_size*num_blocks);
	num_blocks++;

	printf("num_blocks=%d, buffer_size=%lu\n", num_blocks, buffer_size);
}
예제 #4
0
파일: cache.c 프로젝트: gpichon/caches-pfa
/* Data allocations */
struct cache* init_cache(int size, int linesize, int nb_ways, int nb_blocks, int depth, void (*replace)(struct cache *), enum cache_coherence policy, int type, bool snooping, bool directory) {
  struct cache *cache   = malloc(sizeof(struct cache));
  assert(cache!=NULL);
  cache->size           = size;
  cache->linesize       = linesize;
  cache->nb_ways        = nb_ways;
  cache->nb_blocks      = nb_blocks;
  struct block **blocks = init_block(nb_blocks, nb_ways, linesize, policy);
  cache->blocks         = blocks;
  unsigned int i;
  for (i = 0; i < tracking_count; i++) {
    cache->misses[i]                = 0;
    cache->hits[i]                  = 0;
    cache->writes_back[i]           = 0;
    cache->evincted_coherence[i]    = 0;
    cache->evincted_capacity[i]     = 0;
    cache->evincted_caches_types[i] = 0;
    cache->misses_snooping[i]       = 0;
    cache->misses_above[i]          = 0;
    cache->misses_below[i]          = 0;
    cache->broadcast_coherence[i]   = 0;
    cache->broadcast_snooping[i]    = 0;
  }
  cache->depth          = depth;
  cache->type           = type;
  cache->snooping       = snooping;
  cache->directory      = directory;
  cache->policy         = policy;
  replace(cache);
  return cache;
}
예제 #5
0
파일: main.c 프로젝트: YanMinge/Smart_servo
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    volatile uint32_t u32InitCount;
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    init_neuron_system();
		
	init_block();
	
    while(1)
    {
		// protocol.
		parse_uart0_recv_buffer();
        flush_uart1_to_uart0();
        flush_uart0_local_buffer();	
		
		// led
		poll_led_request();
    }
}
예제 #6
0
/**
 *  Constructor Function: allocate memories for the pools 
 *                        and init the variable values
 *
*/
BufferManager::BufferManager():total_block(0),total_file(0),fileHead(NULL)
{
    for (int i = 0; i < MAX_FILE_NUM; i ++)
    {
        file_pool[i].fileName = new char[MAX_FILE_NAME];
        if(file_pool[i].fileName == NULL)
        {
            printf("Can not allocate memory in initing the file pool!\n");
            exit (1);
        }
        init_file(file_pool[i]);
    }
    for (int i = 0; i < MAX_BLOCK_NUM; i ++) {
        block_pool[i].address = new char[BLOCK_SIZE];
        if(block_pool[i].address == NULL)
        {
            printf("Can not allocate memory in initing the block pool!\n");
            exit (1);
        }
        block_pool[i].fileName = new char[MAX_FILE_NAME];
        if(block_pool[i].fileName == NULL)
        {
            printf("Can not allocate memory in initing the block pool!\n");
            exit (1);
        }
        init_block(block_pool[i]);
    }
}
예제 #7
0
파일: add_block.c 프로젝트: gtandeo/malloc
static void	*add_block(size_t size, t_block *list)
{
	t_block		*tmp;
	t_block		*block;

	tmp = list;
	if (tmp && size <= tmp->size && tmp->is_free == 1)
	{
		tmp->size = size;
		tmp->is_free = 0;
		return (&(tmp->ptr));
	}
	while (tmp && tmp->next)
	{
		if (size <= tmp->size && tmp->is_free == 1)
		{
			tmp->size = size;
			tmp->is_free = 0;
			return (&(tmp->ptr));
		}
		tmp = tmp->next;
	}
	tmp->next = tmp + sizeof(t_block) - sizeof(tmp->data) + tmp->size;
	init_block(&block, tmp, size);
	/*block = tmp->next;
	block->size = size;
	block->prev = tmp;
	block->next = NULL;
	block->is_free = 0;*/
	return (&(block->ptr));
}
예제 #8
0
파일: Wrappers.c 프로젝트: Mystro256/Not64
void dynarec(unsigned int address){
	while(!stop){
		refresh_stat();
		
		start_section(TRAMP_SECTION);
		PowerPC_block* dst_block = blocks_get(address>>12);
		unsigned long paddr = update_invalid_addr(address);
		/*
		sprintf(txtbuffer, "trampolining to 0x%08x\n", address);
		DEBUG_print(txtbuffer, DBG_USBGECKO);
		*/
		if(!paddr){
			link_branch = NULL;
			address = interp_addr;
			dst_block = blocks_get(address>>12); 
			paddr = update_invalid_addr(address);
		}
		
		if(!dst_block){
			/*sprintf(txtbuffer, "block at %08x doesn't exist\n", address&~0xFFF);
			DEBUG_print(txtbuffer, DBG_USBGECKO);*/
			dst_block = calloc(1, sizeof(PowerPC_block));
			blocks_set(address>>12, dst_block);
			dst_block->start_address = address & ~0xFFF;
			dst_block->end_address   = (address & ~0xFFF) + 0x1000;
			init_block(dst_block);
		} else if(invalid_code_get(address>>12)){
예제 #9
0
/* "Load" a plaayfield and set the game to that one */
static int goto_level(game_t *p_game)
{
  int i,j;

  if (p_game->level >= p_game->levels)
    return -1;

  rand_nr = 0;
  p_game->nr_blocks=0;
  fe_load_data(p_game->p_levels, p_game->level*((FIELD_WIDTH+1)*(FIELD_HEIGHT-4)+1)+6, (FIELD_WIDTH+1)*FIELD_HEIGHT, "Zarkanoid");

  /* Set the data for the level */
  for(j=0; j<FIELD_HEIGHT-4; j++)
    {
      for(i=0; i<FIELD_WIDTH; i++)
	{
	  uint8_t curr = p_game->p_levels[j*(FIELD_WIDTH+1)+i]-'0';
	  block_t *p_block = &p_game->p_field[j*FIELD_WIDTH+i];

	  /* If field[x,y] is not empty */
	  if (curr && !((curr & TYPE_IMPOSSIBLE) == TYPE_IMPOSSIBLE))
	    p_game->nr_blocks++;
	  init_block(p_block, curr);
	  draw_block(p_block, i, j);
	}
    }

  return 0;
}
예제 #10
0
파일: shm_alloc.c 프로젝트: seco/pipelinedb
/*
 * ShmemDynAlloc
 */
void *
ShmemDynAlloc(Size size)
{
	void *block = NULL;
	Size padded_size;

	size = Max(ALIGN(size), MIN_ALLOC_SIZE);
	for (padded_size = 1; padded_size < size && padded_size <= 1024; padded_size *= 2);
	size = Max(size, padded_size);

	block = get_block(size);

	if (block == NULL)
	{
		/*
		 * Don't request fewer than 1k from ShmemAlloc.
		 * The more contiguous memory we have, the better we
		 * can combat fragmentation.
		 */
		Size alloc_size = Max(size, MIN_SHMEM_ALLOC_SIZE);
		block = ShmemAlloc(BLOCK_SIZE(alloc_size));

		memset(block, 0, BLOCK_SIZE(alloc_size));
		block = (void *) ((intptr_t) block + sizeof(Header));
		init_block(block, alloc_size, true);
		mark_allocated(block);
	}

	if (get_size(block) - size >= MIN_BLOCK_SIZE)
		split_block(block, size);

	Assert(is_allocated(block));

	return block;
}
예제 #11
0
파일: mdt.c 프로젝트: Ale1ster/kerneldir
static int
nilfs_mdt_insert_new_block(struct inode *inode, unsigned long block,
			   struct buffer_head *bh,
			   void (*init_block)(struct inode *,
					      struct buffer_head *, void *))
{
	struct nilfs_inode_info *ii = NILFS_I(inode);
	void *kaddr;
	int ret;

	/* Caller exclude read accesses using page lock */

	/* set_buffer_new(bh); */
	bh->b_blocknr = 0;

	ret = nilfs_bmap_insert(ii->i_bmap, block, (unsigned long)bh);
	if (unlikely(ret))
		return ret;

	set_buffer_mapped(bh);

	kaddr = kmap_atomic(bh->b_page, KM_USER0);
	memset(kaddr + bh_offset(bh), 0, 1 << inode->i_blkbits);
	if (init_block)
		init_block(inode, bh, kaddr);
	flush_dcache_page(bh->b_page);
	kunmap_atomic(kaddr, KM_USER0);

	set_buffer_uptodate(bh);
	nilfs_mark_buffer_dirty(bh);
	nilfs_mdt_mark_dirty(inode);
	return 0;
}
예제 #12
0
int Connection::on_readable()
{
	while (1) {
		if (mreq_ == NULL && init_block() < 0) {
			return -1;
		}

		int rstat, retval;
		if ((rstat = do_read()) == RR_ERROR) {
			return -1;
		}

		if ((retval = handle_block()) < 0) {
			return -1;
		}

		if (rstat == RR_MAY_MORE) {
			continue;
		}
		else if (rstat == RR_CLOSED_BY_PEER) {
			return -1;
		}
		else {
			return 0;
		}
	}

	// can not reach here
	assert(0);
	return 0;	
}
예제 #13
0
파일: labels.c 프로젝트: fido2478/epspectra
int init_labels (void) {
    int i;

    for (i=0; i<LABEL_HASHES; i++) {
	ltab[i] = (union label *) nasm_malloc (LBLK_SIZE);
	if (!ltab[i])
	    return -1;		       /* can't initialise, panic */
	init_block (ltab[i]);
	lfree[i] = ltab[i];
    }

    perm_head = perm_tail = (struct permts *) nasm_malloc (sizeof(struct permts));
    if (!perm_head)
    	return -1;

    perm_head->next = NULL;
    perm_head->size = PERMTS_SIZE;
    perm_head->usage = 0;

    prevlabel = "";

    initialised = TRUE;

    return 0;
}
예제 #14
0
파일: nir_opt_dce.c 프로젝트: Unr34ler/mesa
static bool
nir_opt_dce_impl(nir_function_impl *impl)
{
   struct exec_list *worklist = ralloc(NULL, struct exec_list);
   exec_list_make_empty(worklist);

   nir_foreach_block(block, impl) {
      init_block(block, worklist);
   }
예제 #15
0
파일: typedefs.c 프로젝트: aar2163/GROMACS
void init_mtop(gmx_mtop_t *mtop)
{
  mtop->name = NULL;
  mtop->nmoltype = 0;
  mtop->moltype = NULL;
  mtop->nmolblock = 0;
  mtop->molblock = NULL;
  init_groups(&mtop->groups);
  init_block(&mtop->mols);
  open_symtab(&mtop->symtab);
}
예제 #16
0
파일: shm_alloc.c 프로젝트: seco/pipelinedb
static void
split_block(void *ptr, Size size)
{
	Size orig_size = get_size(ptr);
	void *new_block = (void *) ((intptr_t) ptr + size + sizeof(Header));
	Header *header = get_header(ptr);

	init_block(new_block, orig_size - size - sizeof(Header), false);
	insert_block(new_block);

	header->size = size;
	header->is_allocated = true;
}
예제 #17
0
파일: trees.cpp 프로젝트: lesteriv/libcrest
void _tr_init( z_stream& s )
{
    s.l_desc.dyn_tree = s.dyn_ltree;
    s.l_desc.stat_desc = &static_l_desc;

    s.d_desc.dyn_tree = s.dyn_dtree;
    s.d_desc.stat_desc = &static_d_desc;

    s.bl_desc.dyn_tree = s.bl_tree;
    s.bl_desc.stat_desc = &static_bl_desc;

    init_block(s);
}
예제 #18
0
/* initializes a cache for writing a new node of a tree (not reading first) */
PUBLIC struct cache *init_node( blocknr_t blocknr,
								uint16_t type, uint16_t level) {
	printf("debug: init_node %d %x %d\n", blocknr, type, level);
	struct cache *c = init_block(blocknr);
	if (c) {
		c->u.node.header.header_magic = HEADER_MAGIC;
		c->u.node.header.blocknr = blocknr;
		c->u.node.header.type = type;
		c->u.node.header.nritems = 0;
		c->u.node.header.level = level;
	}
	return c;
}
예제 #19
0
/**
 * Load blocks 0..n into a bstore, where each block
 * has the value given by init_block and is later
 * verifyed by verify_block
 */
static void load_some_blocks(struct bstore_s * bstore, 
        int magic, int num_blocks)
{
    int ret, i;
    char * buf = malloc(BSTORE_BLOCKSIZE);

    for (i = 0; i < num_blocks; i++) {
        init_block(buf, magic, i);
        ret = bstore_put(bstore, i, buf);
        assert(ret == 0);
    }
    free(buf);
}
예제 #20
0
파일: labels.c 프로젝트: sunank200/ATOM-OS
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is TRUE.
 */
static union label *find_label(char *label, int create)
{
    int hash = 0;
    char *p, *prev;
    int prevlen;
    union label *lptr;

    if (islocal(label))
        prev = prevlabel;
    else
        prev = "";
    prevlen = strlen(prev);
    p = prev;
    while (*p)
        hash += *p++;
    p = label;
    while (*p)
        hash += *p++;
    hash %= LABEL_HASHES;
    lptr = ltab[hash];
    while (lptr->admin.movingon != END_LIST) {
        if (lptr->admin.movingon == END_BLOCK) {
            lptr = lptr->admin.next;
            if (!lptr)
                break;
        }
        if (!strncmp(lptr->defn.label, prev, prevlen) &&
            !strcmp(lptr->defn.label + prevlen, label))
            return lptr;
        lptr++;
    }
    if (create) {
        if (lfree[hash]->admin.movingon == END_BLOCK) {
            /*
             * must allocate a new block
             */
            lfree[hash]->admin.next =
                (union label *)nasm_malloc(LBLK_SIZE);
            lfree[hash] = lfree[hash]->admin.next;
            init_block(lfree[hash]);
        }

        lfree[hash]->admin.movingon = BOGUS_VALUE;
        lfree[hash]->defn.label = perm_copy(prev, label);
        lfree[hash]->defn.special = NULL;
        lfree[hash]->defn.is_global = NOT_DEFINED_YET;
        return lfree[hash]++;
    } else
        return NULL;
}
예제 #21
0
파일: labels.c 프로젝트: zoro0312/Liux
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is true.
 */
static union label *find_label(char *label, int create)
{
    char *prev;
    int prevlen, len;
    union label *lptr, **lpp;
    char label_str[IDLEN_MAX];
    struct hash_insert ip;

    if (islocal(label)) {
        prev = prevlabel;
        prevlen = strlen(prev);
        len = strlen(label);
        if (prevlen + len >= IDLEN_MAX) {
            nasm_error(ERR_NONFATAL, "identifier length exceed %i bytes",
                       IDLEN_MAX);
            return NULL;
        }
        memcpy(label_str, prev, prevlen);
        memcpy(label_str+prevlen, label, len+1);
        label = label_str;
    } else {
        prev = "";
        prevlen = 0;
    }

    lpp = (union label **) hash_find(&ltab, label, &ip);
    lptr = lpp ? *lpp : NULL;

    if (lptr || !create)
        return lptr;

    /* Create a new label... */
    if (lfree->admin.movingon == END_BLOCK) {
        /*
         * must allocate a new block
         */
        lfree->admin.next = (union label *)nasm_malloc(LBLK_SIZE);
        lfree = lfree->admin.next;
        init_block(lfree);
    }

    lfree->admin.movingon = BOGUS_VALUE;
    lfree->defn.label = perm_copy(label);
    lfree->defn.special = NULL;
    lfree->defn.is_global = NOT_DEFINED_YET;

    hash_add(&ip, lfree->defn.label, lfree);
    return lfree++;
}
예제 #22
0
diskblock_t create_block(int index, int type) {
  // load the space to be used from the disk
  diskblock_t block = virtual_disk[index];

  //clear it
  if(type == DIR) init_dir_block(&block);
  if(type == DATA) init_block(&block);
  // // give it some data
  // memcpy(block.data, "data", strlen("data"));

  //save the block to the disk
  write_block(&block, index, 'd'); //writing as data seems to work even for dir

  return block;
}
예제 #23
0
파일: main.c 프로젝트: YanMinge/Smart_servo
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();
	
    init_neuron_system();
	
    init_block( );

    while(1)
    {
        // protocol.
        parse_uart0_recv_buffer();
        flush_uart1_to_uart0();
        flush_uart0_local_buffer();
		
        // led.
        poll_led_request();
		
        get_sensor_data();
		
        // on line.
        if(g_block_no != 0) 
        {
            send_sensor_report_online();
        }
		
        // off line.
        else if(g_block_no == 0)
        {
			uint32_t current_millis = millis();
            if((current_millis - s_offline_start_mills) > OFF_LINE_REPORT_PERIOD)
            {
                s_offline_start_mills = current_millis;
                send_sensor_report_offline();
            }
        }
    }
}
예제 #24
0
void	split_block(t_block *b, size_t mem_width)
{
    t_block	*nb;

    if (b->size + BLOCK_SIZE == mem_width)
        return ;
    if (mem_width < b->size + BLOCK_SIZE * 2)
    {
        b->size = mem_width - BLOCK_SIZE;
        return ;
    }
    nb = (t_block*)(BDATA(b) + b->size - 1);
    init_block(nb, mem_width - BLOCK_SIZE * 2 - b->size);
    nb->next = b->next;
    b->next = nb;
    nb->prev = b;
    nb->is_free = 1;
}
예제 #25
0
파일: game.c 프로젝트: AlexLiuyuren/myos
int game_main(){
		init_game();
	while(1){
		printg("game_main\n");
	//	printk("hello");
		clear_letter_pressed();
		printg("init_game");
		black_screen();
		prepare_buffer();
		draw_border();
		display_buffer();
		//system_enable_interrupt();
		init_block();
		printg("gamestart");
		game_loop();
		sleep(2);
	}
	return 0;
}
예제 #26
0
/**
 * Flush all block node in the list to the disk
 *
 * @return void
 *
 */
void BufferManager::writtenBackToDiskAll()
{
    blockNode *btmp = NULL;
    fileNode *ftmp = NULL;
    if(fileHead)
    {
        for(ftmp = fileHead;ftmp != NULL;ftmp = ftmp ->nextFile)
        {
            if(ftmp->blockHead)
            {
                for(btmp = ftmp->blockHead;btmp != NULL;btmp = btmp->nextBlock)
                {
                    if(btmp->preBlock)init_block(*(btmp -> preBlock));
                    writtenBackToDisk(btmp->fileName, btmp);
                }
            }
        }
    }
}
예제 #27
0
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is true.
 */
static union label *find_label(const char *label, bool create, bool *created)
{
    union label *lptr, **lpp;
    char *label_str = NULL;
    struct hash_insert ip;

    nasm_assert(label != NULL);

    if (islocal(label))
        label = label_str = nasm_strcat(prevlabel, label);

    lpp = (union label **) hash_find(&ltab, label, &ip);
    lptr = lpp ? *lpp : NULL;

    if (lptr || !create) {
        if (created)
            *created = false;
        return lptr;
    }

    /* Create a new label... */
    if (lfree->admin.movingon == END_BLOCK) {
        /*
         * must allocate a new block
         */
        lfree->admin.next = nasm_malloc(LBLK_SIZE);
        lfree = lfree->admin.next;
        init_block(lfree);
    }

    if (created)
        *created = true;

    nasm_zero(*lfree);
    lfree->defn.label     = perm_copy(label);
    lfree->defn.subsection = NO_SEG;
    if (label_str)
        nasm_free(label_str);

    hash_add(&ip, lfree->defn.label, lfree);
    return lfree++;
}
예제 #28
0
static void *alloc_pool_cell(am_pool *pool, size_t sz) {
#ifdef AM_PRINT_ALLOC_STATS
    update_stats_alloc(&pool->stats, sz);
#endif
    if (pool->freelist != NULL) {
        void *ptr = (void*)pool->freelist;
        pool->freelist = (void**)(*(pool->freelist));
        return ptr;
    } else {
        // need to allocate new block
        pool->num_blocks++;
        pool->blocks = (void**)realloc(pool->blocks, sizeof(void*) * pool->num_blocks);
        void *block = malloc(pool->blocksize);
        pool->blocks[pool->num_blocks - 1] = block;
        init_block(block, pool->cellsize, pool->blocksize);
        void **first = (void**)block;
        pool->freelist = (void**)(*first);
        return (void*)first;
    }
}
예제 #29
0
int init_labels(void)
{
    hash_init(&ltab, HASH_LARGE);

    ldata = lfree = nasm_malloc(LBLK_SIZE);
    init_block(lfree);

    perm_head = perm_tail =
        nasm_malloc(sizeof(struct permts));

    perm_head->next = NULL;
    perm_head->size = PERMTS_SIZE;
    perm_head->usage = 0;

    prevlabel = "";

    initialized = true;

    return 0;
}
예제 #30
0
파일: mydeflate.c 프로젝트: krunt/projects
void mydeflate_init(compression_state_t *state, zstream_t *stream) 
{
    int i;
    memset(state, 0, sizeof(compression_state_t));

    state->window_size = WINDOW_SIZE;
    state->wsize = WINDOWHALF_SIZE;
    state->strstart = 0;
    state->lookahead = 0;
    state->ins_h = 0;

    state->hash_bits = HASH_BITS;
    state->hash_size = 1<<state->hash_bits;
    state->hash_mask = state->hash_size - 1;
    state->hash_shift = ((state->hash_bits + MIN_MATCH-1)/MIN_MATCH);

    state->head = (int *)malloc(state->hash_size * sizeof(int));
    for (i = 0; i < state->hash_size; ++i) state->head[i] = NIL;

    state->match_length = 0;
    state->match_start = 0;

    state->buf_size = BUFFER_SIZE;
    state->l_buf = (char*)malloc(state->buf_size * sizeof(char));
    state->d_buf = (char*)malloc(state->buf_size * sizeof(char));
    state->max_code = 0;

    init_block(state);

    state->heap_len = 0;
    state->heap_max = 0;

    state->pending_buf_size = PENDING_BUF_SIZE;
    state->pending_buf_pointer = 0;
    state->pending_val = 0;
    state->bits_avail = 8;
    state->opt_len = 0;
    state->stream = stream;

    mydeflate_init_static_tables();
}