Changeset b1b6dd71 in rtems
- Timestamp:
- 12/11/19 15:45:37 (4 years ago)
- Branches:
- 5, 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)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/include/rtems/confdefs.h
r86c70e71 rb1b6dd71 212 212 #if !defined(CONFIGURE_MAXIMUM_PIPES) 213 213 #define CONFIGURE_MAXIMUM_PIPES 0 214 #endif215 216 /*217 * This specifies the number of barriers required for the configured218 * number of FIFOs and named pipes.219 */220 #if CONFIGURE_MAXIMUM_FIFOS > 0 || CONFIGURE_MAXIMUM_PIPES > 0221 #define _CONFIGURE_BARRIERS_FOR_FIFOS \222 (2 * (CONFIGURE_MAXIMUM_FIFOS + CONFIGURE_MAXIMUM_PIPES))223 #else224 #define _CONFIGURE_BARRIERS_FOR_FIFOS 0225 214 #endif 226 215 … … 2042 2031 #endif 2043 2032 2044 /*2045 * This macro is calculated to specify the number of Classic API2046 * Barriers required by the application and configured capabilities.2047 */2048 #define _CONFIGURE_BARRIERS \2049 (CONFIGURE_MAXIMUM_BARRIERS + _CONFIGURE_BARRIERS_FOR_FIFOS)2050 2051 2033 #ifndef CONFIGURE_MAXIMUM_USER_EXTENSIONS 2052 2034 /** … … 2738 2720 ); 2739 2721 2740 #if _CONFIGURE_BARRIERS > 02741 BARRIER_INFORMATION_DEFINE( _CONFIGURE_BARRIERS );2722 #if CONFIGURE_MAXIMUM_BARRIERS > 0 2723 BARRIER_INFORMATION_DEFINE( CONFIGURE_MAXIMUM_BARRIERS ); 2742 2724 #endif 2743 2725 -
cpukit/include/rtems/pipe.h
r86c70e71 rb1b6dd71 48 48 unsigned int writerCounter; /* for differentiation of successive opens */ 49 49 rtems_mutex Mutex; 50 rtems_ idreadBarrier; /* wait queues */51 rtems_ idwriteBarrier;50 rtems_condition_variable readBarrier; /* wait queues */ 51 rtems_condition_variable writeBarrier; 52 52 #if 0 53 53 boolean Anonymous; /* anonymous pipe or FIFO */ -
cpukit/libfs/src/pipe/fifo.c
r86c70e71 rb1b6dd71 28 28 #include <rtems/libio_.h> 29 29 #include <rtems/pipe.h> 30 #include <rtems/rtems/barrierimpl.h>31 #include <rtems/score/statesimpl.h>32 30 33 31 #define LIBIO_ACCMODE(_iop) (rtems_libio_iop_flags(_iop) & LIBIO_FLAGS_READ_WRITE) … … 47 45 48 46 #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) 51 48 52 49 #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) 55 51 56 52 #define PIPE_WAKEUPREADERS(_pipe) \ 57 do {uint32_t n; rtems_barrier_release(_pipe->readBarrier, &n); } while(0)53 rtems_condition_variable_broadcast(&(_pipe)->readBarrier) 58 54 59 55 #define PIPE_WAKEUPWRITERS(_pipe) \ 60 do {uint32_t n; rtems_barrier_release(_pipe->writeBarrier, &n); } while(0)56 rtems_condition_variable_broadcast(&(_pipe)->writeBarrier) 61 57 62 58 /* … … 79 75 pipe->Size = PIPE_BUF; 80 76 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"); 96 84 rtems_mutex_init(&pipe->Mutex, "Pipe"); 97 85 … … 100 88 c = 'a'; 101 89 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;110 90 } 111 91 … … 115 95 ) 116 96 { 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); 119 99 rtems_mutex_destroy(&pipe->Mutex); 120 100 free(pipe->Buffer); … … 242 222 /* Wait until a writer opens the pipe */ 243 223 do { 244 PIPE_UNLOCK(pipe); 245 if (! PIPE_READWAIT(pipe)) 246 goto out_error; 247 PIPE_LOCK(pipe); 224 PIPE_READWAIT(pipe); 248 225 } while (prevCounter == pipe->writerCounter); 249 226 } … … 266 243 err = -EINTR; 267 244 do { 268 PIPE_UNLOCK(pipe); 269 if (! PIPE_WRITEWAIT(pipe)) 270 goto out_error; 271 PIPE_LOCK(pipe); 245 PIPE_WRITEWAIT(pipe); 272 246 } while (prevCounter == pipe->readerCounter); 273 247 } … … 315 289 /* Wait until pipe is no more empty or no writer exists */ 316 290 pipe->waitingReaders ++; 317 PIPE_UNLOCK(pipe); 318 if (! PIPE_READWAIT(pipe)) 319 ret = -EINTR; 320 PIPE_LOCK(pipe); 291 PIPE_READWAIT(pipe); 321 292 pipe->waitingReaders --; 322 293 if (ret != 0) … … 385 356 /* Wait until there is chunk bytes space or no reader exists */ 386 357 pipe->waitingWriters ++; 387 PIPE_UNLOCK(pipe); 388 if (! PIPE_WRITEWAIT(pipe)) 389 ret = -EINTR; 390 PIPE_LOCK(pipe); 358 PIPE_WRITEWAIT(pipe); 391 359 pipe->waitingWriters --; 392 360 if (ret != 0) -
testsuites/sptests/spfifo02/init.c
r86c70e71 rb1b6dd71 20 20 #include <unistd.h> 21 21 #include <errno.h> 22 #include <rtems/ libcsupport.h>22 #include <rtems/malloc.h> 23 23 24 24 const char rtems_test_name[] = "SPFIFO 2"; 25 25 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 1034 26 #define NUM_OPEN_REQ 26 35 27 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) 28 static void create_fifo(void) 79 29 { 80 30 int status; … … 84 34 } 85 35 86 void open_fifo(int expected, int flags)36 static void open_fifo(int expected, int flags) 87 37 { 88 38 int fd; … … 99 49 } 100 50 101 rtems_task Init(51 static rtems_task Init( 102 52 rtems_task_argument argument 103 53 ) 104 54 { 105 void * alloc_ptr = (void *)0;55 void *p; 106 56 int num_opens = 0; 107 57 int index = 0; … … 109 59 TEST_BEGIN(); 110 60 111 puts( "Creating all barriers" );112 create_all_barriers();113 114 61 puts( "Creating FIFO" ); 115 62 create_fifo(); 116 63 117 alloc_ptr = malloc( malloc_free_space() - 4);64 p = rtems_heap_greedy_allocate(NULL, 0); 118 65 puts("Opening FIFO.. expect ENOMEM since no memory is available"); 119 66 open_fifo(ENOMEM, O_RDWR); 67 rtems_heap_greedy_free(p); 120 68 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();130 69 puts( "Opening FIFO in RDWR mode. Expect OK" ); 131 70 open_fifo(0, O_RDWR);
Note: See TracChangeset
for help on using the changeset viewer.