コード例 #1
0
/*
 * Free resources previously allocated in nfs_node_reinit().
 */
void
nfs_node_done()
{
	pool_destroy(&nfs_node_pool);
	pool_destroy(&nfs_vattr_pool);
	malloc_type_detach(M_NFSNODE);
}
コード例 #2
0
ファイル: config.c プロジェクト: Krabby127/misc
config_t *load_config(pool_t *proc, const char *conf_path) {
	char *line = NULL;
	size_t len = 0;
	int rv;
	pool_t *tmp_pool;
	config_t *conf;

	FILE *fp = fopen(conf_path, "r");
	if (!fp) {
		fprintf(stderr, "Unable to open config file %s. Error %s", conf_path, strerror(errno));
		return NULL;
	}

	tmp_pool = pool_create(proc, "temporary config pool");
	conf = pool_alloc(proc, sizeof(*conf), "config object");

	/* format is A=B\n. Lines starting with # are comments. Empty lines are allowed. WS is allowed */
	while ((rv = readline(tmp_pool, &line, fp)) > 0) {
		char *l = line;
		while (isspace(*l)) l++;
		if ((l[0] != '#') && (l[0] != '\0'))  {
			process_config_line(proc, conf, l); 
		}
	}
	if (!feof(fp)) {
		fprintf(stderr, "Error while reading config file %s. Error %s", conf_path, strerror(ferror(fp)));
		pool_destroy(tmp_pool);
		return NULL;
	}
	pool_destroy(tmp_pool);
	return conf;
}
コード例 #3
0
ファイル: alloc_benchmark.c プロジェクト: jupvfranco/ohmm
static unsigned long long
profile_palloc_single_chars(const unsigned long iterations)
{
    struct timeval start;
    struct timeval stop;

    pool_reference char_ref_pool = pool_create(CHAR_REF_TYPE_ID);
    pool_reference char_pool = pool_create(CHAR_TYPE_ID);

    pool_grow(&char_ref_pool, iterations);
    
    global_reference *char_refs = pool_to_array(char_ref_pool);

    gettimeofday(&start, NULL);
    for (unsigned long i = 0 ; i < iterations ; ++i) {
        char_refs[i] = pool_alloc(&char_pool);
    }
    gettimeofday(&stop, NULL);

    pool_destroy(&char_ref_pool);
    pool_destroy(&char_pool);

    return ((stop.tv_sec - start.tv_sec) * 1000000LLU) +
            stop.tv_usec - start.tv_usec; 
}
コード例 #4
0
ファイル: test_pool_map.c プロジェクト: jupvfranco/ohmm
void
t_field_map(void)
{
    pool_reference list_pool = pool_create(LIST_TYPE_ID);
    CU_ASSERT_NOT_EQUAL_FATAL(list_pool, NULL_POOL);

    global_reference head = pool_alloc(&list_pool);
    pool_iterator itr = iterator_new(&list_pool, &head);

    size_t list_size = 10000;

    for (size_t i = 0 ; i < list_size ; ++i) {
        iterator_set_field(itr, 1, &i);
        iterator_list_insert(itr, pool_alloc(&list_pool));
        itr = iterator_next(list_pool, itr);
    }

    pool_reference long_pool = pool_create(LONG_TYPE_ID);
    CU_ASSERT_NOT_EQUAL_FATAL(long_pool, NULL_POOL);

    CU_ASSERT_EQUAL(field_map(list_pool, &long_pool, 1, square), 0);

    uint64_t *result = pool_to_array(long_pool);

    int cmp_error_count = 0;
    for (size_t i = 0 ; i < list_size ; ++i) {
        cmp_error_count += i*i != result[i];
    }

    CU_ASSERT_EQUAL(cmp_error_count, 0);

    iterator_destroy(&itr);
    pool_destroy(&long_pool);
    pool_destroy(&list_pool);
}
コード例 #5
0
ファイル: hashtable.c プロジェクト: srimalik/nfs-ganesha
/**
 * @brief Dispose of a hash table
 *
 * This function deletes all the entries from the given hash table and
 * then destroys the hash table.
 *
 * @param[in,out] ht        Pointer to the hash table.  After calling
 *                          this function, the memory pointed to by ht
 *                          must not be accessed in any way.
 * @param[in]     free_func Function to free entries as they are
 *                          deleted
 *
 * @return HASHTABLE_SUCCESS on success, other things on failure
 */
