bool ipu_init() { _P_image = pool_new(0x100); // if this fail, let it crash the app! _P_ppm = pool_new(0x100); // if this fail, let it crash the app! ipu_stack_select(ipu_stack_new()); // if this fail, let it crash the app! return false; }
/** * Turn sentence expressions into disjuncts. * Sentence expressions must have been built, before calling this routine. */ static void build_sentence_disjuncts(Sentence sent, double cost_cutoff, Parse_Options opts) { Disjunct * d; X_node * x; size_t w; sent->Disjunct_pool = pool_new(__func__, "Disjunct", /*num_elements*/2048, sizeof(Disjunct), /*zero_out*/false, /*align*/false, /*exact*/false); sent->Connector_pool = pool_new(__func__, "Connector", /*num_elements*/8192, sizeof(Connector), /*zero_out*/false, /*align*/false, /*exact*/false); for (w = 0; w < sent->length; w++) { d = NULL; for (x = sent->word[w].x; x != NULL; x = x->next) { Disjunct *dx = build_disjuncts_for_exp(sent, x->exp, x->string, cost_cutoff, opts); word_record_in_disjunct(x->word, dx); d = catenate_disjuncts(dx, d); } sent->word[w].d = d; } }
/* * Prepares the specified hook interface for first use. * * This function may be called directly. * * Returns 0 on success, non-zero on failure */ intptr_t J9HookInitializeInterface(struct J9HookInterface **hookInterface, OMRPortLibrary *portLib, size_t interfaceSize) { J9CommonHookInterface *commonInterface = (J9CommonHookInterface *)hookInterface; memset(commonInterface, 0, interfaceSize); commonInterface->hookInterface = (J9HookInterface *)GLOBAL_TABLE(hookFunctionTable); commonInterface->size = interfaceSize; if (omrthread_monitor_init_with_name(&commonInterface->lock, 0, "Hook Interface")) { J9HookShutdownInterface(hookInterface); return J9HOOK_ERR_NOMEM; } commonInterface->pool = pool_new(sizeof(J9HookRecord), 0, 0, 0, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT((OMRPortLibrary *)portLib)); if (commonInterface->pool == NULL) { J9HookShutdownInterface(hookInterface); return J9HOOK_ERR_NOMEM; } commonInterface->nextAgentID = J9HOOK_AGENTID_DEFAULT + 1; commonInterface->portLib = portLib; commonInterface->threshold4Trace = OMRHOOK_DEFAULT_THRESHOLD_IN_MILLISECONDS_WARNING_CALLBACK_ELAPSED_TIME; commonInterface->eventSize = (interfaceSize - sizeof(J9CommonHookInterface)) / (sizeof(U_8) + sizeof(OMREventInfo4Dump) + sizeof(J9HookRecord*)); return 0; }
int main(int argc, char **argv) { printf("%s %s\n", argv[0], argv[1]); int size = atoi(argv[1]); int sizx = 8; while (sizx < size) { sizx *= 2; } int sz58 = sizx*5/8; if (sz58 >= size) { sizx = sz58; } else { int sz34 = sizx*3/4; if (sz34 >= size) { sizx = sz34; } } printf("%d %d", size, sizx); struct pool_t *pool; pool = pool_new(1024 * 1024); void *p = palloc(pool, 64); }
int main(void) { pool p; pthread_t t1, t2; size_t i; if( (p = pool_new(NELEM)) == NULL) return 77; /* Add some items to the pool */ for(i = 0; i < NELEM; i++) { void* dummy = (void*)(i + 1); pool_add(p, dummy); } /* Start the threads */ pthread_create(&t1, NULL, tfn, p); pthread_create(&t2, NULL, tfn, p); /* Wait for the threads to finish */ pthread_join(t1, NULL); pthread_join(t2, NULL); pool_free(p, NULL); return 0; }
int main(void) { configfile_t *configfile; struct mycontext context; context.current_end_token = 0; context.permissions = 0; context.pool = pool_new(NULL); configfile = dotconf_create("./context.conf", options, (void *)&context, CASE_INSENSITIVE); if (!configfile) { fprintf(stderr, "Error opening configuration file\n"); return 1; } configfile->errorhandler = (dotconf_errorhandler_t) error_handler; configfile->contextchecker = (dotconf_contextchecker_t) context_checker; if (dotconf_command_loop(configfile) == 0) fprintf(stderr, "Error reading configuration file\n"); dotconf_cleanup(configfile); pool_free(context.pool); return 0; }
static void *pool_alloc (struct skiplist *list,size_t size) { struct pool *pool = pool_new (size); pool->next = list->pool; list->pool = pool; return pool->ptr; }
/* * Prepares the specified hook interface for first use. * * This function may be called directly. * * Returns 0 on success, non-zero on failure */ intptr_t J9HookInitializeInterface(struct J9HookInterface **hookInterface, OMRPortLibrary *portLib, size_t interfaceSize) { J9CommonHookInterface *commonInterface = (J9CommonHookInterface *)hookInterface; memset(commonInterface, 0, interfaceSize); commonInterface->hookInterface = (J9HookInterface *)GLOBAL_TABLE(hookFunctionTable); commonInterface->size = interfaceSize; if (omrthread_monitor_init_with_name(&commonInterface->lock, 0, "Hook Interface")) { J9HookShutdownInterface(hookInterface); return J9HOOK_ERR_NOMEM; } commonInterface->pool = pool_new(sizeof(J9HookRecord), 0, 0, 0, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT((OMRPortLibrary *)portLib)); if (commonInterface->pool == NULL) { J9HookShutdownInterface(hookInterface); return J9HOOK_ERR_NOMEM; } commonInterface->nextAgentID = J9HOOK_AGENTID_DEFAULT + 1; return 0; }
static void pet_test(void) { #define NODES 1000000 node_t *pool, *root; struct timeval tv, tv2; time_t sec; suseconds_t msec; int i, j; pool = pool_new(NODES); j = NODES / 2; gettimeofday(&tv, NULL); root = alloc_node(pool); root = make_node(root, 0); for (i = 1; i < NODES; i++, j = (j + 17) % NODES) root = insert(root, alloc_node(pool), j); while (root) root = delete_min(root); gettimeofday(&tv2, NULL); sec = tv2.tv_sec - tv.tv_sec; msec = tv2.tv_usec - tv.tv_usec; msec += sec * 1000000; printf("%d nodes add/remove: %lu msec\n", NODES, msec); pool_release(pool); }
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); }
static J9Pool * createNewPool(OMRPortLibrary *portLib, PoolInputData *input) { uint32_t expectedNumElems = (input->numberElements == 0) ? 1 : input->numberElements; uint32_t expectedAlignment = (input->elementAlignment == 0) ? MIN_GRANULARITY : input->elementAlignment; J9Pool *pool = pool_new( input->structSize, input->numberElements, input->elementAlignment, input->poolFlags, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(portLib)); /* Check that creation succeeded */ if (NULL == pool) { return NULL; } if (pool->puddleAllocSize < ((expectedNumElems * ROUND_TO(expectedAlignment, input->structSize)) + ROUND_TO(expectedAlignment, sizeof(J9PoolPuddle)))) { pool_kill(pool); return NULL; } else if ((input->poolFlags & POOL_ROUND_TO_PAGE_SIZE) && (pool->puddleAllocSize < OS_PAGE_SIZE)) { pool_kill(pool); return NULL; } return pool; }
static void _ensure_pool_delete_releases_all_allocated_memory( void ) { pool_t * pool; allocator_counted_t alloc; allocator_counted_init_default( &alloc ); pool = pool_new( 128, 4, allocator_counted_get( &alloc ) ); pool_delete( pool ); TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 ); }
J9Pool * MM_ConfigurationSegregated::createEnvironmentPool(MM_EnvironmentBase *env) { OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary()); uintptr_t numberOfElements = getConfigurationDelegate()->getInitialNumberOfPooledEnvironments(env); /* number of elements, pool flags = 0, 0 selects default pool configuration (at least 1 element, puddle size rounded to OS page size) */ return pool_new(sizeof(MM_EnvironmentBase), numberOfElements, sizeof(uint64_t), 0, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_MM, POOL_FOR_PORT(OMRPORTLIB)); }
int PoolExercise(int verbose, struct cfg *cfg, char *args[]) { void *data; int rate, i; struct linkedlist *l; struct pool *p; cfg = NULL; args[0] = NULL; if ((p = pool_new(EXERCISE_SM_COUNT, (new_fn)allocator_alloc, allocator_free, NULL, NULL, BUFFER_SIZE_SM, 0, NULL)) == NULL || (l = linkedlist_new(0, NULL)) == NULL) { PMNO(errno); return 1; } rate = EXERCISE_R0; for (i = 0; i < EXERCISE_SM_COUNT; i++) { if (i == EXERCISE_SM_P1) { rate = EXERCISE_R1; } else if (i == EXERCISE_SM_P2) { rate = EXERCISE_R2; } else if (i == EXERCISE_SM_P3) { rate = EXERCISE_R3; } if (rand() % 10 < rate) { if (pool_size(p) == EXERCISE_SM_COUNT && pool_unused(p) == 0) { continue; } else if ((data = pool_get(p)) == NULL) { AMSG(""); return -1; } else if (linkedlist_add(l, data) == -1) { AMSG("%04d %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); return -1; } tcase_printf(verbose, "%04d get %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); } else if ((data = linkedlist_remove(l, 0))) { if (data == NULL || pool_release(p, data) == -1) { AMSG("%04d %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); return -1; } tcase_printf(verbose, "%04d rel %p s=%d,u=%d\n", i, data, pool_size(p), pool_unused(p)); } else { tcase_printf(verbose, "%04d nothing to release\n", i); } } linkedlist_del(l, NULL, NULL); pool_del(p); return 0; }
SMALL_EXPORT list *list_new(int size) { list *l = safe_alloc(sizeof(list)); l->head = l->tail = NULL; l->pool = pool_new(size * sizeof(list_item), sizeof(list_item)); l->size = size; list_init(l); return l; }
END_TEST START_TEST(slablist) { slabclass_t* psct = &slab.slabclass[1]; // size:144 perslab:58254 void* ps = pool_new(&slab); bool ret = slab_add(&slab, psct, ps); fail_unless(ret); fail_unless(NULL != psct->slab_list); fail_unless(ps == psct->slab_list->ptr); fail_unless(NULL == psct->slab_list->next); size_t need_byte = (size_t)ceil(psct->perslab / 8); void* pv = malloc(need_byte); memset(pv, 0, need_byte); fail_unless(0 == memcmp(pv, psct->slab_list->used_bitmap, need_byte)); void* ps2 = pool_new(&slab); ret = slab_add(&slab, psct, ps2); fail_unless(ret); fail_unless(NULL != psct->slab_list); fail_unless(ps2 == psct->slab_list->ptr); fail_unless(NULL != psct->slab_list->next); fail_unless(NULL == psct->slab_list->next->next); void* ps3 = pool_new(&slab); ret = slab_add(&slab, psct, ps3); fail_unless(ret); slablist_t* pslt = slab_search(&slab, psct, ((char*)ps + 4)); fail_unless(pslt == psct->slab_list->next->next); pslt = slab_search(&slab, psct, ((char*)ps2)); fail_unless(pslt == psct->slab_list->next); pslt = slab_search(&slab, psct, ((char*)ps3 + SETTING_ITEM_SIZE_MAX)); fail_unless(pslt == psct->slab_list); pslt = slab_search(&slab, psct, 0); fail_unless(pslt == NULL); void* ps4 = slab_remove(&slab, psct, psct->slab_list->next); fail_unless(ps4 == ps2); fail_unless(psct->slab_list->ptr == ps3); fail_unless(psct->slab_list->next->ptr == ps); fail_unless(psct->slab_list->next->next == NULL); void* ps5 = slab_remove(&slab, psct, psct->slab_list); fail_unless(ps5 == ps3); fail_unless(psct->slab_list->ptr == ps); fail_unless(psct->slab_list->next == NULL); }
static void _ensure_pool_delete_gracefully_handles_cleaned_up_pool( void ) { pool_t * pool; allocator_counted_t alloc; allocator_counted_init_default( &alloc ); pool = pool_new( 128, 4, allocator_counted_get( &alloc ) ); pool_cleanup( pool ); pool_delete( pool ); TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 ); }
J9Pool* MM_ConfigurationStandard::createEnvironmentPool(MM_EnvironmentBase* env) { OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary()); uintptr_t numberElements = _configurationLanguageInterface->getEnvPoolNumElements(); uintptr_t poolFlags = _configurationLanguageInterface->getEnvPoolFlags(); return pool_new(sizeof(MM_EnvironmentStandard), numberElements, sizeof(uint64_t), poolFlags, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_MM, POOL_FOR_PORT(OMRPORTLIB)); }
/* match will find a child in the parent, and either replace (if it's an insert) or remove (if data is NULL) */ int xdb_act(xdbcache xc, jid owner, char *ns, char *act, char *match, xmlnode data) { xdbcache newx; pool p; if(xc == NULL || owner == NULL || ns == NULL) { fprintf(stderr,"Programming Error: xdb_set() called with NULL\n"); return 1; } log_debug(ZONE,"XDB SET"); /* init this newx */ p = pool_new(); newx = pmalloco(p, sizeof(_xdbcache)); newx->i = xc->i; newx->set = 1; newx->data = data; newx->ns = ns; newx->act = act; newx->match = match; newx->owner = owner; newx->sent = time(NULL); newx->preblock = 0; /* flag */ pthread_mutex_lock(&(xc->sem)); newx->id = xc->id++; newx->next = xc->next; newx->prev = xc; newx->next->prev = newx; xc->next = newx; pthread_mutex_unlock(&(xc->sem)); /* send it on it's way */ xdb_deliver(xc->i, newx,0); /* if it hasn't already returned, we should block here until it returns */ while (newx->preblock != 1) usleep(10); /* if it didn't actually get set, flag that */ if(newx->data == NULL) { pool_free(p); return 1; } xmlnode_free(newx->data); pool_free(p); return 0; }
os_t os_new(void) { pool_t p; os_t os; p = pool_new(); os = (os_t) pmalloco(p, sizeof(struct os_st)); os->p = p; return os; }
void mt_ns_msg(mpacket mp, session s) { xmlnode msg, oob; char *body, *ctype, *ptr; /* message body spool*/ pool p = pool_new(); spool sp = spool_new(p); if (s->ti->inbox_headlines == 0) return; ctype = strchr(mt_packet_data(mp,5),':') + 2; body = mt_packet_data(mp,mp->count - 1); /* this message is a Hotmail inbox notification */ if ((strncmp(ctype,"text/x-msmsgsinitialemailnotification",37) != 0) && (strncmp(ctype,"text/x-msmsgsemailnotification",30) != 0)) return; /* Fede <*****@*****.**> */ /* cut off the junk at the end */ if ((ptr = strstr(body,"Inbox-URL")) != NULL) { *ptr = '\0'; spool_add(sp,body); } else { if ((ptr = strstr(body,"From:")) != NULL) { char *p = strchr(ptr, '\r'); *p = '\0'; spooler(sp,"Mail from: ", ptr + 6,sp); body = p + 1; } if ((ptr = strstr(body,"From-Addr:")) != NULL) { *strchr(ptr, '\r') = '\0'; spooler(sp," <",ptr + 11,">",sp); } } msg = xmlnode_new_tag("message"); xmlnode_put_attrib(msg,"to",jid_full(s->id)); xmlnode_put_attrib(msg,"from",s->host); xmlnode_put_attrib(msg,"type","headline"); xmlnode_insert_cdata(xmlnode_insert_tag(msg,"subject"),"Hotmail",-1); xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),spool_print(sp),-1); oob = xmlnode_insert_tag(msg,"x"); xmlnode_put_attrib(oob,"xmlns","jabber:x:oob"); xmlnode_insert_cdata(xmlnode_insert_tag(oob,"url"),"http://www.hotmail.com/cgi-bin/folders",-1); xmlnode_insert_cdata(xmlnode_insert_tag(oob,"desc"),"Login to your Hotmail e-mail account",-1); mt_deliver(s->ti,msg); pool_free(p); }
jqueue_t jqueue_new(void) { pool_t p; jqueue_t q; p = pool_new(); q = (jqueue_t)pmalloco(p, sizeof(struct _jqueue_st)); q->p = p; q->init_time = time(NULL); return q; }
/* blocks until namespace is retrieved, host must map back to this service! */ xmlnode xdb_get(xdbcache xc, jid owner, char *ns) { xdbcache newx; xmlnode x; pool p; if(xc == NULL || owner == NULL || ns == NULL) { fprintf(stderr,"Programming Error: xdb_get() called with NULL\n"); return NULL; } log_debug(ZONE,"XDB GET"); /* init this newx */ p = pool_new(); newx = pmalloco(p, sizeof(_xdbcache)); newx->i = xc->i; newx->set = 0; newx->data = NULL; newx->ns = ns; newx->owner = owner; newx->sent = time(NULL); newx->preblock = 0; /* flag */ pthread_mutex_lock(&(xc->sem)); newx->id = xc->id++; newx->next = xc->next; newx->prev = xc; newx->next->prev = newx; xc->next = newx; pthread_mutex_unlock(&(xc->sem)); /* send it on it's way */ xdb_deliver(xc->i, newx,0); /* if it hasn't already returned, we should block here until it returns */ while (newx->preblock != 1) usleep(10); /* newx.data is now the returned xml packet */ /* return the xmlnode inside <xdb>...</xdb> */ for(x = xmlnode_get_firstchild(newx->data); x != NULL && xmlnode_get_type(x) != NTYPE_TAG; x = xmlnode_get_nextsibling(x)); /* there were no children (results) to the xdb request, free the packet */ if(x == NULL) xmlnode_free(newx->data); pool_free(p); return x; }
int http_redirect_client_init(http_redirect_t *server, http_redirect_client_t *client) { int err=-1; do { memset(client, 0, sizeof(*client)); client->server = server; client->pool = pool_new(); http_header_init(&client->http_req, client->pool); client->recv_max = HTTP_REDIRECT_CLIENT_BUF_MAX; err = 0; } while(0); return err; }
static void _ensure_pool_new_returns_initialised_pool( void ) { pool_t * pool; allocator_guarded_t alloc; allocator_guarded_init_default( &alloc ); pool = pool_new( 128, 4, allocator_guarded_get( &alloc ) ); TEST_REQUIRE( pool ); TEST_REQUIRE( pool->buffer ); TEST_REQUIRE( allocator_guarded_length( pool->buffer ) >= 128 * 4 ); TEST_REQUIRE( pool->next ); TEST_REQUIRE( pool->allocator == allocator_guarded_get( &alloc ) ); pool_delete( pool ); }
/* public functions */ xtree_t xtree_new(int base, int prime) { xtree_t xnew; pool_t p; p = pool_new(); xnew = pmalloc(p, sizeof(xtree_st)); xnew->p = p; xnew->base = (base ? base : 0xf422f); xnew->prime = (prime ? prime : 31); xnew->count = 0; xnew->trees = (node_t *) pmalloc_z(p, sizeof(node_t) * xnew->prime); return xnew; }
jlimit jlimit_new(int maxt, int maxp) { pool p; jlimit r; p = pool_new(); r = pmalloc(p, sizeof(_jlimit)); r->key = NULL; r->start = r->points = 0; r->maxt = maxt; r->maxp = maxp; r->p = p; return r; }
int http_redirect_init(http_redirect_t *server, fdselect_t *fdselect, char *root_dir) { int err; do { memset(server, 0, sizeof(*server)); server->fdselect = fdselect; server->pool = pool_new(); assertb(server->pool); server->root_dir = pool_strdup(server->pool, root_dir); err = 0; } while(0); return 0; }
st_filter_t storage_filter(const char *filter) { pool_t p; st_filter_t f; if(filter == NULL) return NULL; p = pool_new(); f = _storage_filter(p, filter, strlen(filter)); if(f == NULL) pool_free(p); return f; }
void mtq_init() { mtq mtq = NULL; /* queue */ mth t = NULL; int n,k; pool newp; mtq__master = malloc(sizeof(_mtqmaster)); /* happens once, global */ mtq__master->random = 0; /* start MTQ threads */ for(n=0;n<MTQ_THREADS;n++) { newp = pool_new(); t = pmalloco(newp, sizeof(_mth)); t->p = newp; t->mtq = pmalloco(newp,sizeof(_mtq)); t->mtq->first = t->mtq->last = NULL; t->mtq->free_first = t->mtq->free_last = NULL; t->mtq->users_count = 0; t->mtq->dl = 0; t->mtq->length = 0; mtq = t->mtq; /* build queue cache */ for (k=0;k<MTQ_QUEUE_LONG;k++) { /* mtq->free_last if the first to take from queue*/ mtq->queue[k].memory = 0; mtq->queue[k].prev = NULL; /* if queue is empty */ if (mtq->free_last == NULL) mtq->free_last = &(mtq->queue[k]); else mtq->free_first->prev = &(mtq->queue[k]); mtq->free_first = &(mtq->queue[k]); mtq->length++; } SEM_INIT(t->mtq->sem); COND_INIT(t->mtq->cond); pthread_create(&(t->thread), NULL, mtq_main, (void *)t); mtq__master->all[n] = t; /* assign it as available */ } }