I am trying to implement a queue in xv6. In proc.c ,I have a structure named
struct pqueue_n
{
struct proc *head;
struct proc *tail;
int lenght;
};
I have also create an array of structure
struct pqueue_n queue[MAX_LL];
The initialization I have looks like this
struct pqueue_n* queue = {0,0,0};
I have written two methods as well enqueue and dequeue void enqueue_n(void)
{
struct proc *p = myproc();
struct pqueue_n* pq;
if(p->priority < MAX_PRIORITY || p->priority> MIN_PRIORITY)
{
return;
}
if (pq->tail == ((void *)0))
{
return;
}
if (pq->head == ((void *)0))
{
p->next = pq->head;
pq->head = p;
pq->tail = p;
}
else if(pq->head != ((void*)0))
{
if(pq->head->priority == p->priority)
{
p->next = pq->head;
pq->head = p;
}
}
pq->lenght++;
}
void dequeue_n(void)
{
struct proc *p;
struct pqueue_n* pq;
{
if(pq->head == ((void *)0))
{
return ;
}
p = pq->head;
pq->head = pq->head->next ;
p->next = 0;
}
}
I am trying to initialize the structure as a globe structure.so that I can used the structure in my methods. Whenever I compile. I receive this error "excess elements in scalar initializer" and "‘pq’ is used uninitialized in this function ".