Ejemplo n.º 1
0
/*
 * This is a tricky allocation function using the zlib.
 * This is based on the allocation order in deflateInit2.
 */
static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
{
	struct comp_ctx *ctx = opaque;
	static char round = 0; /* order in deflateInit2 */
	void *buf = NULL;

	if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < (long)(items * size))
		goto end;

	switch (round) {
		case 0:
			if (zlib_pool_deflate_state == NULL)
				zlib_pool_deflate_state = create_pool("zlib_state", size * items, MEM_F_SHARED);
			ctx->zlib_deflate_state = buf = pool_alloc2(zlib_pool_deflate_state);
		break;

		case 1:
			if (zlib_pool_window == NULL)
				zlib_pool_window = create_pool("zlib_window", size * items, MEM_F_SHARED);
			ctx->zlib_window = buf = pool_alloc2(zlib_pool_window);
		break;

		case 2:
			if (zlib_pool_prev == NULL)
				zlib_pool_prev = create_pool("zlib_prev", size * items, MEM_F_SHARED);
			ctx->zlib_prev = buf = pool_alloc2(zlib_pool_prev);
		break;

		case 3:
			if (zlib_pool_head == NULL)
				zlib_pool_head = create_pool("zlib_head", size * items, MEM_F_SHARED);
			ctx->zlib_head = buf = pool_alloc2(zlib_pool_head);
		break;

		case 4:
			if (zlib_pool_pending_buf == NULL)
				zlib_pool_pending_buf = create_pool("zlib_pending_buf", size * items, MEM_F_SHARED);
			ctx->zlib_pending_buf = buf = pool_alloc2(zlib_pool_pending_buf);
		break;
	}
	if (buf != NULL)
		zlib_used_memory += items * size;

end:

	/* deflateInit2() first allocates and checks the deflate_state, then if
	 * it succeeds, it allocates all other 4 areas at ones and checks them
	 * at the end. So we want to correctly count the rounds depending on when
	 * zlib is supposed to abort.
	 */
	if (buf || round)
		round = (round + 1) % 5;
	return buf;
}
Ejemplo n.º 2
0
group_t *create_group(char *name){
  list_t *element;
  group_t *my_group;
  int size_string;
  if(!groups)
    groups = create_pool();
  
  element = search(groups, cmp_group, (void*) name); 
  
  if(element){
    my_group = (group_t*) element->args;
    return my_group;
  }
  
  my_group = (group_t *) malloc (sizeof(group_t));
  assert(my_group);
  add_pool_head(groups,my_group);
  
  size_string = strlen(name) + 1;
  my_group->name = (char*) malloc (sizeof(char) * size_string);
  assert(my_group->name);
  
  strcpy(my_group->name,name);
  my_group->name[size_string-1] = '\0';
  
  my_group->pending_q = create_pool();
  my_group->executing_q = create_pool();
  my_group->finished_q = create_pool();
  
  my_group->pending_num=0;
  my_group->executing_num = 0;
  my_group->finished_sig_num = 0;
  my_group->finished_non_sig_num = 0;
  
  my_group->total_sig_tasks = 0;
  my_group->total_non_sig_tasks = 0;
  
  my_group->locked = 0;
  my_group->terminated = 0;
  my_group->schedule = 1;
  my_group->executed = 0;
  my_group->result = 0;
  my_group->sanity_func = NULL;
  
  my_group->redo = 0;
  my_group->ratio = -1.0;
  
  pthread_cond_init(&my_group->condition,NULL);
  
  return my_group;
}
Ejemplo n.º 3
0
int add_pool(struct bank * b) {
    struct pool ** aux_b = NULL;
    int i=0;

    if(!b || (b->_max_pools && (b->_allocd_pools == b->_max_pools))) {
        return -1;
    }

    if(!(aux_b = _b_allocator(
                    (b->_allocd_pools+1)*sizeof(struct pool *)))) {
        return -1;
    }

    for(i=0; i<b->_allocd_pools ; i++) {
        aux_b[i]=b->bank[i];
    }

    aux_b[i] = create_pool(b->_poolsz, b->_objsz);
    if(!aux_b[i]) {
        free(aux_b);
        return -1;
    }

    b->_allocd_pools++;
    free(b->bank);
    b->bank = aux_b;

    return 0;
}
Ejemplo n.º 4
0
void *get_more_memory(struct pool_node *pool, int size)
{
    void *ptr;
    struct pool_node *new_pool;
 
    new_pool = create_pool(pool->size);
    if (NULL == new_pool) {
        return NULL;
    }
    ptr = new_pool->last;
    new_pool->last += size;
    pool->next = new_pool;

    return ptr;
    /* 
    new_pool = (struct pool_node*)malloc(sizeof(struct pool_node));
    if (NULL == new_pool) {
        return NULL;
    }
    new_pool->last = malloc(pool_size);
    if (NULL == new_pool->last) {
        return NULL;
    }
    new_pool->end = new_pool->last + pool->size;
    new_pool->size = pool->size;
*/

}
Ejemplo n.º 5
0
/*
 * Alloc the comp_ctx
 */
