Beispiel #1
0
void
mem_event_handler_rc(mem_state * s, tw_bf * bf, mem_message * m, tw_lp * lp)
{
    tw_memory	*b;

    int		 i;

    s->stats.s_rb++;
    s->stats.s_recv--;

    tw_rand_reverse_unif(lp->rng);
    tw_rand_reverse_unif(lp->rng);

    if(bf->c1 == 1)
        tw_rand_reverse_unif(lp->rng);

    // undo the membuf frees and reattach them to the RB event
    for(i = 0; i < nbufs; i++)
    {
        b = tw_memory_free_rc(lp, my_fd);
        s->stats.s_mem_free_rc++;
        tw_event_memory_get_rc(lp, b, my_fd);
        s->stats.s_mem_get_rc++;

        /*
         * unnecessary to undo the allocs ..
         * they will be reclaimed when the events are reclaimed.
         */
    }

    // sanity check
    if(i != nbufs)
        tw_error(TW_LOC, "Did not free_rc %d (%d) memory buffers!",
                 nbufs, i);
}
Beispiel #2
0
void
rm_rc_particle_handler(rm_state * state, tw_bf * bf, rm_message * m, tw_lp * lp)
{
	//tw_memory	*b;
	//tw_memory	*b_in;

	//state->prev_time = tw_now(lp);

#if DWB
	if(bf->c0 == 1)
	{
		state->initial = tw_memory_free_rc(lp, g_rm_fd);
		tw_event_memory_get_rc(lp, tw_memory_free_rc(lp, g_rm_fd), g_rm_fd);
	} else
	{
		tw_event_memory_get_rc(lp, state->initial, g_rm_fd);
		state->initial = NULL;

		if(bf->c1 == 1)
			state->initial = tw_memory_free_rc(lp, g_rm_fd);
	}
#endif

#if 0
	// remove this particle to the queue
	b_in = tw_memoryq_pop(state->particles);

	// place particle back onto event
	//tw_event_memory_get_rc(lp, b_in, g_rm_fd);

	// if in next timestep, dump the particle queue and add this particle
	if(bf->c0 == 1)
	{
		state->prev_time = tw_now(lp);

		// unfree particles and place back into queue
		while((NULL != (b = tw_memory_free_rc(lp, g_rm_fd))))
			tw_memoryq_push(state->particles, b);
	}
#endif
}
Beispiel #3
0
void
r_msg_update(bgp_state * state, tw_bf * bf, bgp_message * msg, tw_lp * lp)
{
	int             i;

	if (bf->c6)
	{
		for (i = 0; i < msg->rev_num_neighbors; i++)
		{
			tw_rand_reverse_unif(lp->id);
		}
	}

	if (bf->c1)
	{							// reverse add
		tw_memory      *as_path;

		if (bf->c2)
		{
			if (bf->c3)
			{
				tw_memoryq_delete_any(&state->routes, msg->this_route);
				// state->routes.remove(msg->this_bgp_route);
				// state->routes.pop_back(); // makes it non-deterministic
				if (bf->c4)
				{
					tw_memory      *jim = tw_memory_free_rc(lp, g_bgp_fd_rtes);
					bgp_route      *rjim = tw_memory_data(jim);;
					tw_memoryq_push(&state->routes, jim);
					// state->bgp_routes.push_back(msg->erased_route);
					bzero(&rjim->as_path, sizeof(rjim->as_path));

					while (msg->rc_asp)
					{
						tw_memoryq_push(&rjim->as_path,
										tw_memory_free_rc(lp, g_bgp_fd_asp));
						msg->rc_asp--;
					}
				}
			}
		}
		while ((as_path =
				tw_memoryq_pop(&((bgp_route *) msg->this_route->data)->
							   as_path)))
			tw_event_memory_get_rc(lp, as_path, g_bgp_fd_asp);

		state->stats->s_nupdateadds--;
	} else
	{							// reverse remove
		if (bf->c5)
		{
			int             i = msg->rc_asp;
			tw_memory      *it4;
			bgp_route      *r;

			msg->this_route = tw_memory_free_rc(lp, g_bgp_fd_rtes);

			while (i)
			{
				tw_event_memory_get_rc(lp, tw_memory_free_rc(lp, g_bgp_fd_asp),
									   g_bgp_fd_asp);
				i--;
			}

			it4 = tw_memory_free_rc(lp, g_bgp_fd_rtes);
			r = tw_memory_data(it4);

			bzero(&r->as_path, sizeof(r->as_path));
			while (msg->rc_asp)
			{
				tw_memoryq_push(&r->as_path,
								tw_memory_free_rc(lp, g_bgp_fd_asp));
				msg->rc_asp--;
			}

			tw_memoryq_push(&state->routes, it4);

			// state->bgp_routes.push_back(msg->erased_bgp_route);
		}

		state->stats->s_nupdateremoves--;
	}

	tw_event_memory_get_rc(lp, msg->this_route, g_bgp_fd_rtes);

	msg->this_route = NULL;
}