Select

From: pramodh mallipatna (pramodh@ittc.ukans.edu)
Date: Tue Jul 11 2000 - 11:41:16 EST


Hi,

Sorry for sending this mail again. By mistake, the subject of my previous
mail was "Re: Select". So, I thought I did not get any reply.

I have a device driver and I want to use select() on my driver in the user
code, for waiting on some events in the driver. The select call blocks for
ever (even when there are events in the driver). However, it works for a
particular scenario. I have explained it below.
 
I have given the code below.

It works for the following scenario
-----------------------------------
If I just issue an ioctl in the user code when the select is blocking
(using timer_handler()), the select succeeds (but with EINTR). The
select() call succeeds even without wake_up() being called in the ioctl.
 
It doesn't work for the following scenario
------------------------------------------
Without the timer_handler(), if I do a wake_up() within the kernel, in the
event_handler(), select() never succeeds. I want the select() to succeed
on an event reported in the event_handler().
 
Could you tell me what am I missing in my implementation.
 
Your response is highly appreciated.
 
Thanks,
Pramodh
 
 my_driver.c
 -----------
 
 static unsigned int my_driver_poll(struct file *file, struct
                                   poll_table_struct *wait)
 {
        poll_wait(file, &my_sleep, wait);
        
        if (an event occured)
                return POLLRDNORM;
        else
                return 0;
 }
 
 my_event_handler()
 {
        /* an event occured */
        wake_up(&my_sleep);
 }
 
 my_driver_ioctl(....)
 {
        case WAKE_UP_POLLFUNCTION:
                wake_up(&my_sleep);
 }
 
 my_usercode.c
 -------------
 int fd, fds;
 fd_set set;
 
 void timer_handler()
 {
        rval=ioctl(fd, WAKE_UP_POLLFUNCTION, arg);
 }
 
 main()
 {
        signal(SIGALRM, timer_handler);
        setitimer(ITIMER_REAL, &timerval, (struct itimerval *)NULL);
 
        fd = open("/dev/my_driver", 0);
 
        FD_ZERO(&set);
        FD_SET(fd, &set);
        fds = fd+1;
 
        while(1) {
                rval = select(fds, &set, NULL, NULL, NULL);
                if (errno != EINTR)
                        break;
                ......
        }
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:13 EST