hash_error_t
hashtable_destroy(struct hash_table *ht,
		  int (*free_func)(struct gsh_buffdesc,
				   struct gsh_buffdesc))
{
	size_t index = 0;
	hash_error_t hrc = HASHTABLE_SUCCESS;

	hrc = hashtable_delall(ht, free_func);
	if (hrc != HASHTABLE_SUCCESS)
		goto out;

	for (index = 0; index < ht->parameter.index_size; ++index) {
		if (ht->partitions[index].cache) {
			gsh_free(ht->partitions[index].cache);
			ht->partitions[index].cache = NULL;
		}

		PTHREAD_RWLOCK_destroy(&(ht->partitions[index].lock));
	}
	pool_destroy(ht->node_pool);
	pool_destroy(ht->data_pool);
	gsh_free(ht);

 out:
	return hrc;
}
コード例 #6
0
/*
 * Free resources previously allocated in nfs_node_reinit().
 */
void
nfs_node_done(void)
{

	pool_destroy(&nfs_node_pool);
	pool_destroy(&nfs_vattr_pool);
	workqueue_destroy(nfs_sillyworkq);
}
コード例 #7
0
ファイル: ext2fs_vfsops.c プロジェクト: Hooman3/minix
void
ext2fs_done(void)
{

	ufs_done();
	pool_destroy(&ext2fs_inode_pool);
	pool_destroy(&ext2fs_dinode_pool);
}
コード例 #8
0
ファイル: scene.c プロジェクト: ifzz/merriment
void scene_destroy(Scene* scene) {
    cpSpaceFree(scene->space);

    // entities has to be first, because of relation with components
    pool_destroy(scene->entities);
    pool_destroy(scene->transforms);
    pool_destroy(scene->scripts);
    pool_destroy(scene->sprites);
    free(scene);
}
コード例 #9
0
int bacstack_session_destroy(bacstack_session_t *session)
{
  return 1 
      && rwlock_destroy(&session->routetable_lock)
      && bacstack_routetable_destroy(&session->routetable)
      && pool_destroy(&session->message_pool)
      && pool_destroy(&session->proc_pool)
      && bacdl_server_destroy(&session->dl_server)
      && thread_destroy(&session->msg_proc_thread)
      && thread_destroy(&session->dl_accept_thread)
      && thread_destroy(&session->dl_receive_thread);
}
コード例 #10
0
ファイル: glw.c プロジェクト: Allba/showtime
void
glw_fini(glw_root_t *gr)
{
  glw_text_bitmap_fini(gr);
  rstr_release(gr->gr_default_font);
  glw_tex_fini(gr);
  free(gr->gr_skin);
  glw_fini_settings(gr);
  pool_destroy(gr->gr_token_pool);
  pool_destroy(gr->gr_clone_pool);
  prop_courier_destroy(gr->gr_courier);
  hts_mutex_destroy(&gr->gr_mutex);
}
コード例 #11
0
ファイル: ik_speed_test.c プロジェクト: liqwalex/testgit
void upload_speed(char* dest_server_ip,char* interface_name,char* vist_domain)
{
	int i;
	int loop = HTTP_SEND_NUM;
	struct download_post_info info[HTTP_SEND_NUM];
	/*delay time */
	struct timeval starttime,endtime;
	
	/*fill struct for post */
	for(i=0;i<loop;i++){
		fill_upload_request(info[i].post_string,vist_domain);
		strncpy(info[i].server_ip,dest_server_ip,IPV4_SIZE);
		strncpy(info[i].interface,interface_name,MAX_NAME_LEN);
	}
	
	gettimeofday(&starttime,0);
	for(i=0;i<loop;i++){
		pool_add_worker(file_upload,&info[i]); 
	}
	while(1){ 
		usleep(1000);
		//IK_APP_DEBUG_LOG("pool->cur_queue_size == %d\n",pool->cur_queue_size);
		if(pool->cur_queue_size == 0){
			pool_destroy();
			gettimeofday(&endtime,0);
			double timeuse = (1000000*(endtime.tv_sec - starttime.tv_sec) + endtime.tv_usec - starttime.tv_usec)/1000000;
			double result = (sum_send_lens / timeuse / (1024 * 1024));
			printf("sum_lens: %lld byte | time_use: %f s | speed : %.2fMB\n",sum_send_lens,timeuse,result);
			break;
		}
	}
}
コード例 #12
0
/*
 * Deallocates a HacheTable object (created by HacheTableCreate).
 *
 * The deallocate_data parameter is a boolean to indicate whether the
 * data attached to the hash table should also be free()d. DO NOT USE
 * this if the HacheData attached was not a pointer allocated using
 * malloc().
 */
