1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
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. |
---|
27 | */ |
---|
28 | |
---|
29 | #if !defined(OPERATION_COUNT) |
---|
30 | #define OPERATION_COUNT 100 |
---|
31 | #endif |
---|
32 | |
---|
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> |
---|
42 | #include <rtems/btimer.h> |
---|
43 | |
---|
44 | const char rtems_test_name[] = "PSXTMBARRIER 04"; |
---|
45 | |
---|
46 | /* forward declarations to avoid warnings */ |
---|
47 | void *POSIX_Init(void *argument); |
---|
48 | void *Blocker(void *argument); |
---|
49 | |
---|
50 | #define N 2 |
---|
51 | pthread_barrier_t barrier; |
---|
52 | |
---|
53 | void *Blocker( |
---|
54 | void *argument |
---|
55 | ) |
---|
56 | { |
---|
57 | benchmark_timer_t end_time; |
---|
58 | |
---|
59 | /* block on barrier wait, switch back to first thread */ |
---|
60 | (void) pthread_barrier_wait( &barrier ); |
---|
61 | |
---|
62 | |
---|
63 | /* preempt first thread and stop time */ |
---|
64 | end_time = benchmark_timer_read(); |
---|
65 | put_time( |
---|
66 | "pthread_barrier_wait: releasing preempt", |
---|
67 | end_time, |
---|
68 | 1, |
---|
69 | 0, |
---|
70 | 0 |
---|
71 | ); |
---|
72 | TEST_END(); |
---|
73 | rtems_test_exit( 0 ); |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | void *POSIX_Init( |
---|
78 | void *argument |
---|
79 | ) |
---|
80 | { |
---|
81 | int status; |
---|
82 | pthread_t threadId; |
---|
83 | int policy; |
---|
84 | struct sched_param param; |
---|
85 | |
---|
86 | TEST_BEGIN(); |
---|
87 | |
---|
88 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
89 | rtems_test_assert( status == 0 ); |
---|
90 | status = pthread_barrier_init( &barrier, NULL, N ); |
---|
91 | rtems_test_assert( status == 0 ); |
---|
92 | |
---|
93 | /* yield to second thread so it can start up and block */ |
---|
94 | sched_yield(); |
---|
95 | |
---|
96 | pthread_getschedparam(threadId, &policy, ¶m); |
---|
97 | param.sched_priority = sched_get_priority_max(policy) - 1; |
---|
98 | /* preempt doesn't occur here due to second thread being blocked */ |
---|
99 | pthread_setschedparam(threadId, policy, ¶m); |
---|
100 | |
---|
101 | /* as soon as this thread waits on barrier, release occurs, 2nd thread |
---|
102 | * preempts this one due to having a higher priority |
---|
103 | */ |
---|
104 | benchmark_timer_initialize(); |
---|
105 | status = pthread_barrier_wait( &barrier ); |
---|
106 | |
---|
107 | /* avoid warning but should not be executed */ |
---|
108 | return NULL; |
---|
109 | } |
---|
110 | |
---|
111 | /* configuration information */ |
---|
112 | |
---|
113 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
114 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
115 | |
---|
116 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
117 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
118 | |
---|
119 | #define CONFIGURE_INIT |
---|
120 | |
---|
121 | #include <rtems/confdefs.h> |
---|
122 | /* end of file */ |
---|