static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
{
#ifdef USE_ZLIB
	z_stream *strm;

	if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < sizeof(struct comp_ctx))
		return -1;
#endif

	if (unlikely(pool_comp_ctx == NULL)) {
		HA_SPIN_LOCK(COMP_POOL_LOCK, &comp_pool_lock);
		if (unlikely(pool_comp_ctx == NULL))
			pool_comp_ctx = create_pool("comp_ctx", sizeof(struct comp_ctx), MEM_F_SHARED);
		HA_SPIN_UNLOCK(COMP_POOL_LOCK, &comp_pool_lock);
	}

	*comp_ctx = pool_alloc(pool_comp_ctx);
	if (*comp_ctx == NULL)
		return -1;
#if defined(USE_SLZ)
	(*comp_ctx)->direct_ptr = NULL;
	(*comp_ctx)->direct_len = 0;
	(*comp_ctx)->queued = NULL;
#elif defined(USE_ZLIB)
	HA_ATOMIC_ADD(&zlib_used_memory, sizeof(struct comp_ctx));

	strm = &(*comp_ctx)->strm;
	strm->zalloc = alloc_zlib;
	strm->zfree = free_zlib;
	strm->opaque = *comp_ctx;
#endif
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, const char * argv[])
{
    /* constants */
    const int POOL_SIZE = 5;
    
    //process pool
    pid_t pool[POOL_SIZE];
    
    //parent write - children read
    int pipes[POOL_SIZE][2];
    
    signal(SIGCHLD, sigchld_handler);
    
    debug_print("parent pid: %d\n", getpid());
    
    create_pool(pool, POOL_SIZE, pipes);
    
    int marker = run_pipeline(pool, POOL_SIZE, pipes, 0);
    assert(marker == 50);
    
    printf("[%d] all done. marker value: %d\n", (unsigned)time(NULL), marker);
    
    destroy_pool(pool, POOL_SIZE);
    return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
connect_pool& connect_manager::set(const char* addr, int count)
{
	char key[256];
	ACL_SAFE_STRNCPY(key, addr, sizeof(key));
	acl_lowercase(key);

	lock_.lock();

	std::vector<connect_pool*>::iterator it = pools_.begin();
	for (; it != pools_.end(); ++it)
	{
		if (strcasecmp(key, (*it)->get_addr()) == 0)
		{
			lock_.unlock();
			return **it;
		}
	}

	connect_pool* pool = create_pool(key, count, pools_.size() - 1);
	pools_.push_back(pool);

	lock_.unlock();

	logger("Add one service, addr: %s, count: %d", addr, count);

	return *pool;
}
Ejemplo n.º 8
0
connect_pool& connect_manager::set(const char* addr, size_t count,
	int conn_timeout /* = 30 */, int rw_timeout /* = 30 */)
{
	char key[256];
	ACL_SAFE_STRNCPY(key, addr, sizeof(key));
	acl_lowercase(key);

	lock_.lock();

	std::vector<connect_pool*>::iterator it = pools_.begin();
	for (; it != pools_.end(); ++it)
	{
		if (strcasecmp(key, (*it)->get_addr()) == 0)
		{
			lock_.unlock();
			return **it;
		}
	}

	connect_pool* pool = create_pool(key, count, pools_.size() - 1);
	pool->set_retry_inter(retry_inter_);
	pool->set_timeout(conn_timeout, rw_timeout);
	if (idle_ttl_ >= 0)
		pool->set_idle_ttl(idle_ttl_);
	if (check_inter_ > 0)
		pool->set_check_inter(check_inter_);
	pools_.push_back(pool);

	lock_.unlock();

	logger("Add one service, addr: %s, count: %d", addr, (int) count);

	return *pool;
}
Ejemplo n.º 9
0
/*
 * Alloc the comp_ctx
 */
static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
{
#ifdef USE_ZLIB
	z_stream *strm;

	if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < sizeof(struct comp_ctx))
		return -1;
#endif

	if (unlikely(pool_comp_ctx == NULL))
		pool_comp_ctx = create_pool("comp_ctx", sizeof(struct comp_ctx), MEM_F_SHARED);

	*comp_ctx = pool_alloc2(pool_comp_ctx);
	if (*comp_ctx == NULL)
		return -1;
#ifdef USE_ZLIB
	zlib_used_memory += sizeof(struct comp_ctx);

	strm = &(*comp_ctx)->strm;
	strm->zalloc = alloc_zlib;
	strm->zfree = free_zlib;
	strm->opaque = *comp_ctx;
#endif
	return 0;
}
Ejemplo n.º 10
0
/**
 * ipsec pool --add - add a new pool
 */
