Changeset 0a6fb22 in rtems for cpukit/score/cpu/unix/cpu.c


Ignore:
Timestamp:
Apr 22, 1997, 8:19:25 PM (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
7346e5f
Parents:
e0de6ef
Message:

Patch from Chris John <cjohns@…> to add use of a select statement
in the unix port idle thread task. This should keep the entire application
from blocking when any component does a blocking application. Also added
TOD_MICROSECONDS_TO_TICKS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/cpu/unix/cpu.c

    re0de6ef r0a6fb22  
    6262static Context_Control_overlay
    6363          _CPU_Context_Default_with_ISRs_disabled CPU_STRUCTURE_ALIGNMENT;
     64
     65/*
     66 * Sync IO support, an entry for each fd that can be set
     67 */
     68
     69void  _CPU_Sync_io_Init();
     70
     71static rtems_sync_io_handler _CPU_Sync_io_handlers[FD_SETSIZE];
     72static int sync_io_nfds;
     73static fd_set sync_io_readfds;
     74static fd_set sync_io_writefds;
     75static fd_set sync_io_exceptfds;
    6476
    6577/*
     
    217229/*PAGE
    218230 *
     231 *  _CPU_Sync_io_Init
     232 */
     233
     234void _CPU_Sync_io_Init()
     235{
     236  int fd;
     237
     238  for (fd = 0; fd < FD_SETSIZE; fd++)
     239    _CPU_Sync_io_handlers[fd] = NULL;
     240
     241  sync_io_nfds = 0;
     242  FD_ZERO(&sync_io_readfds);
     243  FD_ZERO(&sync_io_writefds);
     244  FD_ZERO(&sync_io_exceptfds);
     245}
     246
     247/*PAGE
     248 *
    219249 *  _CPU_ISR_Get_level
    220250 */
     
    273303  _CPU_ISR_From_CPU_Init();
    274304
     305  _CPU_Sync_io_Init();
     306
    275307  _CPU_Context_From_CPU_Init();
    276308
     
    351383void _CPU_Thread_Idle_body( void )
    352384{
     385#if CPU_SYNC_IO
     386  extern void _Thread_Dispatch(void);
     387  int fd;
     388#endif
     389
    353390  while (1) {
    354391#ifdef RTEMS_DEBUG
     
    357394       abort();
    358395#endif
     396
     397    /*
     398     *  Block on a select statement, the CPU interface added allow the
     399     *  user to add new descriptors which are to be blocked on
     400     */
     401
     402#if CPU_SYNC_IO
     403    if (sync_io_nfds) {
     404      int result;
     405
     406      result = select(sync_io_nfds,
     407                 &sync_io_readfds,
     408                 &sync_io_writefds,
     409                 &sync_io_exceptfds,
     410                 NULL);
     411
     412      if ((result < 0) && (errno != EINTR))
     413        _CPU_Fatal_error(0x200);       /* FIXME : what number should go here !! */
     414
     415      for (fd = 0; fd < sync_io_nfds; fd++) {
     416        boolean read = FD_ISSET(fd, &sync_io_readfds);
     417        boolean write = FD_ISSET(fd, &sync_io_writefds);
     418        boolean except = FD_ISSET(fd, &sync_io_exceptfds);
     419
     420        if (_CPU_Sync_io_handlers[fd] && (read || write || except))
     421          _CPU_Sync_io_handlers[fd](fd, read, write, except);
     422
     423        _Thread_Dispatch();
     424      }
     425    } else
     426      pause();
     427#else
    359428    pause();
     429#endif
     430
    360431  }
    361432
     
    757828 */
    758829
     830int _CPU_Set_sync_io_handler(
     831  int fd,
     832  boolean read,
     833  boolean write,
     834  boolean except,
     835  rtems_sync_io_handler handler
     836)
     837{
     838  if ((fd < FD_SETSIZE) && (_CPU_Sync_io_handlers[fd] == NULL)) {
     839    if (read)
     840      FD_SET(fd, &sync_io_readfds);
     841    else
     842      FD_CLR(fd, &sync_io_readfds);
     843    if (write)
     844      FD_SET(fd, &sync_io_writefds);
     845    else
     846      FD_CLR(fd, &sync_io_writefds);
     847    if (except)
     848      FD_SET(fd, &sync_io_exceptfds);
     849    else
     850      FD_CLR(fd, &sync_io_exceptfds);
     851    _CPU_Sync_io_handlers[fd] = handler;
     852    if ((fd + 1) > sync_io_nfds)
     853      sync_io_nfds = fd + 1;
     854    return 0;
     855  }
     856  return -1;
     857}
     858
     859int _CPU_Clear_sync_io_handler(
     860  int fd
     861)
     862{
     863  if ((fd < FD_SETSIZE) && _CPU_Sync_io_handlers[fd]) {
     864    FD_CLR(fd, &sync_io_readfds);
     865    FD_CLR(fd, &sync_io_writefds);
     866    FD_CLR(fd, &sync_io_exceptfds);
     867    _CPU_Sync_io_handlers[fd] = NULL;
     868    sync_io_nfds = 0;
     869    for (fd = 0; fd < FD_SETSIZE; fd++)
     870      if (FD_ISSET(fd, &sync_io_readfds) ||
     871          FD_ISSET(fd, &sync_io_writefds) ||
     872          FD_ISSET(fd, &sync_io_exceptfds))
     873        sync_io_nfds = fd;
     874    return 0;
     875  }
     876  return -1;
     877}
     878
    759879int _CPU_Get_clock_vector( void )
    760880{
     
    9351055)
    9361056{
    937   struct sembuf      sb;
    938   int                status;
     1057  struct sembuf sb;
    9391058
    9401059  sb.sem_num = semaphore;
     
    9431062
    9441063  while (1) {
     1064    int status = -1;
     1065
    9451066    status = semop(_CPU_SHM_Semid, &sb, 1);
    9461067    if ( status >= 0 )
Note: See TracChangeset for help on using the changeset viewer.