void HacheTableDestroy(HacheTable *h, int deallocate_data) {
    int i;

    if (!h)
	return;

    //HacheTableRefInfo(h, stdout);

    for (i = 0; i < h->nbuckets; i++) {
	HacheItem *hi = h->bucket[i], *next = NULL;
	for (hi = h->bucket[i]; hi; hi = next) {
	    assert(hi->h == h);
	    next = hi->next;
	    HacheItemDestroy(h, hi, deallocate_data);
	}
    }
    
    if (h->hi_pool) pool_destroy(h->hi_pool);

    if (h->bucket)
	free(h->bucket);

    if (h->ordering)
	free(h->ordering);

    free(h);
}
コード例 #13
0
ファイル: h_mgr.cpp プロジェクト: Gallaecio/0ad
static void Shutdown()
{
	debug_printf(L"H_MGR| shutdown. any handle frees after this are leaks!\n");
	// objects that store handles to other objects are destroyed before their
	// children, so the subsequent forced destruction of the child here will
	// raise a double-free warning unless we ignore it. (#860, #915, #920)
	ignoreDoubleFree = true;

	H_ScopedLock s;

	// forcibly close all open handles
	for(HDATA* hd = (HDATA*)hpool.da.base; hd < (HDATA*)(hpool.da.base + hpool.da.pos); hd = (HDATA*)(uintptr_t(hd)+hpool.el_size))
	{
		// it's already been freed; don't free again so that this
		// doesn't look like an error.
		if(hd->key == 0)
			continue;

		// disable caching; we need to release the resource now.
		hd->keep_open = 0;
		hd->refs = 0;

		h_free_hd(hd);
	}

	pool_destroy(&hpool);
}
コード例 #14
0
ファイル: test_rpc.c プロジェクト: HankMa/netcwmp
static void test_getset_parameter_node_value (abts_case *tc, void *data)
{
    cwmp_t * c = (cwmp_t*)data;

    parameter_node_t * param;
    char * name = "InternetGatewayDevice.DeviceInfo.SoftwareVersion";
    char * retval;
    char * value ;
    
    pool_t * pool = pool_create(POOL_DEFAULT_SIZE);
    FUNCTION_TRACE();
    param = cwmp_get_parameter_path_node(c->root, name);
    ASSERT_NOTNULL(param);
    
    value = "V1.3.x";

    cwmp_set_parameter_node_value(c, param, name, value, strlen(value));
    
    retval = cwmp_data_get_parameter_value(c, param, name, pool);
    printf("retval ------------------is %s\n", retval);
    ASSERT_STR_EQ(value, retval);
   
    
    value = "V1.4.x";
    cwmp_set_parameter_node_value(c, param, name, value, strlen(value));
    retval = cwmp_data_get_parameter_value(c, param, name, pool);
    ASSERT_STR_EQ(value, retval);
    
    
    pool_destroy(pool);

}
コード例 #15
0
ファイル: http_request.c プロジェクト: rentiansheng/devSync
void handle_request_socket(http_conf *g , struct epoll_event *evfd ) {

	epoll_extra_data_t * epoll_data = (epoll_extra_data_t *)evfd->data.ptr;

	http_connect_t *con = (http_connect_t *) epoll_data->ptr;

	if(con->in == NULL) {
		//accept_handler(g, con, evfd);
		epoll_edit_fd(g->epfd, evfd, EPOLL_W);
		return ;
		//epoll_del_fd(g->epfd, evfd);
	}
	while(con->next_handle != NULL) {
		int ret = con->next_handle(con);
		if(ret == DONE) {
			if(con->in->execute_file != NULL && con->in->execute_file->len > 0) {
				char *shPath = (char *)palloc(con->p, sizeof(char)*con->in->execute_file->len +1);
				strncpy(shPath, con->in->execute_file->ptr, con->in->execute_file->len);
				ds_log(con, " [send execute sh command:]", LOG_LEVEL_DEFAULT);
				send_execute_sh_cmd(con, g);
			}
			con->next_handle = NULL;
			epoll_del_fd(g->epfd, evfd);
			close(con->fd);
			ds_log(con, "  [END] ", LOG_LEVEL_DEFAULT);
			pool_destroy(con->p);
			//handle_request_destory(g, evfd);
		}else if(ret == CONTINUE) {
			break;
		}
	}
}
コード例 #16
0
static void TestEntries()
{
    const int SZ = 4;
    const int ALGN = 4;
    size_t size[SZ] = {8, 8000, 9000, 100*1024};
    size_t algn[ALGN] = {8, 64, 4*1024, 8*1024*1024};

    rml::MemPoolPolicy pol(getGranMem, putGranMem);
    currGranularity = 1; // not check granularity in the test
    rml::MemoryPool *pool;

    pool_create_v1(0, &pol, &pool);
    for (int i=0; i<SZ; i++)
        for (int j=0; j<ALGN; j++) {
            char *p = (char*)pool_aligned_malloc(pool, size[i], algn[j]);
            ASSERT(p && 0==((uintptr_t)p & (algn[j]-1)), NULL);
            memset(p, j, size[i]);

            size_t curr_algn = algn[rand() % ALGN];
            size_t curr_sz = size[rand() % SZ];
            char *p1 = (char*)pool_aligned_realloc(pool, p, curr_sz, curr_algn);
            ASSERT(p1 && 0==((uintptr_t)p1 & (curr_algn-1)), NULL);
            ASSERT(memEqual(p1, min(size[i], curr_sz), j), NULL);

            memset(p1, j+1, curr_sz);
            size_t curr_sz1 = size[rand() % SZ];
            char *p2 = (char*)pool_realloc(pool, p1, curr_sz1);
            ASSERT(p2, NULL);
            ASSERT(memEqual(p2, min(curr_sz1, curr_sz), j+1), NULL);

            pool_free(pool, p2);
        }

    pool_destroy(pool);
}
コード例 #17
0
ファイル: module.c プロジェクト: howard5888/wineT
/******************************************************************
 *		module_remove
 *
 */