static void add(char *name, host_t *start, host_t *end, int timeout)
{
	chunk_t start_addr, end_addr, cur_addr;
	u_int id, count;

	start_addr = start->get_address(start);
	end_addr = end->get_address(end);
	cur_addr = chunk_clonea(start_addr);
	count = get_pool_size(start_addr, end_addr);

	if (start_addr.len != end_addr.len ||
		memcmp(start_addr.ptr, end_addr.ptr, start_addr.len) > 0)
	{
		fprintf(stderr, "invalid start/end pair specified.\n");
		exit(EXIT_FAILURE);
	}
	id = create_pool(name, start_addr, end_addr, timeout);
	printf("allocating %d addresses... ", count);
	fflush(stdout);
	db->transaction(db, FALSE);
	while (TRUE)
	{
		db->execute(db, NULL,
			"INSERT INTO addresses (pool, address, identity, acquired, released) "
			"VALUES (?, ?, ?, ?, ?)",
			DB_UINT, id, DB_BLOB, cur_addr,	DB_UINT, 0, DB_UINT, 0, DB_UINT, 1);
		if (chunk_equals(cur_addr, end_addr))
		{
			break;
		}
		chunk_increment(cur_addr);
	}
	db->commit(db);
	printf("done.\n");
}
Ejemplo n.º 11
0
/*
 * bcm_mpm_create_heap_pool() - Create a new pool for fixed size objects. The memory
 *                              pool allocator uses the heap (malloc/free) for memory.
 *                              In this case, the pool allocator is just providing
 *                              statistics and instrumentation on top of the heap,
 *                              without modifying the heap allocation implementation.
 *
 * Parameters:
 *    mgr:      INPUT  The handle to the pool manager
 *    obj_sz:   INPUT  Size of objects that will be allocated by the new pool
 *    poolname  INPUT  For instrumentation, the name of the pool
 *    newp:     OUTPUT The handle for the new pool, if creation is successful
 *
 * Returns:
 *    BCME_OK   Pool created ok.
 *    other     Pool not created due to indicated error. newpoolp set to NULL.
 *
 *
 */
