comparison packages/kernel/current/tests/sync3.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents bf00f99aec69
children eb9fd8c04db3
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
46 // With priority inheritance enabled, t2 will inherit its priority 46 // With priority inheritance enabled, t2 will inherit its priority
47 // from t0 when t0 tries to grab the mutex. 47 // from t0 when t0 tries to grab the mutex.
48 // 48 //
49 // Options: 49 // Options:
50 // CYGIMP_THREAD_PRIORITY 50 // CYGIMP_THREAD_PRIORITY
51 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 51 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_INHERIT
52 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE 52 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE
53 //####DESCRIPTIONEND#### 53 //####DESCRIPTIONEND####
54 54
55 #include <pkgconf/kernel.h> 55 #include <pkgconf/kernel.h>
56 56
57 #include <cyg/kernel/thread.hxx> 57 #include <cyg/kernel/thread.hxx>
66 66
67 #ifndef CYGIMP_THREAD_PRIORITY 67 #ifndef CYGIMP_THREAD_PRIORITY
68 #error "Thread priorities disabled" 68 #error "Thread priorities disabled"
69 #endif 69 #endif
70 70
71 // ------------------------------------------------------------------------
72 // Manufacture a simpler feature test macro for priority inheritance than
73 // the configuration gives us. We have priority inheritance if it is configured
74 // as the only protocol, or if it is the default protocol for dynamic protocol
75 // choice.
76 // FIXME: If we have dynamic protocol choice, we can also set priority inheritance
77 // as the protocol to be used on the mutexes we are interested in. At present we
78 // do not do this.
79
80 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_INHERIT
81 # ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC
82 # ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DEFAULT_INHERIT
83 # define PRIORITY_INHERITANCE
84 # else
85 # undef PRIORITY_INHERITANCE
86 # endif
87 # else
88 # define PRIORITY_INHERITANCE
89 # endif
90 #else
91 # undef PRIORITY_INHERITANCE
92 #endif
93
94 // ------------------------------------------------------------------------
95
71 #define NTHREADS 3 96 #define NTHREADS 3
72 97
73 #include "testaux.hxx" 98 #include "testaux.hxx"
74 99
75 static Cyg_Mutex m0; 100 static Cyg_Mutex m0;
86 111
87 static void check_priorities_inherited() 112 static void check_priorities_inherited()
88 { 113 {
89 CHECK( 5 == thread[0]->get_priority()); 114 CHECK( 5 == thread[0]->get_priority());
90 CHECK( 6 == thread[1]->get_priority()); 115 CHECK( 6 == thread[1]->get_priority());
91 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 116 #ifdef PRIORITY_INHERITANCE
92 CHECK( 5 == thread[2]->get_current_priority()); 117 CHECK( 5 == thread[2]->get_current_priority());
93 #endif 118 #endif
94 CHECK( 7 == thread[2]->get_priority()); 119 CHECK( 7 == thread[2]->get_priority());
95 120
96 } 121 }
103 check_priorities_normal(); 128 check_priorities_normal();
104 CHECK( 2 == m0d ); 129 CHECK( 2 == m0d );
105 m0d = 0; 130 m0d = 0;
106 } m0.unlock(); 131 } m0.unlock();
107 check_priorities_normal(); 132 check_priorities_normal();
108 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 133 #ifdef PRIORITY_INHERITANCE
109 CYG_TEST_PASS_FINISH("Sync 3 OK -- priority inheritance worked"); 134 CYG_TEST_PASS_FINISH("Sync 3 OK -- priority inheritance worked");
110 #else 135 #else
111 CYG_TEST_FAIL_FINISH("Sync 3: thread not starved"); 136 CYG_TEST_FAIL_FINISH("Sync 3: thread not starved");
112 #endif 137 #endif
113 // NOT REACHED 138 // NOT REACHED
120 // mechanism when scheduler does not guarantee to schedule threads 145 // mechanism when scheduler does not guarantee to schedule threads
121 // in strict priority order. 146 // in strict priority order.
122 for ( volatile cyg_ucount32 i=0; i < 100000; i++ ) 147 for ( volatile cyg_ucount32 i=0; i < 100000; i++ )
123 ; // math is hard 148 ; // math is hard
124 149
125 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 150 #ifdef PRIORITY_INHERITANCE
126 // thread0 should have stopped by this point 151 // thread0 should have stopped by this point
127 CYG_TEST_FAIL_FINISH("Sync 3: priority inheritance mechanism failed"); 152 CYG_TEST_FAIL_FINISH("Sync 3: priority inheritance mechanism failed");
128 #else 153 #else
129 // With strict priority scheduling and no priority inheritance 154 // With strict priority scheduling and no priority inheritance
130 // this is expected to happen. 155 // this is expected to happen.