Changeset b1b6dd71 in rtems for cpukit/libfs/src/pipe/fifo.c


Ignore:
Timestamp:
Dec 11, 2019, 3:45:37 PM (2 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
08bd7d3
Parents:
86c70e71
git-author:
Sebastian Huber <sebastian.huber@…> (12/11/19 15:45:37)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/11/19 16:45:31)
Message:

pipe: Use condition variables

Use self-contained condition variables instead of Classic API barriers.
This simplifies the implementation and configuration.

Update #3840.

File:
1 edited

Legend:

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

    r86c70e71 rb1b6dd71  
    2828#include <rtems/libio_.h>
    2929#include <rtems/pipe.h>
    30 #include <rtems/rtems/barrierimpl.h>
    31 #include <rtems/score/statesimpl.h>
    3230
    3331#define LIBIO_ACCMODE(_iop) (rtems_libio_iop_flags(_iop) & LIBIO_FLAGS_READ_WRITE)
     
    4745
    4846#define PIPE_READWAIT(_pipe)  \
    49   ( rtems_barrier_wait(_pipe->readBarrier, RTEMS_NO_TIMEOUT)  \
    50    == RTEMS_SUCCESSFUL)
     47  rtems_condition_variable_wait(&(_pipe)->readBarrier, &(_pipe)->Mutex)
    5148
    5249#define PIPE_WRITEWAIT(_pipe)  \
    53   ( rtems_barrier_wait(_pipe->writeBarrier, RTEMS_NO_TIMEOUT)  \
    54    == RTEMS_SUCCESSFUL)
     50  rtems_condition_variable_wait(&(_pipe)->writeBarrier, &(_pipe)->Mutex)
    5551
    5652#define PIPE_WAKEUPREADERS(_pipe) \
    57   do {uint32_t n; rtems_barrier_release(_pipe->readBarrier, &n); } while(0)
     53  rtems_condition_variable_broadcast(&(_pipe)->readBarrier)
    5854
    5955#define PIPE_WAKEUPWRITERS(_pipe) \
    60   do {uint32_t n; rtems_barrier_release(_pipe->writeBarrier, &n); } while(0)
     56  rtems_condition_variable_broadcast(&(_pipe)->writeBarrier)
    6157
    6258/*
     
    7975  pipe->Size = PIPE_BUF;
    8076  pipe->Buffer = malloc(pipe->Size);
    81   if (! pipe->Buffer)
    82     goto err_buf;
    83 
    84   err = -ENOMEM;
    85 
    86   if (rtems_barrier_create(
    87         rtems_build_name ('P', 'I', 'r', c),
    88         RTEMS_BARRIER_MANUAL_RELEASE, 0,
    89         &pipe->readBarrier) != RTEMS_SUCCESSFUL)
    90     goto err_rbar;
    91   if (rtems_barrier_create(
    92         rtems_build_name ('P', 'I', 'w', c),
    93         RTEMS_BARRIER_MANUAL_RELEASE, 0,
    94         &pipe->writeBarrier) != RTEMS_SUCCESSFUL)
    95     goto err_wbar;
     77  if (pipe->Buffer == NULL) {
     78    free(pipe);
     79    return -ENOMEM;
     80  }
     81
     82  rtems_condition_variable_init(&pipe->readBarrier, "Pipe Read");
     83  rtems_condition_variable_init(&pipe->writeBarrier, "Pipe Write");
    9684  rtems_mutex_init(&pipe->Mutex, "Pipe");
    9785
     
    10088    c = 'a';
    10189  return 0;
    102 
    103 err_wbar:
    104   rtems_barrier_delete(pipe->readBarrier);
    105 err_rbar:
    106   free(pipe->Buffer);
    107 err_buf:
    108   free(pipe);
    109   return err;
    11090}
    11191
     
    11595)
    11696{
    117   rtems_barrier_delete(pipe->readBarrier);
    118   rtems_barrier_delete(pipe->writeBarrier);
     97  rtems_condition_variable_destroy(&pipe->readBarrier);
     98  rtems_condition_variable_destroy(&pipe->writeBarrier);
    11999  rtems_mutex_destroy(&pipe->Mutex);
    120100  free(pipe->Buffer);
     
    242222        /* Wait until a writer opens the pipe */
    243223        do {
    244           PIPE_UNLOCK(pipe);
    245           if (! PIPE_READWAIT(pipe))
    246             goto out_error;
    247           PIPE_LOCK(pipe);
     224          PIPE_READWAIT(pipe);
    248225        } while (prevCounter == pipe->writerCounter);
    249226      }
     
    266243        err = -EINTR;
    267244        do {
    268           PIPE_UNLOCK(pipe);
    269           if (! PIPE_WRITEWAIT(pipe))
    270             goto out_error;
    271           PIPE_LOCK(pipe);
     245          PIPE_WRITEWAIT(pipe);
    272246        } while (prevCounter == pipe->readerCounter);
    273247      }
     
    315289    /* Wait until pipe is no more empty or no writer exists */
    316290    pipe->waitingReaders ++;
    317     PIPE_UNLOCK(pipe);
    318     if (! PIPE_READWAIT(pipe))
    319       ret = -EINTR;
    320     PIPE_LOCK(pipe);
     291    PIPE_READWAIT(pipe);
    321292    pipe->waitingReaders --;
    322293    if (ret != 0)
     
    385356      /* Wait until there is chunk bytes space or no reader exists */
    386357      pipe->waitingWriters ++;
    387       PIPE_UNLOCK(pipe);
    388       if (! PIPE_WRITEWAIT(pipe))
    389         ret = -EINTR;
    390       PIPE_LOCK(pipe);
     358      PIPE_WRITEWAIT(pipe);
    391359      pipe->waitingWriters --;
    392360      if (ret != 0)
Note: See TracChangeset for help on using the changeset viewer.