BOOL module_remove(struct process* pcs, struct module* module)
{
    struct module**     p;

    TRACE("%s (%p)\n", module->module.ModuleName, module);
    hash_table_destroy(&module->ht_symbols);
    hash_table_destroy(&module->ht_types);
    HeapFree(GetProcessHeap(), 0, (char*)module->sources);
    HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
    pool_destroy(&module->pool);
    /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
     * so do we
     */
    for (p = &pcs->lmodules; *p; p = &(*p)->next)
    {
        if (*p == module)
        {
            *p = module->next;
            HeapFree(GetProcessHeap(), 0, module);
            return TRUE;
        }
    }
    FIXME("This shouldn't happen\n");
    return FALSE;
}
コード例 #18
0
NSAPI_PUBLIC void session_free(Session *sn)
{
    NSAPISession *nsn = (NSAPISession *) sn;

    // If this session was cloned,
    // Remove any filters that were installed during this session
    if (nsn->session_clone && sn->csd && sn->csd_open)
        filter_finish_response(sn);

    INTsession_cleanup(sn);
    if (sn->inbuf)
      netbuf_close(sn->inbuf);

    if (nsn->session_clone) {
        if (sn->csd && sn->csd_open)
            PR_Close(sn->csd);
        sn->csd = NULL;
        sn->csd_open = 0;

        pool_free(sn->pool, sn);
    } else {
        systhread_setdata(getThreadMallocKey(), NULL);
        pool_destroy(sn->pool);

        PERM_FREE(sn);
    }
}
コード例 #19
0
static void
udf_discstrat_finish_seq(struct udf_strat_args *args)
{
	struct udf_mount *ump = args->ump;
	struct strat_private *priv = PRIV(ump);
	int error;

	if (ump == NULL)
		return;

	/* stop our sheduling thread */
	KASSERT(priv->run_thread == 1);
	priv->run_thread = 0;
	wakeup(priv->queue_lwp);
	do {
		error = tsleep(&priv->run_thread, PRIBIO+1,
			"udfshedfin", hz);
	} while (error);
	/* kthread should be finished now */

	/* set back old device strategy method */
	VOP_IOCTL(ump->devvp, DIOCSSTRATEGY, &priv->old_strategy_setting,
			FWRITE, NOCRED);

	/* destroy our pool */
	pool_destroy(&priv->desc_pool);

	mutex_destroy(&priv->discstrat_mutex);
	cv_destroy(&priv->discstrat_cv);

	/* free our private space */
	free(ump->strategy_private, M_UDFTEMP);
	ump->strategy_private = NULL;
}
コード例 #20
0
void
v7fs_done(void)
{

    DPRINTF("\n");
    pool_destroy(&v7fs_node_pool);
}
コード例 #21
0
ファイル: module.c プロジェクト: alu3177/-LDH-Pract4
/******************************************************************
 *		module_remove
 *
 */
