[94fa540] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
| 2 | |
---|
[4f6cc11d] | 3 | /* |
---|
[50162e0] | 4 | * COPYRIGHT (c) 1989-2013. |
---|
[4f6cc11d] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[94fa540] | 7 | * Redistribution and use in source and binary forms, with or without |
---|
| 8 | * modification, are permitted provided that the following conditions |
---|
| 9 | * are met: |
---|
| 10 | * 1. Redistributions of source code must retain the above copyright |
---|
| 11 | * notice, this list of conditions and the following disclaimer. |
---|
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 13 | * notice, this list of conditions and the following disclaimer in the |
---|
| 14 | * documentation and/or other materials provided with the distribution. |
---|
| 15 | * |
---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[4f6cc11d] | 27 | */ |
---|
| 28 | |
---|
[96e4b22] | 29 | #if !defined(OPERATION_COUNT) |
---|
| 30 | #define OPERATION_COUNT 100 |
---|
| 31 | #endif |
---|
| 32 | |
---|
[4f6cc11d] | 33 | #ifdef HAVE_CONFIG_H |
---|
| 34 | #include "config.h" |
---|
| 35 | #endif |
---|
| 36 | |
---|
| 37 | #include <tmacros.h> |
---|
| 38 | #include <timesys.h> |
---|
| 39 | #include "test_support.h" |
---|
| 40 | #include <pthread.h> |
---|
| 41 | #include <sched.h> |
---|
[8fbe2e6] | 42 | #include <rtems/btimer.h> |
---|
[4f6cc11d] | 43 | |
---|
[fd46711] | 44 | const char rtems_test_name[] = "PSXTMBARRIER 03"; |
---|
| 45 | |
---|
[991a3cc1] | 46 | /* forward declarations to avoid warnings */ |
---|
| 47 | void *POSIX_Init(void *argument); |
---|
| 48 | void *Blocker(void *argument); |
---|
| 49 | |
---|
[4f6cc11d] | 50 | #define N 2 |
---|
| 51 | pthread_barrier_t barrier; |
---|
| 52 | |
---|
| 53 | void *Blocker( |
---|
| 54 | void *argument |
---|
| 55 | ) |
---|
| 56 | { |
---|
| 57 | (void) pthread_barrier_wait( &barrier ); |
---|
| 58 | rtems_test_assert( FALSE ); |
---|
| 59 | return NULL; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void *POSIX_Init( |
---|
| 63 | void *argument |
---|
| 64 | ) |
---|
| 65 | { |
---|
| 66 | int status; |
---|
| 67 | pthread_t threadId; |
---|
[add2977] | 68 | benchmark_timer_t end_time; |
---|
[4f6cc11d] | 69 | |
---|
[fd46711] | 70 | TEST_BEGIN(); |
---|
[4f6cc11d] | 71 | |
---|
| 72 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
| 73 | rtems_test_assert( status == 0 ); |
---|
| 74 | |
---|
| 75 | /* |
---|
| 76 | * Deliberately create the barrier after the threads. This way if the |
---|
| 77 | * threads do run before we intend, they will get an error. |
---|
| 78 | * The barrier will be released on the Nth thread blocking. |
---|
| 79 | */ |
---|
| 80 | status = pthread_barrier_init( &barrier, NULL, N ); |
---|
| 81 | rtems_test_assert( status == 0 ); |
---|
| 82 | |
---|
| 83 | /* |
---|
| 84 | * Let the other thread start so the thread startup overhead, |
---|
| 85 | * is accounted for. When we return, we can start the benchmark. |
---|
| 86 | */ |
---|
| 87 | sched_yield(); |
---|
| 88 | /* let other thread run */ |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | * Because this is the Nth thread at the barrier, this is an |
---|
| 92 | * unblocking operation. |
---|
| 93 | */ |
---|
| 94 | benchmark_timer_initialize(); |
---|
[115e059] | 95 | status = pthread_barrier_wait( &barrier ); |
---|
[4f6cc11d] | 96 | end_time = benchmark_timer_read(); |
---|
| 97 | /* |
---|
| 98 | * Upon successful completion return value, the status should be |
---|
| 99 | * PTHREAD_BARRIER_SERIAL_THREAD. |
---|
| 100 | */ |
---|
| 101 | rtems_test_assert( status == PTHREAD_BARRIER_SERIAL_THREAD ); |
---|
| 102 | |
---|
| 103 | put_time( |
---|
[50162e0] | 104 | "pthread_barrier_wait: releasing no preempt", |
---|
[4f6cc11d] | 105 | end_time, |
---|
| 106 | 1, |
---|
| 107 | 0, |
---|
| 108 | 0 |
---|
| 109 | ); |
---|
| 110 | |
---|
[fd46711] | 111 | TEST_END(); |
---|
[4f6cc11d] | 112 | rtems_test_exit( 0 ); |
---|
| 113 | |
---|
| 114 | return NULL; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /* configuration information */ |
---|
| 118 | |
---|
[c4b8b147] | 119 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[4f6cc11d] | 120 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 121 | |
---|
| 122 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
| 123 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 124 | |
---|
| 125 | #define CONFIGURE_INIT |
---|
| 126 | |
---|
| 127 | #include <rtems/confdefs.h> |
---|
| 128 | /* end of file */ |
---|