Changeset 1f16a9f in rtems


Ignore:
Timestamp:
Apr 12, 2012, 3:15:53 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Children:
52cf1358
Parents:
d189646
git-author:
Sebastian Huber <sebastian.huber@…> (04/12/12 15:15:53)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/12/12 15:17:56)
Message:

Filesystem: Add select() support for pipes

Location:
cpukit/libfs/src/pipe
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/pipe/fifo.c

    rd189646 r1f16a9f  
    6969#include <rtems/score/thread.h>
    7070
     71static void pipe_select_wakeup(rtems_id *id_ptr)
     72{
     73  rtems_id id = *id_ptr;
     74
     75  *id_ptr = 0;
     76
     77  if (id != 0) {
     78    rtems_status_code sc = rtems_event_send(id, RTEMS_IOCTL_SELECT_EVENT);
     79
     80    if (sc != RTEMS_SUCCESSFUL) {
     81      rtems_fatal_error_occurred(sc);
     82    }
     83  }
     84}
     85
    7186/* Set barriers to be interruptible by signals. */
    7287static void pipe_interruptible(pipe_control_t *pipe)
     
    95110  int err = -ENOMEM;
    96111
    97   pipe = malloc(sizeof(pipe_control_t));
     112  pipe = calloc(1, sizeof(pipe_control_t));
    98113  if (pipe == NULL)
    99114    return err;
    100   memset(pipe, 0, sizeof(pipe_control_t));
    101115
    102116  pipe->Size = PIPE_BUF;
     
    448462      pipe->Start = 0;
    449463
     464    pipe_select_wakeup(&pipe->select_write_task_id);
    450465    if (pipe->waitingWriters > 0)
    451466      PIPE_WAKEUPWRITERS(pipe);
     
    526541
    527542    pipe->Length += chunk;
     543    pipe_select_wakeup(&pipe->select_read_task_id);
    528544    if (pipe->waitingReaders > 0)
    529545      PIPE_WAKEUPREADERS(pipe);
     
    548564}
    549565
     566static int pipe_register_select_wakeup(
     567  rtems_id *id_ptr,
     568  const rtems_ioctl_select_request *request
     569)
     570{
     571  int rv = 0;
     572  rtems_id current_id = *id_ptr;
     573  rtems_id request_id = request->request_task_id;
     574
     575  if (current_id == 0 || current_id == request_id) {
     576    *id_ptr = request_id;
     577  } else {
     578    rv = -EINVAL;
     579  }
     580
     581  return rv;
     582}
     583
     584static int pipe_select(
     585  pipe_control_t *pipe,
     586  const rtems_ioctl_select_request *request
     587)
     588{
     589  int rv = 0;
     590
     591  switch (request->kind) {
     592    case RTEMS_IOCTL_SELECT_READ:
     593      if (!PIPE_EMPTY(pipe)) {
     594        rv = 1;
     595      } else {
     596        rv = pipe_register_select_wakeup(&pipe->select_read_task_id, request);
     597      }
     598      break;
     599    case RTEMS_IOCTL_SELECT_WRITE:
     600      if (PIPE_SPACE(pipe) > 0) {
     601        rv = 1;
     602      } else {
     603        rv = pipe_register_select_wakeup(&pipe->select_write_task_id, request);
     604      }
     605      break;
     606    default:
     607      break;
     608  }
     609
     610  return rv;
     611}
     612
    550613/*
    551614 * Interface to file system ioctl.
     
    558621)
    559622{
    560   if (cmd == FIONREAD) {
    561     if (buffer == NULL)
    562       return -EFAULT;
    563 
    564     if (! PIPE_LOCK(pipe))
    565       return -EINTR;
    566 
    567     /* Return length of pipe */
    568     *(unsigned int *)buffer = pipe->Length;
    569     PIPE_UNLOCK(pipe);
    570     return 0;
    571   }
    572 
    573   return -EINVAL;
     623  int rv = 0;
     624
     625  if (buffer != NULL) {
     626    if (PIPE_LOCK(pipe)) {
     627      switch (cmd) {
     628        case RTEMS_IOCTL_SELECT:
     629          rv = pipe_select(pipe, buffer);
     630          break;
     631        case FIONREAD:
     632          /* Return length of pipe */
     633          *(unsigned int *) buffer = pipe->Length;
     634          break;
     635      }
     636
     637      PIPE_UNLOCK(pipe);
     638    } else {
     639      rv = -EINTR;
     640    }
     641  } else {
     642    rv = -EFAULT;
     643  }
     644
     645  return rv;
    574646}
    575647
  • cpukit/libfs/src/pipe/pipe.h

    rd189646 r1f16a9f  
    4040  rtems_id readBarrier;   /* wait queues */
    4141  rtems_id writeBarrier;
     42  rtems_id select_read_task_id;
     43  rtems_id select_write_task_id;
    4244#if 0
    4345  boolean Anonymous;      /* anonymous pipe or FIFO */
Note: See TracChangeset for help on using the changeset viewer.