int BCMATTACHFN(bcm_mpm_create_heap_pool)(bcm_mpm_mgr_h mgr,
                                          unsigned int obj_sz,
                                          char poolname[BCM_MP_NAMELEN],
                                          bcm_mp_pool_h *newp)
{
	return (create_pool(mgr, obj_sz, obj_sz, 0, NULL, poolname,
	                    BCM_MP_TYPE_HEAP, newp));
}
Ejemplo n.º 12
0
PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries) {

	mem_ptr = Memory::alloc_static(p_size, "PoolAllocator()");
	ERR_FAIL_COND(!mem_ptr);
	align = 1;
	create_pool(mem_ptr, p_size, p_max_entries);
	needs_locking = p_needs_locking;
}
Ejemplo n.º 13
0
/* FUNCTION: threadpool 

DESCRIPTION: 
this function is not associated with any particular thread as it is called only once by the main function in order to initialize the thread_pool; before such measures have been taken the server will be unable to cope with client requests
Since the server administration thread isn't running yet, only one thread is working on the pool, therefore no race conditions exist.
*/
void threadpool (){

	int i;
	pool_no = POOL_INIT;
	first_pool_node = create_pool();
	for(i=0; i< pool_no; i++){
		create_pool_node(&first_pool_node, 1);
	}	
}
Ejemplo n.º 14
0
/*prototipo: int create_server(char *srvName)
 *objetivo: Cria o Servidor com o identificador especificado por parametro.*/
int ss_create_server(char *srvName){
	
	//definir identificador da regra 
	uint8_t crush_ruleset = 0;
	
	state = create_pool(cluster,srvName,crush_ruleset);
	
	return ((state >= 0) ? 0 : 1);
}
Ejemplo n.º 15
0
PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int p_max_entries) {

	ERR_FAIL_COND(p_align < 1);
	mem_ptr = Memory::alloc_static(p_size + p_align, "PoolAllocator()");
	uint8_t *mem8 = (uint8_t *)mem_ptr;
	uint64_t ofs = (uint64_t)mem8;
	if (ofs % p_align)
		mem8 += p_align - (ofs % p_align);
	create_pool(mem8, p_size, p_max_entries);
	needs_locking = p_needs_locking;
	align = p_align;
}
Ejemplo n.º 16
0
/* Initialize the trash buffers. It returns 0 if an error occurred. */
int init_trash_buffers(int first)
{
	if (!first) {
		hap_register_per_thread_init(init_trash_buffers_per_thread);
		hap_register_per_thread_deinit(deinit_trash_buffers_per_thread);
	}
	pool_destroy(pool_head_trash);
	pool_head_trash = create_pool("trash", sizeof(struct chunk) + global.tune.bufsize, MEM_F_EXACT);
	if (!pool_head_trash || !alloc_trash_buffers(global.tune.bufsize))
		return 0;
	return 1;
}
Ejemplo n.º 17
0
/*
 * Fill in the remaining fields of the jcr as if it
 *  is going to run the job.
 */
bool complete_jcr_for_job(JCR *jcr, JOB *job, POOL *pool)
{
   POOL_DBR pr;

   memset(&pr, 0, sizeof(POOL_DBR));
   set_jcr_defaults(jcr, job);
   if (pool) {
      jcr->pool = pool;               /* override */
   }
   if (jcr->db) {
      Dmsg0(100, "complete_jcr close db\n");
      db_close_database(jcr, jcr->db);
      jcr->db = NULL;
   }

   Dmsg0(100, "complete_jcr open db\n");
   jcr->db = db_init_database(jcr, jcr->catalog->db_driver, jcr->catalog->db_name, 
                              jcr->catalog->db_user,
                              jcr->catalog->db_password, jcr->catalog->db_address,
                              jcr->catalog->db_port, jcr->catalog->db_socket,
                              jcr->catalog->mult_db_connections, 
                              jcr->catalog->disable_batch_insert);
   if (!jcr->db || !db_open_database(jcr, jcr->db)) {
      Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
                 jcr->catalog->db_name);
      if (jcr->db) {
         Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
         db_close_database(jcr, jcr->db);
         jcr->db = NULL;
      }
      return false;
   }
   bstrncpy(pr.Name, jcr->pool->name(), sizeof(pr.Name));
   while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
      /* Try to create the pool */
      if (create_pool(jcr, jcr->db, jcr->pool, POOL_OP_CREATE) < 0) {
         Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
            db_strerror(jcr->db));
         if (jcr->db) {
            db_close_database(jcr, jcr->db);
            jcr->db = NULL;
         }
         return false;
      } else {
         Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
      }
   }
   jcr->jr.PoolId = pr.PoolId;
   return true;
}
Ejemplo n.º 18
0
PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_locking, int p_max_entries) {

	if (p_align > 1) {

		uint8_t *mem8 = (uint8_t *)p_mem;
		uint64_t ofs = (uint64_t)mem8;
		if (ofs % p_align) {
			int dif = p_align - (ofs % p_align);
			mem8 += p_align - (ofs % p_align);
			p_size -= dif;
			p_mem = (void *)mem8;
		};
	};

	create_pool(p_mem, p_size, p_max_entries);
	needs_locking = p_needs_locking;
	align = p_align;
	mem_ptr = NULL;
}
Ejemplo n.º 19
0
/*
 * Get or create a Pool record with the given name.
 * Returns: 0 on error
 *          poolid if OK
 */