BOOL module_remove(struct process* pcs, struct module* module)
{
    struct module_format*modfmt;
    struct module**     p;
    unsigned            i;

    TRACE("%s (%p)\n", debugstr_w(module->module.ModuleName), module);

    for (i = 0; i < DFI_LAST; i++)
    {
        if ((modfmt = module->format_info[i]) && modfmt->remove)
            modfmt->remove(pcs, module->format_info[i]);
    }
    hash_table_destroy(&module->ht_symbols);
    hash_table_destroy(&module->ht_types);
    wine_rb_destroy(&module->sources_offsets_tree, NULL, NULL);
    HeapFree(GetProcessHeap(), 0, module->sources);
    HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
    pool_destroy(&module->pool);
    /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
     * so do we
     */
    for (p = &pcs->lmodules; *p; p = &(*p)->next)
    {
        if (*p == module)
        {
            *p = module->next;
            HeapFree(GetProcessHeap(), 0, module);
            return TRUE;
        }
    }
    FIXME("This shouldn't happen\n");
    return FALSE;
}
コード例 #22
0
ファイル: test-pool.c プロジェクト: rgs1/libsmall
static void test_basic(void)
{
  int i;
  void *start = NULL;
  void *item;
  pool *p = pool_new(100, 10);

  /* get all items */
  for (i=0; i < 10; i++) {
    item = pool_get(p);
    if (!i)
      start = item;
    assert(item);
  }

  assert(pool_get(p) == NULL);

  /* put all items */
  for (i=0; i < 10; i++) {
    void *t = (void *)((char *)start + (i * 10));
    pool_put(p, t);
  }

  /* get them back */
  for (i=0; i < 10; i++)
    assert(pool_get(p));

  pool_destroy(p);
}
コード例 #23
0
ファイル: list.c プロジェクト: rgs1/libsmall
SMALL_EXPORT void list_destroy(list *l)
{
  assert(l);
  assert(l->pool);
  pool_destroy(l->pool);
  free(l);
}
コード例 #24
0
ファイル: ik_speed_test.c プロジェクト: liqwalex/testgit
void download_speed(char* dest_server_ip,char* interface_name,char* vist_domain)
{
	/*https check ?*/
	/*create  url like http://speedtest.bmcc.com.cn/speedtest/random350x350.jpg */
	int size[] = {4000,4000,4000,3500,3500,3500,3000,3000,3000,2500,2500,2500,2000,2000,2000,1500,1500,1500,1000,1000,1000,750,750,750,500,500,500,350,350,350};
	int size_num = sizeof(size)/4;
	int i;
	struct download_post_info info[size_num];
	/*delay time */
	struct timeval starttime,endtime;

	
	for(i=0;i<size_num;i++){
		fill_down_request(info[i].post_string,size[i],vist_domain);
		strncpy(info[i].server_ip,dest_server_ip,IPV4_SIZE);
		strncpy(info[i].interface,interface_name,MAX_NAME_LEN);
	}
	gettimeofday(&starttime,0);
	for(i=0;i<size_num;i++){
		pool_add_worker(file_download,&info[i]); 
	}
	while(1){ 
		usleep(1000);
		//IK_APP_DEBUG_LOG("cur_queue_size = %d\n",pool->cur_queue_size);
		if(pool->cur_queue_size == 0){
			pool_destroy();
			/*when the pool been destroy , mission had been done */
			gettimeofday(&endtime,0);
			double timeuse = (1000000*(endtime.tv_sec - starttime.tv_sec) + endtime.tv_usec - starttime.tv_usec)/1000000;
			double result = (sum_lens / timeuse / (1024 * 1024));
			printf("sum_lens: %lld byte | time_use: %f s | speed : %.2fMB\n",sum_lens,timeuse,result);
			break;
		}
	}
}
コード例 #25
0
ファイル: obj.c プロジェクト: joerong666/hidb
void *new_obj(pool_t *mpool, size_t sz)
{
    pool_t *mp = mpool;
    obj_t *ob = NULL;

    if (mp == NULL) {
        mp = pool_create(G_MPOOL_SIZE);
        if (mp == NULL) {
            return NULL;
        }

        ob = (obj_t *)pcalloc(mp, sz);
        if (ob == NULL) {
            pool_destroy(mp);
            return NULL;
        }   

        ob->new_mp_flag = 1;
    } else {
        ob = pcalloc(mp, sz);
        if (ob == NULL) {
            return NULL;
        }   

        ob->new_mp_flag = 0;
    }   

    ob->mpool = mp; 
    return ob;
}
コード例 #26
0
// single pool shared by different threads
void TestSharedPool()
{
    rml::MemPoolPolicy pol(getMallocMem, putMallocMem);
    rml::MemoryPool *pool;

    pool_create_v1(0, &pol, &pool);
    void **crossThread = new void*[MaxThread * SharedPoolRun::OBJ_CNT];
    void **afterTerm = new void*[MaxThread * SharedPoolRun::OBJ_CNT];

    for (int p=MinThread; p<=MaxThread; p++) {
        SharedPoolRun::init(p, pool, crossThread, afterTerm);
        SharedPoolRun thr;

        void *hugeObj = pool_malloc(pool, 10*1024*1024);
        ASSERT(hugeObj, NULL);

        NativeParallelFor( p, thr );

        pool_free(pool, hugeObj);
        for (int i=0; i<p*SharedPoolRun::OBJ_CNT; i++)
            pool_free(pool, afterTerm[i]);
    }
    delete []afterTerm;
    delete []crossThread;

    pool_destroy(pool);
    ASSERT(!liveRegions, "Expected all regions were released.");
}
コード例 #27
0
/******************************************************************
 *              macho_load_debug_info_from_map
 *
 * Loads the symbolic information from a Mach-O module.
 * Returns
 *      FALSE if the file doesn't contain symbolic info (or this info
 *              cannot be read or parsed)
 *      TRUE on success
 */
