[4f6cc11d] | 1 | /* |
---|
[991a3cc1] | 2 | * COPYRIGHT (c) 1989-2012. |
---|
[4f6cc11d] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
| 14 | #include <coverhd.h> |
---|
| 15 | #include <tmacros.h> |
---|
| 16 | #include <timesys.h> |
---|
| 17 | #include "test_support.h" |
---|
| 18 | #include <pthread.h> |
---|
| 19 | #include <sched.h> |
---|
| 20 | #include <rtems/timerdrv.h> |
---|
| 21 | |
---|
[991a3cc1] | 22 | /* forward declarations to avoid warnings */ |
---|
| 23 | void *POSIX_Init(void *argument); |
---|
| 24 | void *Blocker(void *argument); |
---|
| 25 | |
---|
[4f6cc11d] | 26 | #define N 2 |
---|
| 27 | pthread_barrier_t barrier; |
---|
| 28 | |
---|
| 29 | void *Blocker( |
---|
| 30 | void *argument |
---|
| 31 | ) |
---|
| 32 | { |
---|
| 33 | (void) pthread_barrier_wait( &barrier ); |
---|
| 34 | rtems_test_assert( FALSE ); |
---|
| 35 | return NULL; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void *POSIX_Init( |
---|
| 39 | void *argument |
---|
| 40 | ) |
---|
| 41 | { |
---|
| 42 | int status; |
---|
| 43 | pthread_t threadId; |
---|
[add2977] | 44 | benchmark_timer_t end_time; |
---|
[4f6cc11d] | 45 | |
---|
| 46 | puts( "\n\n*** POSIX TIME TEST PSXTMBARRIER 03 ***" ); |
---|
| 47 | |
---|
| 48 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
| 49 | rtems_test_assert( status == 0 ); |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * Deliberately create the barrier after the threads. This way if the |
---|
| 53 | * threads do run before we intend, they will get an error. |
---|
| 54 | * The barrier will be released on the Nth thread blocking. |
---|
| 55 | */ |
---|
| 56 | status = pthread_barrier_init( &barrier, NULL, N ); |
---|
| 57 | rtems_test_assert( status == 0 ); |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * Let the other thread start so the thread startup overhead, |
---|
| 61 | * is accounted for. When we return, we can start the benchmark. |
---|
| 62 | */ |
---|
| 63 | sched_yield(); |
---|
| 64 | /* let other thread run */ |
---|
| 65 | |
---|
| 66 | /* |
---|
| 67 | * Because this is the Nth thread at the barrier, this is an |
---|
| 68 | * unblocking operation. |
---|
| 69 | */ |
---|
| 70 | benchmark_timer_initialize(); |
---|
[115e059] | 71 | status = pthread_barrier_wait( &barrier ); |
---|
[4f6cc11d] | 72 | end_time = benchmark_timer_read(); |
---|
| 73 | /* |
---|
| 74 | * Upon successful completion return value, the status should be |
---|
| 75 | * PTHREAD_BARRIER_SERIAL_THREAD. |
---|
| 76 | */ |
---|
| 77 | rtems_test_assert( status == PTHREAD_BARRIER_SERIAL_THREAD ); |
---|
| 78 | |
---|
| 79 | put_time( |
---|
| 80 | "pthread_barrier_wait â releasing, no preempt", |
---|
| 81 | end_time, |
---|
| 82 | 1, |
---|
| 83 | 0, |
---|
| 84 | 0 |
---|
| 85 | ); |
---|
| 86 | |
---|
| 87 | puts( "*** END OF POSIX TIME TEST PSXTMBARRIER 03 ***" ); |
---|
| 88 | rtems_test_exit( 0 ); |
---|
| 89 | |
---|
| 90 | return NULL; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* configuration information */ |
---|
| 94 | |
---|
| 95 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 96 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 97 | |
---|
| 98 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
| 99 | #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1 |
---|
| 100 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 101 | |
---|
| 102 | #define CONFIGURE_INIT |
---|
| 103 | |
---|
| 104 | #include <rtems/confdefs.h> |
---|
| 105 | /* end of file */ |
---|