16
16
#include "thr_template.c"
17
17
#include <waiting_threads.h>
18
18
#include <m_string.h>
19
+ #include <my_rnd.h>
19
20
20
21
struct test_wt_thd {
21
22
WT_THD thd ;
22
- pthread_mutex_t lock ;
23
+ mysql_mutex_t lock ;
23
24
} thds [THREADS ];
24
25
25
26
uint i , cnt ;
26
- pthread_mutex_t lock ;
27
- pthread_cond_t thread_sync ;
27
+ mysql_mutex_t lock ;
28
+ mysql_cond_t thread_sync ;
28
29
29
30
ulong wt_timeout_short = 100 , wt_deadlock_search_depth_short = 4 ;
30
31
ulong wt_timeout_long = 10000 , wt_deadlock_search_depth_long = 15 ;
@@ -49,19 +50,19 @@ pthread_handler_t test_wt(void *arg)
49
50
50
51
my_thread_init ();
51
52
52
- pthread_mutex_lock (& mutex );
53
+ mysql_mutex_lock (& mutex );
53
54
id = cnt ++ ;
54
55
wt_thd_lazy_init (& thds [id ].thd ,
55
56
& wt_deadlock_search_depth_short , & wt_timeout_short ,
56
57
& wt_deadlock_search_depth_long , & wt_timeout_long );
57
58
58
59
/* now, wait for everybody to be ready to run */
59
60
if (cnt >= THREADS )
60
- pthread_cond_broadcast (& thread_sync );
61
+ mysql_cond_broadcast (& thread_sync );
61
62
else
62
63
while (cnt < THREADS )
63
- pthread_cond_wait (& thread_sync , & mutex );
64
- pthread_mutex_unlock (& mutex );
64
+ mysql_cond_wait (& thread_sync , & mutex );
65
+ mysql_mutex_unlock (& mutex );
65
66
66
67
my_rnd_init (& rand , (ulong )(intptr )& m , id );
67
68
if (kill_strategy == YOUNGEST )
@@ -72,7 +73,7 @@ pthread_handler_t test_wt(void *arg)
72
73
for (m = * (int * )arg ; m ; m -- )
73
74
{
74
75
WT_RESOURCE_ID resid ;
75
- int blockers [THREADS /10 ], j , k ;
76
+ int blockers [THREADS /10 ]= { 0 } , j , k ;
76
77
77
78
resid .value = id ;
78
79
resid .type = & restype ;
@@ -94,25 +95,25 @@ pthread_handler_t test_wt(void *arg)
94
95
if (kill_strategy == RANDOM )
95
96
thds [id ].thd .weight = rnd ();
96
97
97
- pthread_mutex_lock (& thds [i ].lock );
98
+ mysql_mutex_lock (& thds [i ].lock );
98
99
res = wt_thd_will_wait_for (& thds [id ].thd , & thds [i ].thd , & resid );
99
- pthread_mutex_unlock (& thds [i ].lock );
100
+ mysql_mutex_unlock (& thds [i ].lock );
100
101
}
101
102
102
103
if (!res )
103
104
{
104
- pthread_mutex_lock (& lock );
105
+ mysql_mutex_lock (& lock );
105
106
res = wt_thd_cond_timedwait (& thds [id ].thd , & lock );
106
- pthread_mutex_unlock (& lock );
107
+ mysql_mutex_unlock (& lock );
107
108
}
108
109
109
110
if (res )
110
111
{
111
- pthread_mutex_lock (& thds [id ].lock );
112
- pthread_mutex_lock (& lock );
112
+ mysql_mutex_lock (& thds [id ].lock );
113
+ mysql_mutex_lock (& lock );
113
114
wt_thd_release_all (& thds [id ].thd );
114
- pthread_mutex_unlock (& lock );
115
- pthread_mutex_unlock (& thds [id ].lock );
115
+ mysql_mutex_unlock (& lock );
116
+ mysql_mutex_unlock (& thds [id ].lock );
116
117
if (kill_strategy == LOCKS )
117
118
thds [id ].thd .weight = 0 ;
118
119
if (kill_strategy == YOUNGEST )
@@ -122,21 +123,21 @@ pthread_handler_t test_wt(void *arg)
122
123
thds [id ].thd .weight ++ ;
123
124
}
124
125
125
- pthread_mutex_lock (& mutex );
126
+ mysql_mutex_lock (& mutex );
126
127
/* wait for everybody to finish */
127
128
if (!-- cnt )
128
- pthread_cond_broadcast (& thread_sync );
129
+ mysql_cond_broadcast (& thread_sync );
129
130
else
130
131
while (cnt )
131
- pthread_cond_wait (& thread_sync , & mutex );
132
+ mysql_cond_wait (& thread_sync , & mutex );
132
133
133
- pthread_mutex_lock (& thds [id ].lock );
134
- pthread_mutex_lock (& lock );
134
+ mysql_mutex_lock (& thds [id ].lock );
135
+ mysql_mutex_lock (& lock );
135
136
wt_thd_release_all (& thds [id ].thd );
136
- pthread_mutex_unlock (& lock );
137
- pthread_mutex_unlock (& thds [id ].lock );
137
+ mysql_mutex_unlock (& lock );
138
+ mysql_mutex_unlock (& thds [id ].lock );
138
139
wt_thd_destroy (& thds [id ].thd );
139
- pthread_mutex_unlock (& mutex );
140
+ mysql_mutex_unlock (& mutex );
140
141
141
142
DBUG_PRINT ("wt" , ("exiting" ));
142
143
my_thread_end ();
@@ -152,7 +153,8 @@ void do_one_test()
152
153
reset (wt_wait_stats );
153
154
wt_success_stats = 0 ;
154
155
cnt = 0 ;
155
- test_concurrently ("waiting_threads" , test_wt , THREADS , CYCLES );
156
+ test_concurrently ("waiting_threads" , test_wt , THREADS ,
157
+ CYCLES /(skip_big_tests ?500 :10 ));
156
158
157
159
sum = sum0 = 0 ;
158
160
for (cnt = 0 ; cnt < WT_CYCLE_STATS ; cnt ++ )
@@ -179,21 +181,16 @@ void do_one_test()
179
181
void do_tests ()
180
182
{
181
183
DBUG_ENTER ("do_tests" );
182
- if (skip_big_tests )
183
- {
184
- skip (1 , "Big test skipped" );
185
- return ;
186
- }
187
184
plan (13 );
188
185
compile_time_assert (THREADS >= 4 );
189
186
190
187
DBUG_PRINT ("wt" , ("================= initialization ===================" ));
191
188
192
- pthread_cond_init ( & thread_sync , 0 );
193
- pthread_mutex_init ( & lock , 0 );
189
+ mysql_cond_init ( PSI_NOT_INSTRUMENTED , & thread_sync , 0 );
190
+ mysql_mutex_init ( PSI_NOT_INSTRUMENTED , & lock , 0 );
194
191
wt_init ();
195
192
for (cnt = 0 ; cnt < THREADS ; cnt ++ )
196
- pthread_mutex_init ( & thds [cnt ].lock , 0 );
193
+ mysql_mutex_init ( PSI_NOT_INSTRUMENTED , & thds [cnt ].lock , 0 );
197
194
{
198
195
WT_RESOURCE_ID resid [4 ];
199
196
for (i = 0 ; i < array_elements (resid ); i ++ )
@@ -218,16 +215,16 @@ void do_tests()
218
215
ok_wait (0 ,2 ,0 );
219
216
ok_wait (0 ,3 ,0 );
220
217
221
- pthread_mutex_lock (& lock );
218
+ mysql_mutex_lock (& lock );
222
219
bad = wt_thd_cond_timedwait (& thds [0 ].thd , & lock );
223
- pthread_mutex_unlock (& lock );
220
+ mysql_mutex_unlock (& lock );
224
221
ok (bad == WT_TIMEOUT , "timeout test returned %d" , bad );
225
222
226
223
ok_wait (0 ,1 ,0 );
227
224
ok_wait (1 ,2 ,1 );
228
225
ok_deadlock (2 ,0 ,2 );
229
226
230
- pthread_mutex_lock (& lock );
227
+ mysql_mutex_lock (& lock );
231
228
ok (wt_thd_cond_timedwait (& thds [0 ].thd , & lock ) == WT_TIMEOUT , "as always" );
232
229
ok (wt_thd_cond_timedwait (& thds [1 ].thd , & lock ) == WT_TIMEOUT , "as always" );
233
230
wt_thd_release_all (& thds [0 ].thd );
@@ -240,7 +237,7 @@ void do_tests()
240
237
wt_thd_release_all (& thds [i ].thd );
241
238
wt_thd_destroy (& thds [i ].thd );
242
239
}
243
- pthread_mutex_unlock (& lock );
240
+ mysql_mutex_unlock (& lock );
244
241
}
245
242
246
243
wt_deadlock_search_depth_short = 6 ;
@@ -277,10 +274,10 @@ void do_tests()
277
274
278
275
DBUG_PRINT ("wt" , ("================= cleanup ===================" ));
279
276
for (cnt = 0 ; cnt < THREADS ; cnt ++ )
280
- pthread_mutex_destroy (& thds [cnt ].lock );
277
+ mysql_mutex_destroy (& thds [cnt ].lock );
281
278
wt_end ();
282
- pthread_mutex_destroy (& lock );
283
- pthread_cond_destroy (& thread_sync );
279
+ mysql_mutex_destroy (& lock );
280
+ mysql_cond_destroy (& thread_sync );
284
281
DBUG_VOID_RETURN ;
285
282
}
286
283
0 commit comments