예제 #1
0
/**
 * \brief Apply the update structure to the current configuration and execute
 *   callbacks (create/update/delete) on channels/profiles
 * \note After update, the \p update structure is automatically freed.
 * \param[in,out] mgr    Event manager
 * \param[in]     update Update structure
 */
static void
pevents_update_apply(pevents_t *mgr, struct pevents_update *update)
{
	// Copy callbacks from old channels/profiles to new channels/profiles
	update->profiles.cbs = mgr->profiles.cbs;
	update->channels.cbs = mgr->channels.cbs;

	// Call "on_delete" callbacks on OLD profiles/channels
	group_on_delete(&mgr->profiles);
	group_on_delete(&mgr->channels);

	// Call "on_update" callbacks on successfully mapped profiles/channels
	group_on_update(&update->profiles, update->prfl_flags);
	group_on_update(&update->channels, update->chnl_flags);

	// Call "on_create" callbacks on NEW profiles/channels
	group_on_create(&update->profiles);
	group_on_create(&update->channels);

	// Delete old information about channels/profiles and apply the update
	group_deinit(&mgr->profiles);
	group_deinit(&mgr->channels);
	mgr->profiles = update->profiles;
	mgr->channels = update->channels;

	// Cleanup after the update
	bitset_clear(mgr->profiles.bitset);
	bitset_clear(mgr->channels.bitset);

	free(update->chnl_flags);
	free(update->prfl_flags);
	free(update);
}
예제 #2
0
void
pevents_destroy(pevents_t *mgr)
{
	// Call on "on_delete" callbacks on all profiles and channels
	bitset_clear(mgr->profiles.bitset);
	bitset_clear(mgr->channels.bitset);

	group_on_delete(&mgr->profiles);
	group_on_delete(&mgr->channels);

	// Delete internal structures for profiles and channels
	group_deinit(&mgr->profiles);
	group_deinit(&mgr->channels);

	free(mgr);
}
예제 #3
0
void
sm_arm_node(Topology_t * topop, Node_t * nodep)
{
	Status_t status;
	Port_t *portp;

	for_all_ports(nodep, portp) {
		if (sm_valid_port(portp) && portp->state == IB_PORT_INIT) {
			status = sm_arm_port(sm_topop, nodep, portp);
			if (status != VSTATUS_OK) {
				IB_LOG_ERROR_FMT(__func__, "TT(ta): can't ARM node %s nodeGuid "FMT_U64" node index %d port index %d",
					   sm_nodeDescString(nodep), nodep->nodeInfo.NodeGUID, nodep->index, portp->index);
				sm_enable_port_led(nodep, portp, TRUE);
			} else {
				bitset_clear(&nodep->initPorts, portp->index);
			}
		} else if(sm_valid_port(portp) && portp->state == IB_PORT_DOWN && portp->portData->linkPolicyViolation) {
			// port marked down administratively for link policy violation but real port state
			// should still be in init, so set linkInitReason here
			sm_set_linkinit_reason(nodep, portp, STL_LINKINIT_OUTSIDE_POLICY);
			sm_enable_port_led(nodep, portp, TRUE);
		}
	}

	if (nodep->nodeInfo.NodeType == NI_TYPE_SWITCH) {
		// clear any pause state on switch doing adaptive routing
		if (nodep->arSupport && nodep->switchInfo.AdaptiveRouting.s.Pause && !nodep->arDenyUnpause) {
			// Setup was successful, clear pause
			sm_SetARPause(nodep, 0) ;
		}
	}
}
예제 #4
0
파일: bitset.c 프로젝트: thumphries/aos
int bitset_toggle(bitset *bs, unsigned int bit) {
    if (bs == NULL || bit >= bs->size) return -BITSET_ERROR;
    if (bitset_test(bs, bit) > 0) {
        return bitset_clear(bs, bit);
    } else {
        return bitset_set(bs, bit);
    }
}
예제 #5
0
파일: index.c 프로젝트: bigbes/tarantool
void
bitset_index_remove_value(struct bitset_index *index, size_t value)
{
	assert(index != NULL);

	if (index->capacity == 0)
		return;

	for (size_t b = 1; b < index->capacity; b++) {
		if (index->bitsets[b] == NULL)
			continue;

		/* Ignore all errors here */
		bitset_clear(index->bitsets[b], value);
	}
	bitset_clear(index->bitsets[0], value);
}
예제 #6
0
static
void test_cardinality()
{
	header();

	struct bitset bm;
	bitset_create(&bm, realloc);

	fail_unless(bitset_cardinality(&bm) == 0);

	size_t cnt = 0;
	fail_if(bitset_set(&bm, 10) < 0);
	cnt++;
	fail_if(bitset_set(&bm, 15) < 0);
	cnt++;
	fail_if(bitset_set(&bm, 20) < 0);
	cnt++;

	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_set(&bm, 10) < 0);
	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_clear(&bm, 20) < 0);
	cnt--;
	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_clear(&bm, 20) < 0);
	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_clear(&bm, 666) < 0);
	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_clear(&bm, 10) < 0);
	cnt--;
	fail_unless(bitset_cardinality(&bm) == cnt);

	fail_if(bitset_clear(&bm, 15) < 0);
	cnt--;
	fail_unless(bitset_cardinality(&bm) == cnt);

	bitset_destroy(&bm);

	footer();
}
예제 #7
0
파일: match.c 프로젝트: pombredanne/nmergec
static void match_push_versions( match *m )
{
    if ( m->prev_bs != NULL )
    {
        bitset_clear( m->prev_bs );
        bitset_or( m->prev_bs, m->bs );
    }
    else
        m->prev_bs = bitset_clone( m->bs );
}
예제 #8
0
int
pevents_process(pevents_t *mgr, const void **channels, void *data)
{
	// Clear bitsets
	bitset_clear(mgr->profiles.bitset);
	bitset_clear(mgr->channels.bitset);

	for (unsigned int i = 0; channels[i] != NULL; i++) {
		// Push data to a channel and its parent profile
		if (pevents_data(mgr, channels[i], data) == 0) {
			// Success
			continue;
		}

		if (i != 0) {
			// Reconfiguration should happen only with the new record!!!
			// This is ugly, because the bitsets will be cleared during reconf.
			MSG_ERROR(msg_module, "Internal error: Reconfiguration request "
				"happened during processing of other channel that the first "
				"one.");
		}

		// Failed -> Reload configuration
		if (pevents_reload(mgr, channels[i])) {
			MSG_ERROR(msg_module, "Failed to reload profiling configuration. ");
			return 1;
		}

		// Try to push data again
		if (pevents_data(mgr, channels[i], data) == 0) {
			// Success
			continue;
		}

		// Failed -> skip the channel
		MSG_ERROR(msg_module, "(internal error) Failed to find a channel info "
			"after reconfiguration. A record will not be stored.");
		return 1;
	}

	return 0;
}
예제 #9
0
bitset *
idset_to_bitset(sdm_idset ids)
{
	sdm_id		id;

	bitset_clear(tmp_bitset);

	for (id = sdm_set_first(ids); !sdm_set_done(ids); id = sdm_set_next(ids)) {
		bitset_set(tmp_bitset, id);
	}

	return tmp_bitset;
}
예제 #10
0
파일: match.c 프로젝트: pombredanne/nmergec
static void match_pop_versions( match *m )
{
    if ( m->prev_bs == NULL )
    {
        if ( m->bs != NULL )
        {
            bitset_dispose( m->bs );
            m->bs = NULL;
        }
    }
    else
    {
        bitset_clear( m->bs );
        bitset_or( m->bs, m->prev_bs );
    }
}
예제 #11
0
파일: ev.button.c 프로젝트: kidmeier/flo
// WARNING: This is not re-entrant; should only be called from one thread.
static int translate_button_Ev( ev_t* dest, const union SDL_Event* ev ) {

	int  which;
	bool pressed;
	switch( ev->type ) {

	case SDL_MOUSEBUTTONDOWN:
	case SDL_MOUSEBUTTONUP: {
		const SDL_MouseButtonEvent* button = &ev->button;

		which = buttonsets[0].base + ev->button.button;
		pressed = SDL_PRESSED == button->state;
		break;
	}

	case SDL_JOYBUTTONDOWN:
	case SDL_JOYBUTTONUP: {
		const SDL_JoyButtonEvent* button = &ev->jbutton;
		struct buttonset_s* buttonset = &buttonsets[ 1+button->which ];
		
		which = buttonset->base + button->button;
		pressed = SDL_PRESSED == button->state;
		break;
	}
	default:
		fatal("Bad button event: 0x%x", ev->type);
		return -1;
	}

	// Update our local state
	if( pressed )
		bitset_set( button_state, which );
	else
		bitset_clear( button_state, which );

	// Copy into dest event
	dest->button.which = which;
	dest->button.pressed = pressed;
	bitset_copy( dest->button.state, maxButtonCount, button_state );

	return 0;

}
예제 #12
0
파일: index.c 프로젝트: bigbes/tarantool
int
bitset_index_insert(struct bitset_index *index, const void *key,
		    size_t key_size, size_t value)
{
	assert(index != NULL);
	assert(key != NULL);
	assert(index->capacity > 0);

	/*
	 * Step 0: allocate enough number of bitsets
	 *
	 * bitset_index_reserve could fail on realloc and return -1.
	 * Do not change anything and return the error to the caller.
	 */
	const size_t size = 1 + key_size * CHAR_BIT;
	if (bitset_index_reserve(index, size) != 0)
		return -1;

	/*
	 * Step 1: set the 'flag' bitset
	 *
	 * bitset_set for 'falg' bitset could fail on realloc.
	 * Do not change anything. Do not shrink buffers allocated on step 1.
	 */
	int rc = bitset_set(index->bitsets[0], value);
	if (rc < 0)
		return -1;

	/* if 1 then the value is new in the index */
	index->rollback_buf[0] = (char) rc;

	/*
	 * Step 2: iterate over 'set' bits in the key and update related bitsets.
	 *
	 * A bitset_set somewhere in the middle also could fail on realloc.
	 * If this happens, we stop processing and jump to the rollback code.
	 * Rollback uses index->rollback_buf buffer to restore previous values
	 * of all bitsets on given position. Remember, that bitset_set
	 * returns 1 if a previous value was 'true' and 0 if it was 'false'.
	 * The buffer is indexed by bytes (char *) instead of bits (bit_set)
	 * because it is a little bit faster here.
	 */
	struct bit_iterator bit_it;
	bit_iterator_init(&bit_it, key, key_size, true);
	size_t pos = 0;
	while ((pos = bit_iterator_next(&bit_it)) != SIZE_MAX) {
		size_t b = pos + 1;
		rc = bitset_set(index->bitsets[b], value);
		if (rc < 0)
			goto rollback;

		index->rollback_buf[b] = (char) rc;
	}

	/* Finish here if the value is new in the index */
	if (index->rollback_buf[0] == 0)
		return 0;

	/*
	 * Step 3: Iterate over 'unset' bits and cleanup other bitsets
	 * This step is needed if the value was already existed in the index.
	 * Nothing can fail here because current implementation of
	 * bitset_clear never fails.
	 */
	bit_iterator_init(&bit_it, key, key_size, false);
	while ((pos = bit_iterator_next(&bit_it)) != SIZE_MAX) {
		size_t b = pos + 1;
		rc = bitset_clear(index->bitsets[b], value);
		assert(rc >= 0); /* bitset_clear never fails */
	}

	return 0;

rollback:
	/*
	 * Rollback changes done by Step 2.
	 */
	bit_iterator_init(&bit_it, key, size, true);
	size_t rpos;
	while ((rpos = bit_iterator_next(&bit_it)) != SIZE_MAX && rpos < pos) {
		size_t b = rpos + 1;

		if (index->rollback_buf[b] == 1) {
			bitset_set(index->bitsets[b], value);
		} else {
			bitset_clear(index->bitsets[b], value);
		}
	}

	/*
	 * Rollback changes done by Step 1.
	 */
	if (index->rollback_buf[0] == 1) {
		bitset_set(index->bitsets[0], value);
	} else {
		bitset_clear(index->bitsets[0], value);
	}

	return -1;
}
예제 #13
0
void set_not_backedge(ir_node *n, int pos)
{
	bitset_t *ba = get_backarray(n);
	assert(ba && "can only set backedges at Phi, Block nodes.");
	bitset_clear(ba, pos);
}
예제 #14
0
/**
 * \brief Map old channels/profiles to new channels/profiles
 *
 * Mapping is trying to find the same channels/profiles in an old and a new
 * configuration based on their names and hierarchy position in a profile tree.
 * These channels/profiles should stay in an Event manager without
 * reinitialization. However, configuration of channels/profiles can be
 * changes e.g. new storage directory, different type (normal/shadow), etc.
 * Therefore, change flags are genereted for each successful mapping.
 *
 * After execution of this function: Set bits in old bitsets (mgr->channel and
 * mgr->profiles) represent successfully mapped OLD channels/profiles. Set
 * bits in new bitsets (update->channel and update->profiles) represent
 * successfully mapped NEW channels/profiles and corresponding change flags
 * (update->chnl_flags and update->prfl_flags) are filled (an index in
 * the "new" bitset is equal to the index in corresponding flag array).
 * Pointers to local user data of each successfully mapped channel/profile
 * are copied to new channels/profiles (update->channels and profiles).
 *
 * Thus, unset bits in the old bitsets represent channels/profiles to delete.
 * Unset bits in the new bitsets represent channels/profiles to create.
 * Non-zero flags in the flags array represent channels/profiles to update.
 *
 * \note The function expects that an update structure is already initialized
 *   and a profile tree has been parsed.
 * \param[in,out] mgr    Event manager
 * \param[in,out] update Update structure
 */
