MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
thr_template.cc
1 /* Copyright (c) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc.
2  Use is subject to license terms.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16 
17 
18 volatile int32 bad;
19 pthread_attr_t thr_attr;
20 mysql_mutex_t mutex;
21 mysql_cond_t cond;
22 uint running_threads;
23 const int THREADS= 30;
24 const int CYCLES= 3000;
25 
26 void test_concurrently(const char *test, pthread_handler handler, int n, int m)
27 {
28  pthread_t t;
29  ulonglong now= my_getsystime();
30 
31  bad= 0;
32 
33  for (running_threads= n ; n ; n--)
34  {
35  if (pthread_create(&t, &thr_attr, handler, &m) != 0)
36  {
37  ADD_FAILURE() << "Could not create thread";
38  abort();
39  }
40  }
41  mysql_mutex_lock(&mutex);
42  while (running_threads)
43  mysql_cond_wait(&cond, &mutex);
44  mysql_mutex_unlock(&mutex);
45 
46  now= my_getsystime()-now;
47  EXPECT_FALSE(bad)
48  << "tested " << test
49  << " in " << ((double)now)/1e7 << " secs "
50  << "(" << bad << ")";
51 }