[4f6cc11d] | 1 | /* |
---|
[50162e0] | 2 | * COPYRIGHT (c) 1989-2013. |
---|
[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 |
---|
[c499856] | 7 | * http://www.rtems.org/license/LICENSE. |
---|
[4f6cc11d] | 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> |
---|
[8fbe2e6] | 20 | #include <rtems/btimer.h> |
---|
[4f6cc11d] | 21 | |
---|
[fd46711] | 22 | const char rtems_test_name[] = "PSXTMBARRIER 03"; |
---|
| 23 | |
---|
[991a3cc1] | 24 | /* forward declarations to avoid warnings */ |
---|
| 25 | void *POSIX_Init(void *argument); |
---|
| 26 | void *Blocker(void *argument); |
---|
| 27 | |
---|
[4f6cc11d] | 28 | #define N 2 |
---|
| 29 | pthread_barrier_t barrier; |
---|
| 30 | |
---|
| 31 | void *Blocker( |
---|
| 32 | void *argument |
---|
| 33 | ) |
---|
| 34 | { |
---|
| 35 | (void) pthread_barrier_wait( &barrier ); |
---|
| 36 | rtems_test_assert( FALSE ); |
---|
| 37 | return NULL; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void *POSIX_Init( |
---|
| 41 | void *argument |
---|
| 42 | ) |
---|
| 43 | { |
---|
| 44 | int status; |
---|
| 45 | pthread_t threadId; |
---|
[add2977] | 46 | benchmark_timer_t end_time; |
---|
[4f6cc11d] | 47 | |
---|
[fd46711] | 48 | TEST_BEGIN(); |
---|
[4f6cc11d] | 49 | |
---|
| 50 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
| 51 | rtems_test_assert( status == 0 ); |
---|
| 52 | |
---|
| 53 | /* |
---|
| 54 | * Deliberately create the barrier after the threads. This way if the |
---|
| 55 | * threads do run before we intend, they will get an error. |
---|
| 56 | * The barrier will be released on the Nth thread blocking. |
---|
| 57 | */ |
---|
| 58 | status = pthread_barrier_init( &barrier, NULL, N ); |
---|
| 59 | rtems_test_assert( status == 0 ); |
---|
| 60 | |
---|
| 61 | /* |
---|
| 62 | * Let the other thread start so the thread startup overhead, |
---|
| 63 | * is accounted for. When we return, we can start the benchmark. |
---|
| 64 | */ |
---|
| 65 | sched_yield(); |
---|
| 66 | /* let other thread run */ |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * Because this is the Nth thread at the barrier, this is an |
---|
| 70 | * unblocking operation. |
---|
| 71 | */ |
---|
| 72 | benchmark_timer_initialize(); |
---|
[115e059] | 73 | status = pthread_barrier_wait( &barrier ); |
---|
[4f6cc11d] | 74 | end_time = benchmark_timer_read(); |
---|
| 75 | /* |
---|
| 76 | * Upon successful completion return value, the status should be |
---|
| 77 | * PTHREAD_BARRIER_SERIAL_THREAD. |
---|
| 78 | */ |
---|
| 79 | rtems_test_assert( status == PTHREAD_BARRIER_SERIAL_THREAD ); |
---|
| 80 | |
---|
| 81 | put_time( |
---|
[50162e0] | 82 | "pthread_barrier_wait: releasing no preempt", |
---|
[4f6cc11d] | 83 | end_time, |
---|
| 84 | 1, |
---|
| 85 | 0, |
---|
| 86 | 0 |
---|
| 87 | ); |
---|
| 88 | |
---|
[fd46711] | 89 | TEST_END(); |
---|
[4f6cc11d] | 90 | rtems_test_exit( 0 ); |
---|
| 91 | |
---|
| 92 | return NULL; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /* configuration information */ |
---|
| 96 | |
---|
| 97 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 98 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 99 | |
---|
| 100 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
| 101 | #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1 |
---|
| 102 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 103 | |
---|
| 104 | #define CONFIGURE_INIT |
---|
| 105 | |
---|
| 106 | #include <rtems/confdefs.h> |
---|
| 107 | /* end of file */ |
---|