Code: Select all
struct sleep_event_struct {
unsigned long sleeping_pid;
char thread_event_flags; //Defines actions
char thread_event_state; //Current state
char event_type;
void *arg;
struct sleep_event_struct *next,*prev;
};
volatile struct sleep_event_struct *head_sev,*temp_sev;
void _idle()
{
struct sleep_event_struct *x,*y;
while(1) {
for(x=head_sev;x;x=x->next) { //Not entered!!
switch(x->event_type) {
case EVENT_IRQ: if(got_irq(x->arg)) {
wake_thread(x->sleeping_pid);
}
break;
}
}
for(x=head_sev;x;x=x->next) {
if(x->thread_event_state==PESTATE_EXPIRED) {
if((x->thread_event_flags)&PEFLAG_EXPIRED_DELETE) {
(x->prev)->next=x->next;
(x->next)->prev=x->prev;
y=x->next;
free(x);
x=y;
}
}
}
asm("hlt");
}
}
Uptill this part everything goes fine. But when an IRQ goes then the process is not woken up.
When i tried to debug the code i saw that the first for loop never got executed because the value of x was already null since head_sev was read as null (i guess).
head_sev is properly updated by the main thread when an event sleeps (i am only adding one sleep_event_struct currently. So either head_sev is null or it has the first entry). So now idle thread should read head_sev and enter the for loop to check whether the specified event for head_sev has taken place...
But head_sev is not updated in the idle thread inspite of a volatile declaration.
So what else do i do?
My compilation options simply include gcc -c -O2