Beispiel #1
0
void merge(int *p, int low, int middle, int high)
{
	int i;
	queue_t *q1 = &queue1;
	queue_t *q2 = &queue2;

	queue_init(q1);
	queue_init(q2);

	for (i = low; i <= middle; i++)
		en_queue(q1, p[i]);

	for (i = middle + 1; i <= high; i++)
		en_queue(q2, p[i]);

	i = low;
	while (!(empty_queue(q1) || empty_queue(q2))) {
		if (head_queue(q1) > head_queue(q2))
			p[low++] = de_queue(q1);
		else
			p[low++] = de_queue(q2);
	}

	while (!(empty_queue(q1)))
		p[low++] = de_queue(q1);
	while (!(empty_queue(q2)))
		p[low++] = de_queue(q2);
}
Beispiel #2
0
static void merge(int s[], int low, int middle, int high) {
    int i;
    queue buffer1, buffer2; /* buffers to hold elements for merging*/

    init_queue(&buffer1);
    init_queue(&buffer2);

    for (i = low; i <= middle; i++)
        en_queue(&buffer1, &s[i], sizeof (int));

    for (i = middle + 1; i <= high; i++)
        en_queue(&buffer2, &s[i], sizeof (int));

    i = low;

    while (!(empty_queue(&buffer1) || empty_queue(&buffer2))) {

        if (*(int*) head_queue(&buffer1) <= *(int*) head_queue(&buffer2))
            s[i++] = deq_buffer(&buffer1);

        else
            s[i++] = deq_buffer(&buffer2);
    }

    while (!empty_queue(&buffer1))
        s[i++] = deq_buffer(&buffer1);

    while (!empty_queue(&buffer2))
        s[i++] = deq_buffer(&buffer2);

    clear_queue(&buffer1);
    clear_queue(&buffer2);
}
Beispiel #3
0
/**
* Select the port containing the first injected packet.
*
* Given a range of input-injection ports, select the one with the oldest packet,
* measured since it was injected.
* 
* @param i The node in which the arbitration is performed.
* @param d_p The destination port for wich the arbitration is performed.
* @param first The first port for looking to.
* @param last The next port from the last to looking to. This port is not included.
* @return The selected port, or NULL_PORT if there isnt anyone.
* @see arbitrate
*/
port_type arbitrate_select_age(long i, port_type d_p, port_type first, port_type last) {
	port_type s_p, selected_port;
	CLOCK_TYPE time_of_selected, min;
	phit *p;

	time_of_selected = CLOCK_MAX;

	for (s_p=first; s_p<last; s_p++) {
		if (!network[i].p[d_p].req[s_p])
			continue;
		p = head_queue(&network[i].p[s_p].q);
		min = pkt_space[p->packet].inj_time;
		if (min < time_of_selected) {
			time_of_selected = min;
			selected_port = s_p;
		}
	}
	if (time_of_selected != CLOCK_MAX) 
		return (selected_port);
	else 
		return (NULL_PORT);
}