1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
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.com/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/timerdrv.h> |
---|
21 | |
---|
22 | pthread_mutex_t MutexId; |
---|
23 | |
---|
24 | void *Blocker( |
---|
25 | void *argument |
---|
26 | ) |
---|
27 | { |
---|
28 | (void) pthread_mutex_lock( &MutexId ); |
---|
29 | /* should never return */ |
---|
30 | rtems_test_assert( FALSE ); |
---|
31 | |
---|
32 | return NULL; |
---|
33 | } |
---|
34 | |
---|
35 | void *POSIX_Init( |
---|
36 | void *argument |
---|
37 | ) |
---|
38 | { |
---|
39 | int status; |
---|
40 | pthread_t threadId; |
---|
41 | benchmark_timer_t end_time; |
---|
42 | |
---|
43 | puts( "\n\n*** POSIX TIME TEST PSXTMMUTEX05 ***" ); |
---|
44 | |
---|
45 | status = pthread_create( &threadId, NULL, Blocker, NULL ); |
---|
46 | rtems_test_assert( status == 0 ); |
---|
47 | |
---|
48 | /* |
---|
49 | * Deliberately create the mutex after the threads. This way if the |
---|
50 | * threads do run before we intend, they will get an error. |
---|
51 | */ |
---|
52 | status = pthread_mutex_init( &MutexId, NULL ); |
---|
53 | rtems_test_assert( status == 0 ); |
---|
54 | |
---|
55 | /* |
---|
56 | * Ensure the mutex is unavailable so the other threads block. |
---|
57 | */ |
---|
58 | status = pthread_mutex_lock( &MutexId ); |
---|
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 | benchmark_timer_initialize(); |
---|
69 | status = pthread_mutex_unlock( &MutexId ); |
---|
70 | end_time = benchmark_timer_read(); |
---|
71 | rtems_test_assert( status == 0 ); |
---|
72 | |
---|
73 | put_time( |
---|
74 | "pthread_mutex_unlock - unblocking, no preemption", |
---|
75 | end_time, |
---|
76 | 1, |
---|
77 | 0, |
---|
78 | 0 |
---|
79 | ); |
---|
80 | |
---|
81 | puts( "*** END OF POSIX TIME TEST PSXTMMUTEX05 ***" ); |
---|
82 | rtems_test_exit( 0 ); |
---|
83 | |
---|
84 | return NULL; |
---|
85 | } |
---|
86 | |
---|
87 | /* configuration information */ |
---|
88 | |
---|
89 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
90 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
91 | |
---|
92 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
93 | #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1 |
---|
94 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
95 | |
---|
96 | #define CONFIGURE_INIT |
---|
97 | |
---|
98 | #include <rtems/confdefs.h> |
---|
99 | /* end of file */ |
---|