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 <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/btimer.h> |
---|
21 | |
---|
22 | const char rtems_test_name[] = "PSXTMMUTEX 05"; |
---|
23 | |
---|
24 | /* forward declarations to avoid warnings */ |
---|
25 | void *POSIX_Init(void *argument); |
---|
26 | void *Blocker(void *argument); |
---|
27 | |
---|
28 | pthread_mutex_t MutexId; |
---|
29 | |
---|
30 | void *Blocker( |
---|
31 | void *argument |
---|
32 | ) |
---|
33 | { |
---|
34 | (void) pthread_mutex_lock( &MutexId ); |
---|
35 | /* should never return */ |
---|
36 | rtems_test_assert( FALSE ); |
---|
37 | |
---|
38 | return NULL; |
---|
39 | } |
---|
40 | |
---|
41 | void *POSIX_Init( |
---|
42 | void *argument |
---|
43 | ) |
---|
44 | { |
---|
45 | int status; |
---|
46 | pthread_t threadId; |
---|
47 | benchmark_timer_t end_time; |
---|
48 | |
---|
49 | TEST_BEGIN(); |
---|
50 | |
---|
51 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
52 | rtems_test_assert( status == 0 ); |
---|
53 | |
---|
54 | /* |
---|
55 | * Deliberately create the mutex after the threads. This way if the |
---|
56 | * threads do run before we intend, they will get an error. |
---|
57 | */ |
---|
58 | status = pthread_mutex_init( &MutexId, NULL ); |
---|
59 | rtems_test_assert( status == 0 ); |
---|
60 | |
---|
61 | /* |
---|
62 | * Ensure the mutex is unavailable so the other threads block. |
---|
63 | */ |
---|
64 | status = pthread_mutex_lock( &MutexId ); |
---|
65 | rtems_test_assert( status == 0 ); |
---|
66 | |
---|
67 | /* |
---|
68 | * Let the other thread start so the thread startup overhead, |
---|
69 | * is accounted for. When we return, we can start the benchmark. |
---|
70 | */ |
---|
71 | sched_yield(); |
---|
72 | /* let other thread run */ |
---|
73 | |
---|
74 | benchmark_timer_initialize(); |
---|
75 | status = pthread_mutex_unlock( &MutexId ); |
---|
76 | end_time = benchmark_timer_read(); |
---|
77 | rtems_test_assert( status == 0 ); |
---|
78 | |
---|
79 | put_time( |
---|
80 | "pthread_mutex_unlock: unblocking no preemption", |
---|
81 | end_time, |
---|
82 | 1, |
---|
83 | 0, |
---|
84 | 0 |
---|
85 | ); |
---|
86 | |
---|
87 | TEST_END(); |
---|
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_MUTEXES 1 |
---|
100 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
101 | |
---|
102 | #define CONFIGURE_INIT |
---|
103 | |
---|
104 | #include <rtems/confdefs.h> |
---|
105 | /* end of file */ |
---|