DBId_t get_or_create_pool_record(JCR *jcr, char *pool_name)
{
   POOL_DBR pr;

   memset(&pr, 0, sizeof(pr));
   bstrncpy(pr.Name, pool_name, sizeof(pr.Name));
   Dmsg1(110, "get_or_create_pool=%s\n", pool_name);

   while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
      /* Try to create the pool */
      if (create_pool(jcr, jcr->db, jcr->res.pool, POOL_OP_CREATE) < 0) {
         Jmsg(jcr, M_FATAL, 0, _("Pool \"%s\" not in database. ERR=%s"), pr.Name,
            db_strerror(jcr->db));
         return 0;
      } else {
         Jmsg(jcr, M_INFO, 0, _("Created database record for Pool \"%s\".\n"), pr.Name);
      }
   }
   return pr.PoolId;
}
Ejemplo n.º 20
0
int main() {
    
    create_pool(1000);
    list = createList();

    // test1();
    // test2();
    // test3();
    test4();


    





    
    
    return 0;
}
Ejemplo n.º 21
0
struct bank * create_bank( uint16_t n_pools
                         , int8_t   growing
                         , uint16_t poolsize
                         , size_t   objsize ){

    struct bank * b = NULL;

    if(!(b = _b_allocator(sizeof(struct bank))))
    {
        return NULL;
    }
    memset(b, 0, sizeof(struct bank));

    b->_max_pools = (growing ? 0 : n_pools);
    b->_objsz = objsize;
    b->_poolsz = poolsize;

    if(n_pools > 0)
    {
        if(!(b->bank = _b_allocator(n_pools*sizeof(struct pool *))))
        {
                free(b);
                return NULL;
        }

        for(int i=0 ; i<n_pools ; i++)
        {
            b->bank[i] = create_pool(poolsize, objsize);
            if(!(b->bank[i])){
                for(int j = 0 ; j < i ; j++) {
                    free(b->bank[i]);
                    free(b);
                    return NULL;
                }
            }
            b->_allocd_pools++;
        }
    }
    return b;
}
Ejemplo n.º 22
0
Thread_pool_t * threadPool_create_and_init(int num)
{
    if (num <= 0)
    {
        fprintf(stderr, "thread number invalied!\n");
        return NULL;
    }
    Thread_pool_t *pools;
    int ret;

    pools = create_pool(num);
    if (pools == NULL)
        return NULL;

    ret = create_threads(num, pools);
    if (ret)
        return NULL;

    wait_all_threads_ready(pools, num);

    return pools;
}
Ejemplo n.º 23
0
/*
 * bcm_mpm_create_prealloc_pool() - Create a new pool for fixed size objects. The
 *                                  pool uses a contiguous block of pre-alloced
 *                                  memory. The memory block may either be provided
 *                                  by the client or dynamically allocated by the
 *                                  pool manager.
 *
 * Parameters:
 *    mgr:      INPUT  The handle to the pool manager
 *    obj_sz:   INPUT  Size of objects that will be allocated by the new pool.
 *                     Must be >= sizeof(void *).
 *    nobj:     INPUT  Maximum number of concurrently existing objects to support
 *    memstart  INPUT  Pointer to the memory to use, or NULL to malloc()
 *    memsize   INPUT  Number of bytes referenced from memstart (for error checking)
 *                     Must be 0 if 'memstart' is NULL.
 *    poolname  INPUT  For instrumentation, the name of the pool
 *    newp:     OUTPUT The handle for the new pool, if creation is successful
 *
 * Returns:
 *    BCME_OK   Pool created ok.
 *    other     Pool not created due to indicated error. newpoolp set to NULL.
 *
 *
 */
