vqueue.c


/*************************************************************************
*                                                                        *
*   Modulo: vqueue.c                                                     *
*                                                                        *
*   realizzato dal Gruppo 17 di Lab2 Anno Accademico 1995/96             *
*                                                                        *
*   Lorenzo     Claudio       Valerio    Riccardo    Emiliano            *
*   Coronati    Lanconelli    Paolini    Solmi       Trentini            *
*                                                                        *
**************************************************************************/

#include "../h/tproc.h"
#include "../h/syscallt.h"
#include "../h/queue.e"

void
initVQueue(tproc)
tproc_t *tproc;
{
    tproc->T_vqfp = (vqueue_t *) initQueue(tproc->T_vqueue, VQUEUENO, sizeof(vqueue_t));
}

vqueue_t *
allocVQueue(tproc)
tproc_t *tproc;
{
    return (vqueue_t *) AllocQueue(&tproc->T_vqfp);
}

void
freeVQueue(tproc, p)
tproc_t *tproc;
vqueue_t *p;
{
    freeQueue(p, &tproc->T_vqfp);
}

int
foundVS(p, from, to)
vqueue_t *p;
thr_t *from, *to;
{
    return (p->vq_to == to && (p->vq_from == ANYSENDER || p->vq_from == from));
}

int
foundVR(p, from, to)
vqueue_t *p;
thr_t *from, *to;
{
    return (p->vq_to == to && (from == ANYSENDER || p->vq_from == from));
}

int
foundVP(p, from, to)
vqueue_t *p;
thr_t *from, *to;
{
    return (p->vq_to == to && p->vq_from == from);
}

vqueue_t *
keyVQueue(tp, from, to, found)
vqueue_t **tp;
thr_t *from, *to;
int (*found)(/* vqueue_t *p, thr_t *from, thr_t *to */);
{
    register vqueue_t *p;
    register vqueue_t *prevp = *tp;

    if (prevp == NULL)
        return NULL;
    else
    {
        /* Se la coda non e' vuota, scandisce alla ricerca del nodo */
        while ( (p = prevp->vq_next) != *tp && ! (*found)(p, from, to) )
            prevp = p;

        /* trovato: estraggo e restituisco il nodo */
        if ( (*found)(p, from, to) )
        {
            /* controllo se unico nodo della lista */
            if (prevp == p)
                *tp = NULL;
            else
            {
                /* controllo se si rimuove il msg di coda */
                if (p == *tp)
                    *tp = prevp;
                prevp->vq_next = p->vq_next;
            }
            return p;
        } else
            return NULL;
    }
}



[INDICE CODICE]