Esempio n. 1
0
/* reload configurations for the PPPoE daemon */
int
pppoed_reload(pppoed *_this, struct pppoe_confs *pppoe_conf)
{
	int                i, count, do_start, found;
	struct pppoe_conf *conf;
	struct ifaddrs    *ifa0;
	slist              rmlist, newlist;
	struct {
		char			 ifname[IF_NAMESIZE];
		char			 name[PPPOED_PHY_LABEL_SIZE];
		struct pppoe_conf	*conf;
	} listeners[PPPOE_NLISTENER];
	pppoed_listener   *l;
	pppoe_session     *session;
	hash_link         *hl;

	do_start = 0;
	ifa0 = NULL;
	slist_init(&rmlist);
	slist_init(&newlist);

	if (getifaddrs(&ifa0) != 0) {
		pppoed_log(_this, LOG_ERR,
		    "getifaddrs() failed on %s(): %m", __func__);
		goto fail;
	}
	count = 0;
	TAILQ_FOREACH(conf, pppoe_conf, entry) {
		strlcpy(listeners[count].ifname, conf->if_name,
		    sizeof(listeners[count].ifname));
		strlcpy(listeners[count].name, conf->name,
		    sizeof(listeners[count].name));
		listeners[count].conf = conf;
		count++;
	}
Esempio n. 2
0
struct util_buf_pool *util_buf_pool_create_ex(size_t size, size_t alignment,
					       size_t max_cnt, size_t chunk_cnt,
					       util_buf_region_alloc_hndlr alloc_hndlr,
					       util_buf_region_free_hndlr free_hndlr)
{
	size_t entry_sz;
	struct util_buf_pool *buf_pool;

	buf_pool = calloc(1, sizeof(*buf_pool));
	if (!buf_pool)
		return NULL;

	buf_pool->alloc_hndlr = alloc_hndlr;
	buf_pool->free_hndlr = free_hndlr;
	buf_pool->data_sz = size;
	buf_pool->alignment = alignment;
	buf_pool->max_cnt = max_cnt;
	buf_pool->chunk_cnt = chunk_cnt;

	entry_sz = util_buf_use_ftr(buf_pool) ?
		(size + sizeof(struct util_buf_footer)) : size;
	buf_pool->entry_sz = fi_get_aligned_sz(entry_sz, alignment);

	slist_init(&buf_pool->buf_list);
	slist_init(&buf_pool->region_list);

	if (util_buf_grow(buf_pool)) {
		free(buf_pool);
		return NULL;
	}
	return buf_pool;
}
//Private Method
int init_state(pm_t* pm, pm_state_t* state, pm_int_t depth) {

	if(pm == NULL || state == NULL) {
		return -1;
	}

	memset(state, 0, sizeof(pm_state_t));

	state->depth = depth;
	state->id = pm->newstate;
	state->fail = NULL;

	state->output = (slist_t*)malloc(sizeof(slist_t));
	state->_transitions = (slist_t*)malloc(sizeof(slist_t));
	if(state->output == NULL || state->_transitions == NULL) {
		perror("Failed to allocate memory\n");
		exit(-1);
	}

	slist_init(state->output);
	slist_init(state->_transitions);

	pm->newstate++;

	return 0;
}
Esempio n. 4
0
int main()
{
    int i, x;
    list *first = slist_init();
    list *second = slist_init();
    list *m;

    slist_push_back(first, 0);
    slist_push_back(first, 2);
    slist_push_back(first, 4);
    slist_push_back(first, 6);
    slist_push_back(first, 8);
    slist_show(first, mydump);

    slist_push_back(second, 1);
    slist_push_back(second, 3);
    slist_push_back(second, 5);
    slist_push_back(second, 7);
    slist_push_back(second, 9);
    slist_show(second, mydump);

    m = merge(first, second);
    slist_show(m, mydump);

    return 0;
}
Esempio n. 5
0
int util_buf_pool_create_ex(struct util_buf_pool **buf_pool,
			    size_t size, size_t alignment,
			    size_t max_cnt, size_t chunk_cnt,
			    util_buf_region_alloc_hndlr alloc_hndlr,
			    util_buf_region_free_hndlr free_hndlr,
			    void *pool_ctx)
{
	size_t entry_sz;

	(*buf_pool) = calloc(1, sizeof(**buf_pool));
	if (!*buf_pool)
		return -FI_ENOMEM;

	(*buf_pool)->alloc_hndlr = alloc_hndlr;
	(*buf_pool)->free_hndlr = free_hndlr;
	(*buf_pool)->data_sz = size;
	(*buf_pool)->alignment = alignment;
	(*buf_pool)->max_cnt = max_cnt;
	(*buf_pool)->chunk_cnt = chunk_cnt;
	(*buf_pool)->ctx = pool_ctx;

	entry_sz = util_buf_use_ftr(*buf_pool) ?
		(size + sizeof(struct util_buf_footer)) : size;
	(*buf_pool)->entry_sz = fi_get_aligned_sz(entry_sz, alignment);

	slist_init(&(*buf_pool)->buf_list);
	slist_init(&(*buf_pool)->region_list);

	if (util_buf_grow(*buf_pool)) {
		free(*buf_pool);
		return -FI_ENOMEM;
	}
	return FI_SUCCESS;
}
Esempio n. 6
0
/*****************************************************
 PUBLIC: void medin_initparams()
*****************************************************/
void
medin_initparams( param *p, const char *progname )
{
	p->readformat       = BIBL_MEDLINEIN;
	p->charsetin        = BIBL_CHARSET_UNICODE;
	p->charsetin_src    = BIBL_SRC_DEFAULT;
	p->latexin          = 0;
	p->xmlin            = 1;
	p->utf8in           = 1;
	p->nosplittitle     = 0;
	p->verbose          = 0;
	p->addcount         = 0;
	p->output_raw       = BIBL_RAW_WITHMAKEREFID |
	                      BIBL_RAW_WITHCHARCONVERT;

	p->readf    = medin_readf;
	p->processf = medin_processf;
	p->cleanf   = NULL;
	p->typef    = NULL;
	p->convertf = NULL;
	p->all      = NULL;
	p->nall     = 0;

	slist_init( &(p->asis) );
	slist_init( &(p->corps) );

	if ( !progname ) p->progname = NULL;
	else p->progname = strdup( progname );
}
Esempio n. 7
0
int _gnix_sfl_init(int elem_size, int offset, int init_size,
		   int refill_size, int growth_factor,
		   int max_refill_size, struct gnix_s_freelist *fl)
{
	assert(elem_size > 0);
	assert(offset >= 0);
	assert(init_size >= 0);
	assert(refill_size >= 0);
	assert(growth_factor >= 0);
	assert(max_refill_size >= 0);

	int fill_size = init_size != 0 ? init_size : GNIX_SFL_INIT_SIZE;

	fl->refill_size = (refill_size != 0 ?
			   refill_size :
			   GNIX_SFL_INIT_REFILL_SIZE);
	fl->growth_factor = (growth_factor != 0 ?
			     growth_factor :
			     GNIX_SFL_GROWTH_FACTOR);
	fl->max_refill_size = (max_refill_size != 0 ?
			       max_refill_size :
			       fill_size);
	fl->elem_size = elem_size;
	fl->offset = offset;

	assert(slist_empty(&fl->freelist)); /* maybe should be a warning? */
	slist_init(&fl->freelist);
	assert(slist_empty(&fl->chunks)); /* maybe should be a warning? */
	slist_init(&fl->chunks);

	return __gnix_sfl_refill(fl, fill_size);
}
Esempio n. 8
0
int main()
{
    int data[LOOP];
    int i, res;
    int* p;
    struct slist_t* sl;
    sl = slist_init();
    assert(sl);

    for (i = 0; i < LOOP; ++ i) {
        data[i] = rand() % LOOP;
        res = slist_push_front(sl, &data[i]);
        assert(0 == res);
        res = slist_push_back(sl, &data[i]);
        assert(0 == res);
    }
    printf("list count=%d\n", slist_count(sl));

    for (i = LOOP-1; i >= 0; -- i) {
        res = slist_find(sl, &data[i]);
        assert(0 == res);
        p = slist_pop_front(sl);
        assert(p == &data[i]);
        p = slist_pop_back(sl);
        assert(p == &data[i]);
        res = slist_find(sl, &data[i]);
        assert(res < 0);
    }
    printf("list count=%d\n", slist_count(sl));

    slist_release(sl);
    sl = 0;
    return 0;
}
Esempio n. 9
0
int chtbl_init(struct chtbl_t *htbl, int buckets, int (*h)(const void *key),
		int (*match)(const void *key1, const void *key2),
		void (*free_data)(void *data))
{
	int i;

	if (!htbl)
		return -1;

	htbl->table = (struct slist *) malloc(buckets * sizeof(struct slist));
	if (htbl->table == NULL)
		return -1;

	htbl->buckets = buckets;

	for (i = 0; i < htbl->buckets; i++)
		slist_init(&htbl->table[i], free_data);

	htbl->hash = h;
	htbl->match = match;
	htbl->free_data = free_data;
	htbl->size = 0;

	return 0;
}
Esempio n. 10
0
struct sock_rx_entry *sock_rx_new_entry(struct sock_rx_ctx *rx_ctx)
{
	struct sock_rx_entry *rx_entry;
	struct slist_entry *entry;
	int i;

	if (rx_ctx->rx_entry_pool == NULL) {
		rx_ctx->rx_entry_pool = calloc(rx_ctx->attr.size,
						sizeof(*rx_entry));
		if (!rx_ctx->rx_entry_pool)
			return NULL;

		slist_init(&rx_ctx->pool_list);

		for (i = 0; i < rx_ctx->attr.size; i++) {
			slist_insert_tail(&rx_ctx->rx_entry_pool[i].pool_entry,
					  &rx_ctx->pool_list);
			rx_ctx->rx_entry_pool[i].is_pool_entry = 1;
		}
	}

	if (!slist_empty(&rx_ctx->pool_list)) {
		entry = slist_remove_head(&rx_ctx->pool_list);
		rx_entry = container_of(entry, struct sock_rx_entry, pool_entry);
		rx_entry->rx_ctx = rx_ctx;
		entry = slist_remove_head(&rx_ctx->pool_list);
	} else {
Esempio n. 11
0
int tmodule_load(struct tconfig_block *tcfg, struct tconfig_block *global_cfg)
{
	struct tconfig_block *myblk = tcfg;
	struct ics_server    *ics   = NULL;

	ics_servers = NULL;
	tsockets    = NULL;
	g_tcfg      = global_cfg;

	slist_init(&ics_servers, free_ics_server);

	while (myblk != NULL)
	{
		if (!strcmp(myblk->key,"ics_server"))
		{
			ics = ics_server_from_tconfig_block(myblk);

			slist_insert_next(ics_servers, NULL, (void *)ics);

			printf("We have an ICS server %s\n", ics->label);
		}

		myblk = myblk->next;
	}

	/* HACK */
	ics_server_connect(ics, NULL);

	/* FIXME: Need logging mechanism */
	printf("ICS Module Loaded.\n");
	return 1;
}
Esempio n. 12
0
static void
test_12()
{
	slist sl;
	slist *l = &sl;

	slist_init(l);
	slist_add(l, (void *)42);
	slist_add(l, (void *)15);
	slist_add(l, (void *)14);
	slist_add(l, (void *)13);
	slist_add(l, (void *)29);
	slist_add(l, (void *)15);
	slist_add(l, (void *)25);
	slist_add(l, (void *)55);
	slist_add(l, (void *)66);
	slist_add(l, (void *)23);
	slist_qsort(l, test_12_compar);
	ASSERT((int)slist_get(l, 0) == 13);
	ASSERT((int)slist_get(l, 1) == 14);
	ASSERT((int)slist_get(l, 2) == 15);
	ASSERT((int)slist_get(l, 3) == 15);
	ASSERT((int)slist_get(l, 4) == 23);
	ASSERT((int)slist_get(l, 5) == 25);
	ASSERT((int)slist_get(l, 6) == 29);
	ASSERT((int)slist_get(l, 7) == 42);
	ASSERT((int)slist_get(l, 8) == 55);
	ASSERT((int)slist_get(l, 9) == 66);
}
Esempio n. 13
0
static void
test_10()
{
	int i;
	slist sl;
	slist *l = &sl;

	slist_init(l);
	slist_add(l, (void *)1);
	slist_add(l, (void *)2);
	slist_add(l, (void *)3);
	slist_itr_first(l);
	ASSERT((int)slist_itr_next(l) == 1);
	ASSERT((int)slist_itr_next(l) == 2);
	for (i = 4; i < 10000; i++) {
		ASSERT(slist_itr_has_next(l));
		ASSERT((int)slist_itr_next(l) == i - 1);
		if (i % 3 == 1)
			slist_add(l, (void *)i);
		if (i % 3 == 0)
			ASSERT((int)slist_itr_remove(l) == i - 1);
		if (i % 3 != 1)
			slist_add(l, (void *)i);
	}
	slist_itr_first(l);
	while (slist_itr_has_next(l)) {
		slist_itr_next(l);
		slist_itr_remove(l);
	}
	ASSERT((int)slist_length(l) == 0);

	slist_fini(l);
}
Esempio n. 14
0
static void
test_08()
{
	slist sl;
	slist *l = &sl;

	slist_init(l);
	slist_set_size(l, 4);
	slist_add(l, (void *)1);
	slist_add(l, (void *)2);
	slist_add(l, (void *)3);

	/* [1, 2, 3] */

	slist_itr_first(l);
	slist_itr_has_next(l);
	slist_itr_next(l);
	slist_itr_remove(l);
	/* [2, 3] */

	slist_add(l, (void *)4);
	/* [2, 3, 4] */
	ASSERT((int)slist_get(l, 0) == 2);
	ASSERT((int)slist_get(l, 1) == 3);
	ASSERT((int)slist_get(l, 2) == 4);
	slist_add(l, (void *)5);

	/* [2, 3, 4, 5] */
	ASSERT((int)slist_get(l, 0) == 2);
	ASSERT((int)slist_get(l, 1) == 3);
	ASSERT((int)slist_get(l, 2) == 4);
	ASSERT((int)slist_get(l, 3) == 5);
}
Esempio n. 15
0
static void
test_01()
{
	int i;
	slist sl;
	slist *l = &sl;

	slist_init(&sl);


	for (i = 0; i < 255; i++) {
		slist_add(&sl, (void *)i);
	}
	for (i = 0; i < 128; i++) {
		slist_remove_first(&sl);
	}
	for (i = 0; i < 128; i++) {
		slist_add(&sl, (void *)(i + 255));
	}
	ASSERT((int)slist_get(&sl, 127) == 255);
	ASSERT((int)slist_get(&sl, 254) == 129 + 253);
	ASSERT((int)slist_length(&sl) == 255);

	/* dump(&sl); */
	/* printf("==\n"); */
	slist_add(&sl, (void *)(128 + 255));
	ASSERT((int)slist_get(&sl, 127) == 255);
	/* ASSERT((int)slist_get(&sl, 255) == 128 + 255); */
	ASSERT((int)slist_length(&sl) == 256);
	/* dump(&sl); */
}
Esempio n. 16
0
int util_buf_pool_create_attr(struct util_buf_attr *attr,
			      struct util_buf_pool **buf_pool)
{
	size_t entry_sz;
	ssize_t hp_size;

	(*buf_pool) = calloc(1, sizeof(**buf_pool));
	if (!*buf_pool)
		return -FI_ENOMEM;

	(*buf_pool)->attr = *attr;

	entry_sz = (attr->size + sizeof(struct util_buf_footer));
	(*buf_pool)->entry_sz = fi_get_aligned_sz(entry_sz, attr->alignment);

	hp_size = ofi_get_hugepage_size();

	if ((*buf_pool)->attr.chunk_cnt * (*buf_pool)->entry_sz < hp_size)
		(*buf_pool)->attr.is_mmap_region = 0;
	else
		(*buf_pool)->attr.is_mmap_region = 1;

	if (!(*buf_pool)->attr.indexing.ordered)
		slist_init(&(*buf_pool)->list.buffers);
	else
		dlist_init(&(*buf_pool)->list.regions);

	return FI_SUCCESS;
}
Esempio n. 17
0
ret_code_t ilcore_init_comp(ilcore_comp_h *h, OMX_CALLBACKTYPE *cb, char *name)
{
    OMX_ERRORTYPE err;
    ilcore_comp_ctx_t *ctx;

    ctx = (ilcore_comp_ctx_t *)malloc(sizeof(ilcore_comp_ctx_t));
    if (!ctx)
    {
        DBG_E("Memory allocation failed\n");
        return L_FAILED;
    }
    memset(ctx, 0, sizeof(ilcore_comp_ctx_t));

    slist_init(&ctx->event_list);
    msleep_init(&ctx->event_sleep);
    
    ctx->name = strdup(name);
    if (!ctx->name)
    {
        DBG_E("strdup failed\n");
        return L_FAILED;
    }

    err = OMX_GetHandle(&ctx->handle, name, ctx, cb);
    if (err != OMX_ErrorNone)
    {
        DBG_E("OMX_GetHandle failed. err=%d\n", err);
        return L_FAILED;
    }

    *h = ctx;

    return L_OK;
}
Esempio n. 18
0
/* Initializes all of the transition arrows to FAIL.  representation_type must
   be either DENSE_TRANSITIONS or SPARSE_TRANSITIONS.  If everything is ok,
   returns 0.  If bad things happen, returns -1. */
static int aho_corasick_goto_initialize(aho_corasick_state_t *state) {
	aho_corasick_transition_t rep_type = AHO_CORASICK_DENSE_TRANSITIONS;
	if (state->depth >= TRANSITION_SWITCHING_THRESHOLD) {
		rep_type = AHO_CORASICK_SPARSE_TRANSITIONS;
	}
	switch (rep_type) {
	case AHO_CORASICK_DENSE_TRANSITIONS:
		state->_transitions.type = AHO_CORASICK_DENSE_TRANSITIONS;
		state->_transitions.data.array =
			xalloc(AHO_CORASICK_CHARACTERS *
			       sizeof(aho_corasick_state_t *));
		if (state->_transitions.data.array == NULL)
			return -1;
		memset(state->_transitions.data.array,
		       (int) FAIL,
		       AHO_CORASICK_CHARACTERS*sizeof(aho_corasick_state_t *));
		return 0;
	case AHO_CORASICK_SPARSE_TRANSITIONS:
		state->_transitions.type = AHO_CORASICK_SPARSE_TRANSITIONS;
		state->_transitions.data.slist =
			xalloc(sizeof(slist_t));
		if (state->_transitions.data.slist == NULL)
			return -1;
		slist_init(state->_transitions.data.slist);
		return 0;
	}

    return -1;
}
Esempio n. 19
0
static int setup(void) {
	slist_init(&m);
	slist_link_init(&x.lnk);
	slist_link_init(&y.lnk);
	slist_link_init(&z.lnk);
	return 0;
}
Esempio n. 20
0
int _gnix_queue_create(struct gnix_queue **queue, alloc_func alloc_item,
		       free_func free_item, size_t entry_size,
		       size_t entry_count)
{
	struct gnix_queue *q;
	struct slist_entry *temp;
	int ret = FI_SUCCESS;

	if (!alloc_item || !free_item) {
		ret = -FI_EINVAL;
		goto err;
	}

	q = calloc(1, sizeof(*q));
	if (!q) {
		ret = -FI_ENOMEM;
		goto err;
	}

	q->alloc_item = alloc_item;
	q->free_item = free_item;

	q->entry_size = entry_size;

	slist_init(&q->item_list);
	slist_init(&q->free_list);

	for (size_t count = 0; count < entry_count; count++) {
		temp = q->alloc_item(entry_size);
		if (!temp) {
			ret = -FI_ENOMEM;
			goto err1;
		}

		_gnix_queue_enqueue_free(q, temp);
	}

	*queue = q;

	return ret;

err1:
	_gnix_queue_destroy(q);
	*queue = NULL;
err:
	return ret;
}
Esempio n. 21
0
/* initialize pptp daemon */
int
pptpd_init(pptpd *_this)
{
	int i, m;
	struct sockaddr_in sin0;
	uint16_t call0, call[UINT16_MAX - 1];

	memset(_this, 0, sizeof(pptpd));
	_this->id = pptpd_seqno++;

	slist_init(&_this->listener);
	memset(&sin0, 0, sizeof(sin0));
	sin0.sin_len = sizeof(sin0);
	sin0.sin_family = AF_INET;
	if (pptpd_add_listener(_this, 0, PPTPD_DEFAULT_LAYER2_LABEL,
	    (struct sockaddr *)&sin0) != 0) {
		return 1;
	}

	_this->ip4_allow = NULL;

	slist_init(&_this->ctrl_list);
	slist_init(&_this->call_free_list);

	/* randomize call id */
	for (i = 0; i < countof(call) ; i++)
		call[i] = i + 1;
	for (i = countof(call); i > 1; i--) {
		m = random() % i;
		call0 = call[m];
		call[m] = call[i - 1];
		call[i - 1] = call0;
	}

	for (i = 0; i < MIN(PPTP_MAX_CALL, countof(call)); i++)
		slist_add(&_this->call_free_list, (void *)(uintptr_t)call[i]);
	slist_add(&_this->call_free_list, (void *)PPTPD_SHUFFLE_MARK);

	if (_this->call_id_map == NULL)
		_this->call_id_map = hash_create(pptp_call_cmp, pptp_call_hash,
		    0);

	return 0;
}
Esempio n. 22
0
/**
 * initialize L2TP daemon instance
 * <p>
 * {@link _l2tpd#bind_sin} will return with .sin_family = AF_INET,
 * .sin_port = 1701 and .sin_len = "appropriate value"
 * </p>
 */
int
l2tpd_init(l2tpd *_this)
{
	int i, off;
	u_int id;

	L2TPD_ASSERT(_this != NULL);
	memset(_this, 0, sizeof(l2tpd));

	slist_init(&_this->listener);
	slist_init(&_this->free_session_id_list);

	_this->id = l2tpd_id_seq++;

	if ((_this->ctrl_map = hash_create(short_cmp, short_hash,
	    L2TPD_TUNNEL_HASH_SIZ)) == NULL) {
		log_printf(LOG_ERR, "hash_create() failed in %s(): %m",
		    __func__);
		return 1;
	}

	if (slist_add(&_this->free_session_id_list,
	    (void *)L2TP_SESSION_ID_SHUFFLE_MARK) == NULL) {
		l2tpd_log(_this, LOG_ERR, "slist_add() failed on %s(): %m",
		    __func__);
		return 1;
	}
	off = arc4random() & L2TP_SESSION_ID_MASK;
	for (i = 0; i < L2TP_NCALL; i++) {
		id = (i + off) & L2TP_SESSION_ID_MASK;
		if (id == 0)
			id = (off - 1) & L2TP_SESSION_ID_MASK;
		if (slist_add(&_this->free_session_id_list,
		    (void *)(uintptr_t)id) == NULL) {
			l2tpd_log(_this, LOG_ERR,
			    "slist_add() failed on %s(): %m", __func__);
			return 1;
		}
	}
	_this->purge_ipsec_sa = 1;
	_this->state = L2TPD_STATE_INIT;

	return 0;
}
Esempio n. 23
0
int ioq_init(struct ioq *q, unsigned int bg_threads)
{
	struct epoll_event evt;
	syserr_t err;

	if (runq_init(&q->run, bg_threads) < 0) {
		err = syserr_last();
		goto fail_runq;
	}

	if (!bg_threads)
		q->run.wakeup = wakeup_runq;

	waitq_init(&q->wait, &q->run);
	q->wait.wakeup = wakeup_waitq;

	thr_mutex_init(&q->lock);
	slist_init(&q->mod_list);

	if (pipe(q->intr) < 0) {
		err = syserr_last();
		goto fail_pipe;
	}

	fcntl(q->intr[0], F_SETFL, fcntl(q->intr[0], F_GETFL) | O_NONBLOCK);

	q->intr_state = 0;

	q->epoll_fd = epoll_create(64);
	if (q->epoll_fd < 0) {
		err = syserr_last();
		goto fail_epoll;
	}

	memset(&evt, 0, sizeof(evt));
	evt.events = EPOLLIN;
	if (epoll_ctl(q->epoll_fd, EPOLL_CTL_ADD, q->intr[0], &evt) < 0) {
		err = syserr_last();
		goto fail_ctl;
	}

	return 0;

fail_ctl:
	close(q->epoll_fd);
fail_epoll:
	close(q->intr[0]);
	close(q->intr[1]);
fail_pipe:
	thr_mutex_destroy(&q->lock);
	waitq_destroy(&q->wait);
	runq_destroy(&q->run);
fail_runq:
	syserr_set(err);
	return -1;
}
Esempio n. 24
0
static void
test_13()
{
	slist sl;
	slist *l = &sl;

	slist_init(l);
	slist_qsort(l, test_12_compar);
	/* still alive without SIGFPE */
}
Esempio n. 25
0
/* slist_t */
void _type_init_slist(const void* cpv_input, void* pv_output)
{
    bool_t b_result = false;
    assert(cpv_input != NULL && pv_output != NULL);

    b_result = _create_slist_auxiliary((slist_t*)cpv_input, (char*)pv_output);
    assert(b_result);
    /* initialize slist_t */
    slist_init((slist_t*)cpv_input);
}
Esempio n. 26
0
/* Test code for removing of the first, last and middle item. */
static void
test_01a()
{
	int i, f;
	slist sl;
	slist *l = &sl;

	slist_init(&sl);
	slist_add(&sl, (void *)1);

	ASSERT(sl.list_size == 256);

#define	SETUP()						\
    {							\
	l->last_idx =  64;				\
	l->first_idx = 192;				\
	for (i = 0; i < slist_length(l); i++) {		\
		slist_set(l, i, (void *)i);		\
	}						\
    }

	/* Remove the first item. */
	SETUP();
	f = 0;
	while (slist_length(l) > 0) {
		slist_remove(l, 0);
		f++;
		for (i = 0; i < slist_length(l); i++) {
			ASSERT((int)slist_get(l, i) == i + f);
		}
	}

	/* Remove the last item. */
	SETUP();
	while (slist_length(l) > 0) {
		slist_remove(l, slist_length(l) - 1);
		for (i = 0; i < slist_length(l); i++) {
			ASSERT((int)slist_get(l, i) == i);
		}
	}
	/* Remove the second item from the end. */
	SETUP();
	while (slist_length(l) > 1) {
		slist_remove(l, slist_length(l) - 2);
		for (i = 0; i < slist_length(l) - 1; i++) {
			ASSERT((int)slist_get(l, i) == i);
		}
		if (slist_length(l) > 0) {
			ASSERT((int)slist_get(l, slist_length(l) - 1) == 127);
		}
	}
	slist_remove(l, slist_length(l) - 1);
	ASSERT(slist_length(l) == 0);
}
Esempio n. 27
0
void os_init(void)
{
    moduleAddOperServCmds();

    /* Initialization of the lists */
    slist_init(&servadmins);
    servadmins.opts = &saopts;
    slist_init(&servopers);
    servopers.opts = &soopts;

    slist_init(&akills);
    akills.opts = &akopts;

    if (ircd->sgline) {
        slist_init(&sglines);
        sglines.opts = &sgopts;
    }
    if (ircd->sqline) {
        slist_init(&sqlines);
        sqlines.opts = &sqopts;
    }
    if (ircd->szline) {
        slist_init(&szlines);
        szlines.opts = &szopts;
    }
}
static struct slist *get_map_bucket(struct hash_table *m, void *key, bool allocate_on_empty)
{
    if (!m) { return NULL; }
    
    const size_t bucket = (m->hasher)(m, key);
    struct slist **index = &m->table[bucket];
    
    if (!*index && allocate_on_empty) {
        *index = slist_init((bool (*)(const void *, const void *))m->comparer);
    }
    
    return *index;
}
Esempio n. 29
0
extern RET_T ss_create_worker_threads(size_t thread_num, P_THREAD_OBJ threads)
{
    int i = 0;

    pthread_attr_t  attr;
    int ret = 0;

    pthread_mutex_init(&init_lock, NULL);
    pthread_cond_init(&init_cond, NULL);

    for (i=0; i < thread_num; ++i)
    {
        int fds[2];
        if (pipe(fds)) {
            SYS_ABORT("Can't create notify pipe");
        }

        threads[i].notify_receive_fd = fds[0];
        threads[i].notify_send_fd = fds[1];

        threads[i].base = event_init();
        if (! threads[i].base ){
            SYS_ABORT("Can't allocate event base");
        }
        threads[i].p_notify_event = event_new(threads[i].base, threads[i].notify_receive_fd,
                                             EV_READ | EV_PERSIST, thread_process, &threads[i]);

        if (! threads[i].p_notify_event ){
            SYS_ABORT("Can't allocate new event");
        }

        if (event_add(threads[i].p_notify_event, 0) == -1) {
            SYS_ABORT("Can't monitor libevent notify pipe");
        }

        slist_init(&threads[i].conn_queue);
        pthread_mutex_init(&threads[i].q_lock, NULL); 

        pthread_attr_init(&attr);
        if ((ret = pthread_create(&threads[i].thread_id, &attr, thread_run, (void*)(&threads[i]))) != 0) 
        {
             SYS_ABORT("Cannot create worker thread %s", strerror(ret));
        }
    }


    pthread_mutex_lock(&init_lock);
    wait_for_thread_registration(thread_num);
    pthread_mutex_unlock(&init_lock);

}
Esempio n. 30
0
int
aho_corasick_maketree(aho_corasick_t *in)
{
	slist_t queue;
	aho_corasick_state_t *state,*s,*r;
	aho_corasick_t *g = in;
	int i;

	slist_init(&queue);

	// Set all FAIL transition of 0 state to point to itself
	for(i = 0; i < AHO_CORASICK_CHARACTERS ;i++)
	{
		if ( aho_corasick_goto_get(g->zerostate,i) == FAIL )
			aho_corasick_goto_set(g->zerostate, i, g->zerostate);
		// Construct fail()
		else
		{
			if ( slist_append(&queue,aho_corasick_goto_get(g->zerostate,i)) < 0 )
				goto fail;
			aho_corasick_fail(aho_corasick_goto_get(g->zerostate,i)) = g->zerostate;
		}
	}

	// Set fail() for depth > 0
	while( (r = slist_pop_first(&queue)) != NULL )
	{
		for(i = 0; i < AHO_CORASICK_CHARACTERS ;i++)
		{
			if ( (s = aho_corasick_goto_get(r,i)) == FAIL )
				continue;
			if ( slist_append(&queue,s) < 0 )
				goto fail;
			state = aho_corasick_fail(r);
			while( aho_corasick_goto_get(state,i) == FAIL )
				state = aho_corasick_fail(state);
			aho_corasick_fail(s) = aho_corasick_goto_get(state,i);
			debug(printf("Setting f(%u) == %u\n",s->id,
				     aho_corasick_goto_get(state,i)->id));
			// Join outputs missing
		}
	}

	slist_destroy(&queue,SLIST_LEAVE_DATA);
	return 0;

fail:
	slist_destroy(&queue,SLIST_LEAVE_DATA);
	return -1;
}