Ignore:
Timestamp:
Dec 11, 2019, 3:45:37 PM (3 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
  • testsuites/sptests/spfifo02/init.c

    r86c70e71 rb1b6dd71  
    2020#include <unistd.h>
    2121#include <errno.h>
    22 #include <rtems/libcsupport.h>
     22#include <rtems/malloc.h>
    2323
    2424const char rtems_test_name[] = "SPFIFO 2";
    2525
    26 /* forward declarations to avoid warnings */
    27 rtems_task Init(rtems_task_argument argument);
    28 void create_all_barriers(void);
    29 void delete_barrier(void);
    30 void create_fifo(void);
    31 void open_fifo(int expected, int flags);
    32 
    33 #define MAXIMUM 10
    3426#define NUM_OPEN_REQ 26
    3527
    36 rtems_id Barriers[MAXIMUM];
    37 int BarrierCount;
    38 
    39 rtems_id Semaphores[MAXIMUM];
    40 int SemaphoreCount;
    41 
    42 void create_all_barriers(void)
    43 {
    44   rtems_status_code status;
    45   int               i;
    46 
    47   BarrierCount = 0;
    48 
    49   memset( Barriers, 0, sizeof(Barriers) );
    50   for ( i=0 ; i<MAXIMUM ; i++ ) {
    51     status = rtems_barrier_create(
    52       rtems_build_name( 'B', 'A', 'R', 0x30+i ),
    53       RTEMS_BARRIER_MANUAL_RELEASE,
    54       0,
    55       &Barriers[i]
    56     );
    57     if ( status == RTEMS_TOO_MANY ) {
    58       printf( "%d Barriers created\n", BarrierCount+1 );
    59       return;
    60     }
    61 
    62     directive_failed( status, "barrier create" );
    63     BarrierCount++;
    64   }
    65 }
    66 
    67 void delete_barrier(void)
    68 {
    69   rtems_status_code status;
    70  
    71   BarrierCount--;
    72   printf( "Deleting barrier id=0x%08x\n",
    73     (unsigned int)Barriers[BarrierCount] );
    74   status = rtems_barrier_delete( Barriers[BarrierCount] );
    75   directive_failed( status, "barrier delete" );
    76 }
    77 
    78 void create_fifo(void)
     28static void create_fifo(void)
    7929{
    8030  int status;
     
    8434}
    8535
    86 void open_fifo(int expected, int flags)
     36static void open_fifo(int expected, int flags)
    8737{
    8838  int fd;
     
    9949}
    10050
    101 rtems_task Init(
     51static rtems_task Init(
    10252  rtems_task_argument argument
    10353)
    10454{
    105   void *alloc_ptr = (void *)0;
     55  void *p;
    10656  int num_opens = 0;
    10757  int index = 0;
     
    10959  TEST_BEGIN();
    11060
    111   puts( "Creating all barriers" );
    112   create_all_barriers();
    113 
    11461  puts( "Creating FIFO" );
    11562  create_fifo();
    11663
    117   alloc_ptr = malloc( malloc_free_space() - 4 );
     64  p = rtems_heap_greedy_allocate(NULL, 0);
    11865  puts("Opening FIFO.. expect ENOMEM since no memory is available");
    11966  open_fifo(ENOMEM, O_RDWR);
     67  rtems_heap_greedy_free(p);
    12068
    121   free(alloc_ptr);
    122   puts( "Opening FIFO.. expect ENOMEM (barrier-1 for pipe could not be created)" );
    123   open_fifo(ENOMEM, O_RDWR);
    124 
    125   delete_barrier();
    126   puts( "Opening FIFO.. expect ENOMEM (barrier-2 for pipe could not be created" );
    127   open_fifo(ENOMEM, O_RDWR);
    128 
    129   delete_barrier();
    13069  puts( "Opening FIFO in RDWR mode. Expect OK" );
    13170  open_fifo(0, O_RDWR);
Note: See TracChangeset for help on using the changeset viewer.