Пример #1
0
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);
}
Пример #2
0
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; 
}
Пример #3
0
int
glw_init(glw_root_t *gr, const char *theme,
	 ui_t *ui, int primary, 
	 const char *instance, const char *instance_title)
{
  hts_mutex_init(&gr->gr_mutex);
  gr->gr_courier = prop_courier_create_passive();
  gr->gr_token_pool = pool_create("glwtokens", sizeof(token_t), POOL_ZERO_MEM);
  gr->gr_clone_pool = pool_create("glwclone", sizeof(glw_clone_t),
				  POOL_ZERO_MEM);

  gr->gr_vpaths[0] = "theme";
  gr->gr_vpaths[1] = theme;
  gr->gr_vpaths[2] = NULL;

  gr->gr_uii.uii_ui = ui;

  glw_text_bitmap_init(gr);
  glw_init_settings(gr, instance, instance_title);

  TAILQ_INIT(&gr->gr_destroyer_queue);
  glw_tex_init(gr);

  gr->gr_frameduration = 1000000 / 60;
  uii_register(&gr->gr_uii, primary);

  return 0;
}
Пример #4
0
void initialize(void) {

	cwmp_log_init(NULL, CWMP_LOG_DEBUG);

	gpool = (pool_t*)pool_create(POOL_DEFAULT_SIZE);
	gcwmp = (cwmp_t*)pool_palloc(gpool, sizeof(cwmp_t));
	if(!gcwmp)
	{
		cwmp_log_error("create cwmp_t error!");
		exit(-1);
	}
	cwmp_log_debug("cwmp at %p", gcwmp);
	if(!gcwmp->pool)
	{
		cwmp_log_debug("cwmp pool at %p", gpool);
		gcwmp->pool = gpool;   
	}

	cwmp_model_load_xml(gcwmp, "device.xml", NULL, 0);

	char * envstr;
	char * encstr;

	envstr = "SOAP-ENV"; //cwmp_conf_get("cwmp:soap_env");
	encstr = "SOAP-ENC"; // cwmp_conf_get("cwmp:soap_enc");

	cwmp_set_envelope_ns(envstr, encstr);

}
Пример #5
0
IQueue*
seed_concurrent_queue_create(size_t limit) {
	Queue* q;
	if ((q = malloc(sizeof(Queue)+sizeof(IQueue))) == NULL) {
		return NULL;
	}
	if ((q->mutex = (Mutex*)malloc(sizeof(Mutex))) == NULL) {
		free(q);
		return NULL;
	}
	if ((q->pool = pool_create(limit, sizeof(Node))) == NULL) {
		mutex_release(q->mutex);
		free(q);
		return NULL;
	}
	mutex_init(q->mutex, NULL);
	q->tail = q->head = NULL;

	IQueue* queue = (IQueue*)q->methods;
	queue->enqueue      = &enqueue;
	queue->dequeue      = &dequeue;
	queue->batchDequeue = &batchDequeue;
	queue->release      = &release;
	return queue;
}
Пример #6
0
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;
}
Пример #7
0
void classification_test_destroy_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	odp_pool_t pool;
	odp_queue_t queue;
	odp_cls_cos_param_t cls_param;
	int retval;

	pool = pool_create("cls_basic_pool");
	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

	queue = queue_create("cls_basic_queue", true);
	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);

	sprintf(name, "ClassOfService");
	odp_cls_cos_param_init(&cls_param);
	cls_param.pool = pool;
	cls_param.queue = queue;
	cls_param.drop_policy = ODP_COS_DROP_POOL;

	cos = odp_cls_cos_create(name, &cls_param);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	retval = odp_cos_destroy(cos);
	CU_ASSERT(retval == 0);
	retval = odp_cos_destroy(ODP_COS_INVALID);
	CU_ASSERT(retval < 0);

	odp_pool_destroy(pool);
	odp_queue_destroy(queue);
}
Пример #8
0
void classification_test_cos_set_drop(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	odp_cos_t cos_drop;
	odp_queue_t queue;
	odp_pool_t pool;
	odp_cls_cos_param_t cls_param;

	pool = pool_create("cls_basic_pool");
	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

	queue = queue_create("cls_basic_queue", true);
	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);

	sprintf(cosname, "CoSDrop");
	odp_cls_cos_param_init(&cls_param);
	cls_param.pool = pool;
	cls_param.queue = queue;
	cls_param.drop_policy = ODP_COS_DROP_POOL;
	cos_drop = odp_cls_cos_create(cosname, &cls_param);
	CU_ASSERT_FATAL(cos_drop != ODP_COS_INVALID);

	retval = odp_cos_drop_set(cos_drop, ODP_COS_DROP_POOL);
	CU_ASSERT(retval == 0);
	retval = odp_cos_drop_set(cos_drop, ODP_COS_DROP_NEVER);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_drop);
	odp_pool_destroy(pool);
	odp_queue_destroy(queue);
}
Пример #9
0
END_TEST