static BOOL macho_load_debug_info_from_map(struct module* module,
                                           struct macho_file_map* fmap)
{
    BOOL                    ret = FALSE;
    struct macho_debug_info mdi;
    int                     result;

    TRACE("(%p, %p/%d)\n", module, fmap, fmap->fd);

    module->module.SymType = SymExport;

    mdi.fmap = fmap;
    mdi.module = module;
    pool_init(&mdi.pool, 65536);
    hash_table_init(&mdi.pool, &mdi.ht_symtab, 256);
    result = macho_enum_load_commands(fmap, LC_SYMTAB, macho_parse_symtab, &mdi);
    if (result > 0)
        ret = TRUE;
    else if (result < 0)
        WARN("Couldn't correctly read stabs\n");

    macho_finish_stabs(module, &mdi.ht_symtab);

    pool_destroy(&mdi.pool);
    return ret;
}
コード例 #28
0
    void operator()( int id ) const {
        rml::MemPoolPolicy pol(CrossThreadGetMem, CrossThreadPutMem);
        const int objLen = 10*id;

        pool_create_v1(id, &pol, &pool[id]);
        obj[id] = (char*)pool_malloc(pool[id], objLen);
        ASSERT(obj[id], NULL);
        memset(obj[id], id, objLen);

        {
            const size_t lrgSz = 2*16*1024;
            void *ptrLarge = pool_malloc(pool[id], lrgSz);
            ASSERT(ptrLarge, NULL);
            memset(ptrLarge, 1, lrgSz);

            // consume all small objects
            while (pool_malloc(pool[id], 5*1024))
                ;
            // releasing of large object can give a chance to allocate more
            pool_free(pool[id], ptrLarge);

            ASSERT(pool_malloc(pool[id], 5*1024), NULL);
        }

        barrier.wait();
        int myPool = number_of_threads-id-1;
        for (int i=0; i<10*myPool; i++)
            ASSERT(myPool==obj[myPool][i], NULL);
        pool_free(pool[myPool], obj[myPool]);
        pool_destroy(pool[myPool]);
    }