int BCMATTACHFN(bcm_mpm_create_prealloc_pool)(bcm_mpm_mgr_h mgr,
                                              unsigned int obj_sz,
                                              int nobj,
                                              void *memstart,
                                              unsigned int memsize,
                                              char poolname[BCM_MP_NAMELEN],
                                              bcm_mp_pool_h *newp)
{
	int ret;
	unsigned int padded_obj_sz;

	/* Check parameters */
	if ((nobj == 0) ||
	    (memstart && !memsize) ||
	    (memsize && !memstart)) {
		return (BCME_BADARG);
	}


	/* Get padded object size. */
	ret = bcm_mpm_get_obj_size(mgr, obj_sz, &padded_obj_sz);
	if (ret != BCME_OK) {
		return (ret);
	}


	/* For client allocated memory, validate memory block size and alignment. */
	if (memstart != NULL) {
		if ((memsize < (padded_obj_sz * nobj)) || (!ISALIGNED(memstart, sizeof(void *)))) {
			return (BCME_BADARG);
		}
	}

	return (create_pool(mgr, obj_sz, padded_obj_sz, nobj, memstart, poolname,
	                    BCM_MP_TYPE_PREALLOC, newp));
}
Ejemplo n.º 24
0
static int pktio_suite_init(void)
{
	int i;

	odp_atomic_init_u32(&ip_seq, 0);

	if (getenv("ODP_WAIT_FOR_NETWORK"))
		wait_for_network = true;

	iface_name[0] = getenv("ODP_PKTIO_IF0");
	iface_name[1] = getenv("ODP_PKTIO_IF1");
	num_ifaces = 1;

	if (!iface_name[0]) {
		printf("No interfaces specified, using default \"loop\".\n");
		iface_name[0] = "loop";
	} else if (!iface_name[1]) {
		printf("Using loopback interface: %s\n", iface_name[0]);
	} else {
		num_ifaces = 2;
		printf("Using paired interfaces: %s %s\n",
		       iface_name[0], iface_name[1]);
	}

	for (i = 0; i < num_ifaces; i++) {
		if (create_pool(iface_name[i], i) != 0)
			return -1;
	}

	if (default_pool_create() != 0) {
		fprintf(stderr, "error: failed to create default pool\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 25
0
int main(int argc, char *argv[])
{
    FILE *fp;
    int i = 0;
    char line[MAX_LAST_NAME_SIZE];
    struct timespec start, end;
    double cpu_time1, cpu_time2;

    /* check file opening */
    fp = fopen(DICT_FILE, "r");
    if (fp == NULL) {
        printf("cannot open the file\n");
        return -1;
    }

#ifdef TABLE_SIZE
    /* Create the hashtable */
    hashtable *ht=NULL;
    ht = Create_Hash_Table();

    /*Create memory pool*/
    pool *mem_pool = (pool*)malloc(sizeof(pool));
    create_pool(mem_pool);
#else
    /* build the entry */
    entry *pHead, *e;
    pHead = (entry *) malloc(sizeof(entry));
    e = pHead;
    e->pNext = NULL;
#endif

    /* print the size of entry */
    printf("size of entry : %lu bytes\n", sizeof(entry));
    i = 0;
    clock_gettime(CLOCK_REALTIME, &start);
    while (fgets(line, sizeof(line), fp)) {
        while (line[i] != '\0')
            i++;
        line[i - 1] = '\0';
        i = 0;
#ifdef TABLE_SIZE
        appendhash(line, ht, mem_pool);
#else
        e = append(line, e);
#endif
    }
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time1 = diff_in_second(start, end);

    /* close file as soon as possible */
    fclose(fp);
    /* the givn last name to find */
    char input[MAX_LAST_NAME_SIZE] = "zora";
#ifndef TABLE_SIZE
    e = pHead;
#endif
    /* compute the execution time */
    clock_gettime(CLOCK_REALTIME, &start);
#ifdef TABLE_SIZE
    findhash(input, ht);
#else
    findName(input, e);
#endif
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time2 = diff_in_second(start, end);
	printf("%s", input);
#ifdef TABLE_SIZE
    /* Calculate the unuse of hashtable */
    int sum=0;
    for(i=0; i<TABLE_SIZE; i++) {
        if( ht->list[i] == NULL)
            sum++;
    }

    FILE *nfp=fopen("null.txt", "a");
    fprintf(nfp,"Tablesize:%d, Total of null: %d\n",TABLE_SIZE, sum);
    fclose(fp);
#endif
    printf("execution time of append() : %lf sec\n", cpu_time1);
    printf("execution time of findName() : %lf sec\n", cpu_time2);

#ifdef TABLE_SIZE
    destroy_pool(mem_pool);
#else

#endif
    return 0;
}
Ejemplo n.º 26
0
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_session()
{
	pool_head_session = create_pool("session", sizeof(struct session), MEM_F_SHARED);
	return pool_head_session != NULL;
}
Ejemplo n.º 27
0
static void add_addresses(char *pool, char *path, int timeout)
{
	u_int pool_id, count = 0;
	int family = AF_UNSPEC;
	char address_str[512];
	host_t *addr;
	FILE *file;

	db->transaction(db, FALSE);

	addr = host_create_from_string("%any", 0);
	pool_id = create_pool(pool, addr->get_address(addr),
						  addr->get_address(addr), timeout);
	addr->destroy(addr);

	file = (strcmp(path, "-") == 0 ? stdin : fopen(path, "r"));
	if (file == NULL)
	{
		fprintf(stderr, "opening '%s' failed: %s\n", path, strerror(errno));
		exit(-1);
	}

	printf("starting allocation... ");
	fflush(stdout);

	while (fgets(address_str, sizeof(address_str), file))
	{
		size_t addr_len = strlen(address_str);
		char *last_chr = address_str + addr_len - 1;
		if (*last_chr == '\n')
		{
			if (addr_len == 1)
			{	/* end of input */
				break;
			}
			*last_chr = '\0';
		}
		if (add_address(pool_id, address_str, &family) == FALSE)
		{
			if (file != stdin)
			{
				fclose(file);
			}
			exit(EXIT_FAILURE);
		}
		++count;
	}

	if (file != stdin)
	{
		fclose(file);
	}

	if (family == AF_INET6)
	{	/* update address family if necessary */
		addr = host_create_from_string("%any6", 0);
		if (db->execute(db, NULL,
					"UPDATE pools SET start = ?, end = ? WHERE id = ?",
					DB_BLOB, addr->get_address(addr),
					DB_BLOB, addr->get_address(addr), DB_UINT, pool_id) <= 0)
		{
			addr->destroy(addr);
			fprintf(stderr, "updating pool address family failed.\n");
			exit(EXIT_FAILURE);
		}
		addr->destroy(addr);
	}

	db->commit(db);

	printf("%d addresses done.\n", count);
}
Ejemplo n.º 28
0
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_channel()
{
	pool2_channel = create_pool("channel", sizeof(struct channel), MEM_F_SHARED);
	return pool2_channel != NULL;
}
Ejemplo n.º 29
0
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_pendconn()
{
    pool2_pendconn = create_pool("pendconn", sizeof(struct pendconn), MEM_F_SHARED);
    return pool2_pendconn != NULL;
}
Ejemplo n.º 30
0
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_connection()
{
	pool2_connection = create_pool("connection", sizeof (struct connection), MEM_F_SHARED);
	return pool2_connection != NULL;
}