START_TEST(test_version_split)
{
    Pool *pool = pool_create();
    char evr[] = "1:5.9.3-8";
    char *epoch, *version, *release;

    pool_split_evr(pool, evr, &epoch, &version, &release);
    ck_assert_str_eq(epoch, "1");
    ck_assert_str_eq(version, "5.9.3");
    ck_assert_str_eq(release, "8");

    char evr2[] = "8.0-9";
    pool_split_evr(pool, evr2, &epoch, &version, &release);
    fail_unless(epoch == NULL);
    ck_assert_str_eq(version, "8.0");
    ck_assert_str_eq(release, "9");

    char evr3[] = "1.4";
    pool_split_evr(pool, evr3, &epoch, &version, &release);
    fail_unless(epoch == NULL);
    ck_assert_str_eq(version, "1.4");
    fail_unless(release == NULL);

    pool_free(pool);
}
Пример #10
0
int main(void) {
    lcb_pool_t pool;
    lcb_t instance;
    struct lcb_create_st options;
    lcb_error_t error;

    /* set up the options to represent your cluster (hostname etc) */
    /* ... */

    /* Create the pool */
    error = pool_create(10, &options, &pool, initiate);
    if (error != LCB_SUCCESS) {
        fprintf(stderr, "Failed to create pool: %s\n",
                lcb_strerror(NULL, error));
        exit(EXIT_FAILURE);
    }

    /*
     * Every time you want to use libcouchbase you would grab an instance
     * from the pool by:
     */
    instance = pool_pop(pool);

    /* use the instance for whatever you wanted to do */


    /*
     * When you're done using the instance you would put it back into the
     * pool (and ready for others to use) by:
     */
    pool_push(pool, instance);

    return 0;
}
Пример #11
0
int
main(int argc, char **argv)
{
  Pool *pool;
  Repo *repo;
  int with_attr = 0;
#ifdef SUSE
  int add_auto = 0;
#endif
  int c;

  pool = pool_create();
  repo = repo_create(pool, "<mergesolv>");
  
  while ((c = getopt(argc, argv, "ahX")) >= 0)
    {
      switch (c)
      {
	case 'h':
	  usage();
	  break;
	case 'a':
	  with_attr = 1;
	  break;
	case 'X':
#ifdef SUSE
	  add_auto = 1;
#endif
	  break;
	default:
	  usage();
	  exit(1);
      }
    }
  if (with_attr)
    pool_setloadcallback(pool, loadcallback, 0);

  for (; optind < argc; optind++)
    {
      FILE *fp;
      if ((fp = fopen(argv[optind], "r")) == NULL)
	{
	  perror(argv[optind]);
	  exit(1);
	}
      if (repo_add_solv(repo, fp, 0))
	{
	  fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool));
	  exit(1);
	}
      fclose(fp);
    }
#ifdef SUSE
  if (add_auto)
    repo_add_autopattern(repo, 0);
#endif
  tool_write(repo, stdout);
  pool_free(pool);
  return 0;
}
Пример #12
0
int
main(int argc, char **argv)
{
  int c, flags = 0;
  char *attrname = 0;
  
  Pool *pool = pool_create();
  Repo *repo = repo_create(pool, "<stdin>");

  while ((c = getopt(argc, argv, "hn:")) >= 0)
    {
      switch(c)
	{
	case 'h':
	  usage(0);
	  break;
	case 'n':
	  attrname = optarg;
	  break;
	default:
	  usage(1);
	  break;
	}
    }
  if (repo_add_updateinfoxml(repo, stdin, flags))
    {
      fprintf(stderr, "updateinfoxml2solv: %s\n", pool_errstr(pool));
      exit(1);
    }
  tool_write(repo, 0, attrname);
  pool_free(pool);
  exit(0);
}
Пример #13
0
/**
 * Initialize pool of RX buffers.
 */