コード例 #29
0
void TestFixedBufferPool()
{
    void *ptrs[7];
    rml::MemPoolPolicy pol(fixedBufGetMem, NULL, 0, /*fixedSizePool=*/true,
                           /*keepMemTillDestroy=*/false);
    rml::MemoryPool *pool;

    pool_create_v1(0, &pol, &pool);
    void *largeObj = pool_malloc(pool, 7*1024*1024);
    ASSERT(largeObj, NULL);
    pool_free(pool, largeObj);

    for (int i=0; i<7; i++) {
        ptrs[i] = pool_malloc(pool, 1024*1024);
        ASSERT(ptrs[i], NULL);
    }
    for (int i=0; i<7; i++)
        pool_free(pool, ptrs[i]);

    largeObj = pool_malloc(pool, 7*1024*1024);
    ASSERT(largeObj, NULL);
    pool_free(pool, largeObj);

    pool_destroy(pool);
}
コード例 #30
0
ファイル: thread_pool.c プロジェクト: LXiong/blog_tmp
int
main(int argc, char *argv[])
{
	int NUM_THREAD = 100;
	int NUM_WORK = 10;

	/* 线程池中最多 xx 个活动线程 */
	init_thread_pool(NUM_THREAD);
	/* 连续向池中投入 xx 个任务 */
	int *working_num = (int *) malloc(sizeof(int) * NUM_WORK);

	int i;
	for (i = 0; i < NUM_WORK ; ++i) {
		working_num[i] = i;
		pool_add_worker(thread_func, &working_num[i]);
	}
	printf("\n");

	/* 等待所有任务完成 */
	//sleep (5);
	/* 销毁线程池 */
	pool_destroy();
	free(working_num);

	return 0;
}