Changeset b4e3b2b in rtems


Ignore:
Timestamp:
10/28/98 19:25:12 (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
22fa5832
Parents:
692b9f7
Message:

Patch from Ian Lance Taylor <ian@…>.

I just happened across the sync_io support in

c/src/exec/score/cpu/unix/cpu.c

(is this documented anywhere?). That looked more useful than the
signal driven I/O I was using before, so I tried it. I ran across a
few bugs in the way it uses select.

Select changes its fd_set arguments, so you can't use global variables
for them. You have to copy them into local variables first.

If select returns -1 with errno set to EINTR, then it has not changed
any of the fd_sets. You can't start looking at them.

When clearing a descriptor, the code has the usual select off by one
error when setting sync_io_nfds.

I don't see how this code could ever have worked correctly.

I have appended a patch for the problems I found.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/cpu/unix/cpu.c

    r692b9f7 rb4e3b2b  
    401401    if (sync_io_nfds) {
    402402      int result;
    403 
     403      fd_set readfds, writefds, exceptfds;
     404
     405      readfds = sync_io_readfds;
     406      writefds = sync_io_writefds;
     407      exceptfds = sync_io_exceptfds;
    404408      result = select(sync_io_nfds,
    405                  &sync_io_readfds,
    406                  &sync_io_writefds,
    407                  &sync_io_exceptfds,
     409                 &readfds,
     410                 &writefds,
     411                 &exceptfds,
    408412                 NULL);
    409413
    410       if ((result < 0) && (errno != EINTR))
    411         _CPU_Fatal_error(0x200);       /* FIXME : what number should go here !! */
     414      if (result < 0) {
     415        if (errno != EINTR)
     416          _CPU_Fatal_error(0x200);       /* FIXME : what number should go here !! */
     417        _Thread_Dispatch();
     418        continue;
     419      }
    412420
    413421      for (fd = 0; fd < sync_io_nfds; fd++) {
    414         boolean read = FD_ISSET(fd, &sync_io_readfds);
    415         boolean write = FD_ISSET(fd, &sync_io_writefds);
    416         boolean except = FD_ISSET(fd, &sync_io_exceptfds);
     422        boolean read = FD_ISSET(fd, &readfds);
     423        boolean write = FD_ISSET(fd, &writefds);
     424        boolean except = FD_ISSET(fd, &exceptfds);
    417425
    418426        if (_CPU_Sync_io_handlers[fd] && (read || write || except))
    419427          _CPU_Sync_io_handlers[fd](fd, read, write, except);
    420 
    421         _Thread_Dispatch();
    422428      }
     429
     430      _Thread_Dispatch();
    423431    } else
    424432      pause();
     
    870878          FD_ISSET(fd, &sync_io_writefds) ||
    871879          FD_ISSET(fd, &sync_io_exceptfds))
    872         sync_io_nfds = fd;
     880        sync_io_nfds = fd + 1;
    873881    return 0;
    874882  }
  • cpukit/score/cpu/unix/cpu.c

    r692b9f7 rb4e3b2b  
    401401    if (sync_io_nfds) {
    402402      int result;
    403 
     403      fd_set readfds, writefds, exceptfds;
     404
     405      readfds = sync_io_readfds;
     406      writefds = sync_io_writefds;
     407      exceptfds = sync_io_exceptfds;
    404408      result = select(sync_io_nfds,
    405                  &sync_io_readfds,
    406                  &sync_io_writefds,
    407                  &sync_io_exceptfds,
     409                 &readfds,
     410                 &writefds,
     411                 &exceptfds,
    408412                 NULL);
    409413
    410       if ((result < 0) && (errno != EINTR))
    411         _CPU_Fatal_error(0x200);       /* FIXME : what number should go here !! */
     414      if (result < 0) {
     415        if (errno != EINTR)
     416          _CPU_Fatal_error(0x200);       /* FIXME : what number should go here !! */
     417        _Thread_Dispatch();
     418        continue;
     419      }
    412420
    413421      for (fd = 0; fd < sync_io_nfds; fd++) {
    414         boolean read = FD_ISSET(fd, &sync_io_readfds);
    415         boolean write = FD_ISSET(fd, &sync_io_writefds);
    416         boolean except = FD_ISSET(fd, &sync_io_exceptfds);
     422        boolean read = FD_ISSET(fd, &readfds);
     423        boolean write = FD_ISSET(fd, &writefds);
     424        boolean except = FD_ISSET(fd, &exceptfds);
    417425
    418426        if (_CPU_Sync_io_handlers[fd] && (read || write || except))
    419427          _CPU_Sync_io_handlers[fd](fd, read, write, except);
    420 
    421         _Thread_Dispatch();
    422428      }
     429
     430      _Thread_Dispatch();
    423431    } else
    424432      pause();
     
    870878          FD_ISSET(fd, &sync_io_writefds) ||
    871879          FD_ISSET(fd, &sync_io_exceptfds))
    872         sync_io_nfds = fd;
     880        sync_io_nfds = fd + 1;
    873881    return 0;
    874882  }
Note: See TracChangeset for help on using the changeset viewer.