Esempio n. 1
0
static void list_move(struct core_timer* timer, int level, int idx)
{
	struct timer_node* r = list_clear(&timer->n[level][idx]);
	while (r) {
		struct timer_node* n = r->list_next;
		r->list_prev = NULL;
		r->list_next = NULL;
		addto_list(timer,r);
		r = n;
	}
}
Esempio n. 2
0
uint32_t coretimer_add(struct core_timer *t, timer_call call, void* ctx, uint32_t wait)
{
	struct timer_node * r = timernode_alloc(t);
	r->call = call;
	r->u = ctx;
	r->id = ++t->index;
	wait = wait / TIME_SLOT_LEN;
	wait = wait ? wait : 1;
	r->expire = t->time + wait;
	r->hash_next = NULL;
	r->hash_prev = NULL;
	r->list_next = NULL;
	r->list_prev = NULL;

	LOCK(&t->lock);
	addto_list(t, r);
	addto_hash(t->h, r);
	UNLOCK(&t->lock);

	return r->id;
}
Esempio n. 3
0
void
draw_voters(ModeInfo * mi)
{
	int         i, spineless_dude, neighbor_direction;
	int         spineless_col, spineless_row;
	int         new_opinion, old_opinion;
	cellstruct  info;
	voterstruct *vp;

	if (voters == NULL)
		return;
	vp = &voters[MI_SCREEN(mi)];
	if (vp->first == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	vp->painted = True;
	if (vp->busyLoop) {
		if (vp->busyLoop >= 5000)
			vp->busyLoop = 0;
		else
			vp->busyLoop++;
		return;
	}
	for (i = 0; i < BITMAPS; i++)
		if (vp->number_in_party[i] == vp->npositions) {		/* The End of the WORLD */
			init_voters(mi);	/* Create a more interesting planet */
		}
	spineless_dude = NRAND(vp->npositions);
	neighbor_direction = NRAND(vp->neighbors) * 360 / vp->neighbors;
	spineless_col = spineless_dude % vp->ncols;
	spineless_row = spineless_dude / vp->ncols;
	old_opinion = vp->arr[spineless_dude];
	new_opinion = neighbors_opinion(vp, spineless_col, spineless_row,
					neighbor_direction);
	if (old_opinion != new_opinion) {
		vp->number_in_party[old_opinion]--;
		vp->number_in_party[new_opinion]++;
		vp->arr[spineless_dude] = new_opinion;
		info.kind = new_opinion;
		info.age = (old_opinion - new_opinion);
		if (info.age == 2)
			info.age = -1;
		if (info.age == -2)
			info.age = 1;
		info.age *= (FACTOR * MI_NPIXELS(mi)) / 3;
		info.col = spineless_col;
		info.row = spineless_row;
		if (MI_NPIXELS(mi) > 2) {
			advanceColors(mi, spineless_col, spineless_row);
			if (!addto_list(vp, info)) {
				free_voters(vp);
				return;
			}
		}
		drawcell(mi, spineless_col, spineless_row,
			 (MI_NPIXELS(mi) + info.age / FACTOR +
		  (MI_NPIXELS(mi) * new_opinion / BITMAPS)) % MI_NPIXELS(mi),
			 new_opinion, True);
	} else if (MI_NPIXELS(mi) > 2)
		advanceColors(mi, -1, -1);
	vp->generation++;
	for (i = 0; i < BITMAPS; i++)
		if (vp->number_in_party[i] == vp->npositions) {		/* The End of the WORLD */
			vp->busyLoop = 1;
			refresh_voters(mi);
		}
}