1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2013. |
---|
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.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include <timesys.h> |
---|
16 | #include "test_support.h" |
---|
17 | #include <pthread.h> |
---|
18 | #include <sched.h> |
---|
19 | #include <rtems/btimer.h> |
---|
20 | |
---|
21 | #define N 1 |
---|
22 | |
---|
23 | const char rtems_test_name[] = "PSXTMCOND 07"; |
---|
24 | |
---|
25 | /* forward declarations to avoid warnings */ |
---|
26 | void *POSIX_Init(void *argument); |
---|
27 | void *Blocker(void *argument); |
---|
28 | |
---|
29 | pthread_mutex_t MutexID; |
---|
30 | pthread_cond_t CondID; |
---|
31 | |
---|
32 | void *Blocker( |
---|
33 | void *argument |
---|
34 | ) |
---|
35 | { |
---|
36 | int status; |
---|
37 | benchmark_timer_t end_time; |
---|
38 | |
---|
39 | status = pthread_mutex_lock(&MutexID); |
---|
40 | rtems_test_assert( status == 0 ); |
---|
41 | |
---|
42 | /* Unlock mutex, block, wait for CondID to be signaled */ |
---|
43 | pthread_cond_wait(&CondID,&MutexID); |
---|
44 | |
---|
45 | end_time = benchmark_timer_read(); |
---|
46 | put_time( |
---|
47 | "pthread_cond_broadcast: threads waiting, preempt", |
---|
48 | end_time, |
---|
49 | 1, |
---|
50 | 0, |
---|
51 | 0 |
---|
52 | ); |
---|
53 | |
---|
54 | TEST_END(); |
---|
55 | rtems_test_exit( 0 ); |
---|
56 | return NULL; |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | void *POSIX_Init( |
---|
61 | void *argument |
---|
62 | ) |
---|
63 | { |
---|
64 | int status; |
---|
65 | int i; |
---|
66 | pthread_t threadId; |
---|
67 | pthread_attr_t attr; |
---|
68 | struct sched_param param; |
---|
69 | |
---|
70 | TEST_BEGIN(); |
---|
71 | |
---|
72 | /* Setup variables */ |
---|
73 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
74 | rtems_test_assert( status == 0 ); |
---|
75 | |
---|
76 | status = pthread_mutex_init(&MutexID, NULL); |
---|
77 | rtems_test_assert( status == 0 ); |
---|
78 | |
---|
79 | status = pthread_cond_init(&CondID, NULL); |
---|
80 | rtems_test_assert( status == 0 ); |
---|
81 | |
---|
82 | /* Setup so threads are created with a high enough priority to preempt |
---|
83 | * as they get created. |
---|
84 | */ |
---|
85 | status = pthread_attr_init( &attr ); |
---|
86 | rtems_test_assert( status == 0 ); |
---|
87 | |
---|
88 | status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
89 | rtems_test_assert( status == 0 ); |
---|
90 | |
---|
91 | status = pthread_attr_setschedpolicy( &attr, SCHED_FIFO ); |
---|
92 | rtems_test_assert( status == 0 ); |
---|
93 | |
---|
94 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); |
---|
95 | status = pthread_attr_setschedparam( &attr, ¶m ); |
---|
96 | rtems_test_assert( status == 0 ); |
---|
97 | |
---|
98 | for ( i=0 ; i < N ; i++ ) { |
---|
99 | /* Threads will preempt as they are created, start up, and block */ |
---|
100 | status = pthread_create(&threadId, &attr, Blocker, NULL); |
---|
101 | rtems_test_assert( status == 0 ); |
---|
102 | } |
---|
103 | |
---|
104 | /* broadcast will awaken all threads and one will preempt us, end time |
---|
105 | * in other thread |
---|
106 | */ |
---|
107 | benchmark_timer_initialize(); |
---|
108 | status = pthread_cond_broadcast(&CondID); |
---|
109 | |
---|
110 | /* Should never reach this point */ |
---|
111 | rtems_test_assert( FALSE ); |
---|
112 | return NULL; |
---|
113 | } |
---|
114 | |
---|
115 | /* configuration information */ |
---|
116 | |
---|
117 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
118 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
119 | |
---|
120 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 + N |
---|
121 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
122 | |
---|
123 | #define CONFIGURE_INIT |
---|
124 | |
---|
125 | #include <rtems/confdefs.h> |
---|
126 | /* end of file */ |
---|