void
rxbuf_init(void)
{
	rxbuf_pagesize = compat_pagesize();
	rxpool = pool_create("RX buffers", rxbuf_pagesize,
		rxbuf_page_alloc, rxbuf_page_free, rxbuf_page_is_fragment);
}
Пример #14
0
int main(int argc, char **argv)
{
  pool p[1] = { pool_create() };
  
  int basis = (int) time(NULL);
  
  assert(argc == 1);
  
  random_init();
  int offset = rand() % 10000;
  
  uint32_t target = first_output_given_seed(basis - offset);
  
  // we have our target, just search!
  uint32_t check = basis;
  while (1)
  {
    if (first_output_given_seed(check) == target)
    {
      printf("ok\n");
      break;
    }
    check--;
  }
  
  p->finish(p);
  return 0;
}
Пример #15
0
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;
}
Пример #16
0
int
main(int argc, char **argv)
{
  int c, flags = 0;
  const char *query = 0;
  
  Pool *pool = pool_create();
  Repo *repo = repo_create(pool, "<stdin>");

  while ((c = getopt (argc, argv, "hq:")) >= 0)
    {
      switch(c)
        {
        case 'h':
          usage(0);
          break;
        case 'q':
	  query = optarg;
          break;
	default:
          usage(1);
          break;
        }
    }
  repo_add_repomdxml(repo, stdin, flags);
  if (query)
    doquery(pool, repo, query);
  else
    tool_write(repo, 0, 0);
  pool_free(pool);
  exit(0);
}
Пример #17
0
int main(int argc, char **argv)
{
  pool p[1] = { pool_create() };
  assert(argc == 1);
  
  byteblock test = { (void *) "joe", 3 };
  byteblock token = encrypt_userdata(p, &test);
  assert(!is_admin(p, &token));
  
  byteblock test2 = { (void *) magic, strlen(magic) };
  token = encrypt_userdata(p, &test2);
  assert(!is_admin(p, &token));
  
  /* strategy: first, we need a userdata with two blocks:
   *  dontcare || ;admin=true; ...
   * we can't directly encode this, but can get close
   * and then flip the bits in the dontcare block:
   * :admin<true:
   * ^     ^    ^
   * 0     6    11
   */
  uint8_t vector[32] = { 0 };
  memcpy(vector + 16, ":admin<true:", 12);
  byteblock vec = { vector, sizeof vector };
  token = encrypt_userdata(p, &vec);
  token.buf[32 + 0] ^= 0x01;
  token.buf[32 + 6] ^= 0x01;
  token.buf[32 + 11] ^= 0x01;
  assert(is_admin(p, &token));
  
  printf("ok\n");
  
  p->finish(p);
  return 0;
}
Пример #18
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_pool");

	if (argc < 4)
		UT_FATAL("usage: %s op path bsize [poolsize mode]", argv[0]);

	size_t bsize = strtoul(argv[3], NULL, 0);
	size_t poolsize;
	unsigned mode;

	switch (argv[1][0]) {
	case 'c':
		poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
		mode = strtoul(argv[5], NULL, 8);

		pool_create(argv[2], bsize, poolsize, mode);
		break;

	case 'o':
		pool_open(argv[2], bsize);
		break;

	default:
		UT_FATAL("unknown operation");
	}

	DONE(NULL);
}
Пример #19
0
void 
http_accept_request_socket(http_conf_t * conf, int fd) {
	int confd  ;
	struct sockaddr addr;
	struct sockaddr_in addrIn;
	socklen_t addLen = sizeof(struct sockaddr );
	while( (confd =  accept(fd, &addr, &addLen)) && confd > 0) {
		pool_t *p = (pool_t *)pool_create();
		http_connect_t * con;
		epoll_extra_data_t *data_ptr;

		addrIn =  *((struct sockaddr_in *) &addr);
		data_ptr = (epoll_extra_data_t *)palloc(p, sizeof(epoll_extra_data_t));
		con = (http_connect_t *) palloc(p, sizeof(http_connect_t));//换成初始化函数,
		con->p= p;
		con->fd = confd;
		con->in = (request *)request_init(p);
		con->out = (response *)response_init(p);
		/*char *ip  = NULL;
		if(addrIn.sin_addr.s_addr) {
			ip = inet_ntoa(addrIn.sin_addr);
		}

		if(ip) {
			//con->in->clientIp = (string *) string_init_from_str(p, ip, strlen(ip));
		}*/

		con->next_handle = accept_handler;
		data_ptr->type = SOCKFD;
		data_ptr->ptr = (void *) con;
		epoll_add_fd(conf->epfd, confd, EPOLL_R, (void *)data_ptr);//对epoll data结构指向的结构体重新封装,分websit
		//data struct ,  connect  data struct , file data struct ,
	}
}
Пример #20
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_pool");

	if (argc < 4)
		UT_FATAL("usage: %s op path layout [poolsize mode]", argv[0]);

	char *layout = NULL;
	size_t poolsize;
	unsigned mode;

	if (strcmp(argv[3], "EMPTY") == 0)
		layout = "";
	else if (strcmp(argv[3], "NULL") != 0)
		layout = argv[3];

	switch (argv[1][0]) {
	case 'c':
		poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
		mode = strtoul(argv[5], NULL, 8);

		pool_create(argv[2], layout, poolsize, mode);
		break;

	case 'o':
		pool_open(argv[2], layout);
		break;

	default:
		UT_FATAL("unknown operation");
	}

	DONE(NULL);
}
Пример #21
0
int
wmain(int argc, wchar_t *argv[])
{
	STARTW(argc, argv, "log_pool_win");

	if (argc < 3)
		UT_FATAL("usage: %s op path [poolsize mode]",
			ut_toUTF8(argv[0]));

	size_t poolsize;
	unsigned mode;

	switch (argv[1][0]) {
	case 'c':
		poolsize = wcstoul(argv[3], NULL, 0) * MB; /* in megabytes */
		mode = wcstoul(argv[4], NULL, 8);

		pool_create(argv[2], poolsize, mode);
		break;

	case 'o':
		pool_open(argv[2]);
		break;

	default:
		UT_FATAL("unknown operation");
	}

	DONEW(NULL);
}
Пример #22
0
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);

}
Пример #23
0
int
main(int argc, char **argv)
{
  int c, flags = 0;
  char *attrname = 0;
  
  Pool *pool = pool_create();
  Repo *repo = repo_create(pool, "<stdin>");

  while ((c = getopt(argc, argv, "hn:")) >= 0)
    {   
      switch(c)
	{
	case 'h':
	  usage(0);
	  break;
	case 'n':
	  attrname = optarg;
	  break;
	default:
	  usage(1);
	  break;
	}
    }
  repo_add_deltainfoxml(repo, stdin, flags);
  tool_write(repo, 0, attrname);
  pool_free(pool);
  exit(0);
}
Пример #24
0
Pool* scriptpool_create() {
    unsigned int item_size = sizeof(ScriptComponent);
    return pool_create(
        item_size,
        MAX_SCRIPTS,
        (void (*)(void*)) scriptcomponent_destroy);
}
Пример #25
0
static void test_cwmp_session_create_addobject(abts_case *tc, void *data)
{
    cwmp_t * cwmp = (cwmp_t*)data;
    pool_t * pool = pool_create(POOL_DEFAULT_SIZE);
    xmldoc_t *  doc, *newdoc;
    char * message = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
                       xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns=\"urn:dslforum-org:cwmp-1-0\"><SOAP-ENV:Header><cwmp:ID soap:mustUnderstand=\"1\">1234</cwmp:ID></SOAP-ENV:Header>  \
                       <SOAP-ENV:Body><cwmp:AddObject><ObjectName>InternetGatewayDevice.WANDevice.</ObjectName><ParameterKey></ParameterKey></cwmp:AddObject></SOAP-ENV:Body></SOAP-ENV:Envelope>"
    ;
   

   printf("create session\n"); 
    cwmp_session_t * session = cwmp_session_create(cwmp);
    pool_create(POOL_DEFAULT_SIZE);
   pool_create(POOL_DEFAULT_SIZE);
  pool_create(POOL_DEFAULT_SIZE);
 pool_create(POOL_DEFAULT_SIZE);
pool_create(POOL_DEFAULT_SIZE);
pool_create(POOL_DEFAULT_SIZE);
pool_create(POOL_DEFAULT_SIZE);
pool_create(POOL_DEFAULT_SIZE);
 printf("open session \n"); 
    cwmp_session_open(session);
  
   

       
    cwmp_uint32_t msglength = strlen(message);
    size_t len;

    char *xmlbuf = pool_palloc(pool, msglength+32);

    len = sprintf(xmlbuf,"<cwmp>");
    strncpy(xmlbuf + len, message, msglength);
    strcpy(xmlbuf + len + msglength, "</cwmp>");
//    strcat(xmlbuf, "</cwmp>");
 //   xmlbuf[len+msglength+7] = '\0';

    printf("agent analyse xml: \n%s", xmlbuf);

    doc = XmlParseBuffer(pool, xmlbuf);
    ASSERT_NOTNULL(doc);
    
    newdoc = cwmp_session_create_addobject_response_message(session, doc, pool);
    
    cwmp_write_doc_to_chunk(newdoc, session->writers,  pool);
    
    cwmp_chunk_print(session->writers);
    
    pool_destroy(pool);

}
Пример #26
0
	// Constructor.
	qmidinetJackMidiQueue ( unsigned int size, unsigned int slack )
	{
		m_pool  = pool_create(size * (slack + sizeof(Slot)));
		m_items = new char * [size];
		m_size  = size;		
		m_count = 0;
		m_dirty = 0;
	}