static void
pevents_update_mapper(pevents_t *mgr, struct pevents_update *update)
{
	/* Try to map new channels to the new profiles.
	 * Each profile must have at least one channel, so we just need to remap
	 * new channels to old channels and simultaneously remap also their
	 * profiles.
	 *
	 * Note:
	 * - mgr->channels and mgr->profiles represents old channels/profiles
	 * - update->channels and update->profiles represents new channels/profiles
	 */

	if (update->channels.all_size == 0) {
		// Nothing for mapping -> skip
		return;
	}

	// Old/new bitset represents successfully mapped old/new channels/profiles
	bitset_clear(mgr->channels.bitset);
	bitset_clear(mgr->profiles.bitset);

	bitset_clear(update->channels.bitset);
	bitset_clear(update->profiles.bitset);

	struct pevents_item *item_chnl_new;
	struct pevents_item *item_chnl_old;

	const size_t new_chnl_cnt = update->channels.all_size;
	for (size_t i = 0; i < new_chnl_cnt; ++i) {
		// Get one of the new channels
		item_chnl_new = group_item_at(&update->channels, i);
		void *ch_new = item_chnl_new->ctx.ptr.channel;

		// Find corresponding old channel
		item_chnl_old = pevents_update_mapper_find_old_channel(mgr, ch_new);
		if (!item_chnl_old) {
			// Failed to find the old channel
			continue;
		}

		// Get flags of changes
		void *ch_old = item_chnl_old->ctx.ptr.channel;
		uint16_t flags = pevents_update_mapper_change_flags(ch_old, ch_new);

		// Indicate successful channel mapping and move local/global data
		bitset_set_fast(mgr->channels.bitset, item_chnl_old->idx, true);
		bitset_set_fast(update->channels.bitset, item_chnl_new->idx, true);
		item_chnl_new->ctx.user.local = item_chnl_old->ctx.user.local;
		update->chnl_flags[i] = flags;

		// Check if the profile has been mapped
		struct pevents_item *item_prfl_new = item_chnl_new->parent_ptr;
		struct pevents_item *item_prfl_old = item_chnl_old->parent_ptr;

		if (bitset_get_fast(update->profiles.bitset, item_prfl_new->idx)) {
			// Already mapped -> skip
			continue;
		}

		// Indicate successful profile mapping and move local/global data
		bitset_set_fast(mgr->profiles.bitset, item_prfl_old->idx, true);
		bitset_set_fast(update->profiles.bitset, item_prfl_new->idx, true);
		item_prfl_new->ctx.user.local = item_prfl_old->ctx.user.local;
		update->prfl_flags[item_prfl_new->idx] = flags;
	}
}
예제 #15
0
파일: test-bitset.c 프로젝트: Meijuh/ltsmin
static void setclear(){
	int i;
	bitset_t set=bitset_create(16,16);

    printf("setting 5 and 60\n");
	bitset_set(set,5);
	bitset_set(set,60);
	for(i=0;i<80;i++) printf("%s",bitset_test(set,i)?"1":"0");
	printf("\n");
	
	int N=10;
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("set %d\n",N);
    bitset_set(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("clear %d\n",N);
	bitset_clear(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));

	N=100;
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("set %d\n",N);
	bitset_set(set,N);
	printf("%d in set is %d\n",10,bitset_test(set,10));
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("clear %d\n",N);
	bitset_clear(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));

	N=200;
	printf("%d in set is %d\n",N,bitset_test(set,N));
	bitset_fprint(stdout,set);
	printf("set %d\n",N);
	bitset_set(set,N);
	bitset_fprint(stdout,set);
	printf("%d in set is %d\n",10,bitset_test(set,10));
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("clear %d\n",N);
	bitset_clear(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));
	bitset_fprint(stdout,set);
	printf("\n");

	N=1000000;
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("set %d\n",N);
	bitset_set(set,N);
	printf("%d in set is %d\n",10,bitset_test(set,10));
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("clear %d\n",N);
	bitset_clear(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));

	N=10000;
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("set %d\n",N);
	bitset_set(set,N);
	printf("%d in set is %d\n",10,bitset_test(set,10));
	printf("%d in set is %d\n",N,bitset_test(set,N));
	printf("clear %d\n",N);
	bitset_clear(set,N);
	printf("%d in set is %d\n",N,bitset_test(set,N));

    printf("setting 5 and 60\n");
	bitset_set(set,5);
	bitset_set(set,60);
	for(i=0;i<80;i++) printf("%s",bitset_test(set,i)?"1":"0");
	printf("\n");
	
	
	N=1222333;
	printf("set %d\n",N);
	bitset_set(set,N);
	
	printf("set:{");
	for(element_t e=0;bitset_next_set(set,&e);e++){
	    printf(" %u",e);
	}
	printf(" }\n");
	
	bitset_destroy(set);
}
예제 #16
0
void bipartite_remv(bipartite_t *const gr, unsigned const i, unsigned const j)
{
	assert(i < gr->n_left && j < gr->n_right);
	bitset_clear(gr->adj[i], j);
}
예제 #17
0
static
void test_get_set()
{
	header();

	struct bitset bm;
	bitset_create(&bm, realloc);

	const size_t NUM_SIZE = (size_t) 1 << 14;
	size_t *nums = malloc(NUM_SIZE * sizeof(size_t));

	printf("Generating test set... ");
	for(size_t i = 0; i < NUM_SIZE; i++) {
		nums[i] = rand();
	}
	printf("ok\n");

	printf("Settings bits... ");
	for(size_t i = 0; i < NUM_SIZE; i++) {
		fail_if(bitset_set(&bm, nums[i]) < 0);
	}
	printf("ok\n");

	printf("Checking bits... ");
	shuffle(nums, NUM_SIZE);
	for(size_t i = 0; i < NUM_SIZE; i++) {
		fail_unless(bitset_test(&bm, nums[i]));
	}
	printf("ok\n");

	printf("Unsetting random bits... ");
	shuffle(nums, NUM_SIZE);
	for(size_t i = 0; i < NUM_SIZE; i++) {
		if (nums[i] % 5 == 0) {
			fail_if(bitset_clear(&bm, nums[i]) < 0);
			// printf("Clear :%zu\n", nums[i]);
			fail_if(bitset_test(&bm, nums[i]));
		}
	}
	printf("ok\n");

	printf("Checking set bits... ");
	shuffle(nums, NUM_SIZE);
	for(size_t i = 0; i < NUM_SIZE; i++) {
		if (nums[i] % 5 == 0) {
			continue;
		}

		if (!bitset_test(&bm, nums[i])) {
			printf("Fail :%zu\n", nums[i]);
		}
		fail_unless(bitset_test(&bm, nums[i]));
	}
	printf("ok\n");

	printf("Checking all bits... ");
	qsort(nums, NUM_SIZE, sizeof(size_t), size_compator);

	size_t *pn = nums;

	size_t i_max = (size_t) 1 << 14;
	if (i_max > RAND_MAX) {
		i_max = RAND_MAX;
	}

	for(size_t i = 0; i < i_max; i++) {
		if (*pn < SIZE_MAX && *pn == i) {
			fail_unless(bitset_test(&bm, *pn));
			pn++;
		} else {
			fail_if(bitset_test(&bm, i));
		}
	}
	printf("ok\n");


	printf("Unsetting all bits... ");
	shuffle(nums, NUM_SIZE);
	for(size_t i = 0; i < NUM_SIZE; i++) {
		if (nums[i] == SIZE_MAX) {
			continue;
		}

		fail_if(bitset_clear(&bm, nums[i]) < 0);
	}
	printf("ok\n");


	printf("Checking all bits... ");
	for(size_t i = 0; i < i_max; i++) {
		fail_if(bitset_test(&bm, i));
	}
	printf("ok\n");

	free(nums);

	bitset_destroy(&bm);

	footer();
}