Пример #27
0
static pool* get_yarn_pool ()
{
	if (!yarn_pool)
	{
		yarn_pool = pool_create(sizeof(yarn), YARNS_MAX_PROCESSES);
	}
	return yarn_pool;
}
Пример #28
0
int HacheTableEmpty(HacheTable *h, int deallocate_data) {
    int i;
    
    if (!h) return -1;
    if (h->nbuckets == 0) return 0;
    
    // the destruction
    
    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->bucket) free(h->bucket);
    
    if (h->ordering) free(h->ordering);
    
    // and a bit of creation

    if (h->hi_pool) {
    	pool_destroy(h->hi_pool);
	h->hi_pool = pool_create(sizeof(HacheItem));
	
	if (NULL == h->hi_pool) return -1;
    }
    
    // the creation proper
    h->bucket = (HacheItem **)malloc(sizeof(*h->bucket) * h->nbuckets);
    h->mask = h->nbuckets - 1;
    h->nused = 0;
    h->searches = 0;
    h->hits = 0;
    h->ordering = (HacheOrder *)malloc(h->cache_size * sizeof(*h->ordering));
    h->head = h->tail = -1;
    h->free = 0;

    for (i = 0; i < h->cache_size; i++) {
	h->ordering[i].hi = NULL;
	h->ordering[i].next = i == h->cache_size-1 ? -1 : i+1;
	h->ordering[i].prev = i-1;
    }

    h->clientdata = NULL;
    h->load = NULL;
    h->del = NULL;
    h->in_use = NULL;

    for (i = 0; i < h->nbuckets; i++) {
	h->bucket[i] = NULL;
    }
    
    return 0;
}
Пример #29
0
pl_collisioncontext_t*
pl_new_collision_context(double size)
{
  pl_collisioncontext_t *ctxt = smalloc(sizeof(pl_collisioncontext_t));
  ctxt->pool = pool_create(sizeof(pl_recgrid_t));
  obj_array_init(&ctxt->colls);
  ctxt->otree = pl_new_recgrid(ctxt, size); // Roughly the heliospause
  return ctxt;
}
Пример #30
0
PLcollisioncontext*
plNewCollisionContext(void)
{
  PLcollisioncontext *ctxt = malloc(sizeof(PLcollisioncontext));
  ctxt->pool = pool_create(sizeof(PLrecgrid));
  obj_array_init(&ctxt->colls);
  ctxt->otree = plNewRecgrid(ctxt, plAuToMetres(100.0)); // Roughly the heliospause
  return ctxt;
}