MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / test_thread

Function test_thread

mysys/thr_lock.c:1551–1599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1549
1550
1551static void *test_thread(void *arg)
1552{
1553 int i,j,param=*((int*) arg);
1554 THR_LOCK_DATA data[MAX_LOCK_COUNT];
1555 THR_LOCK_INFO lock_info;
1556 THR_LOCK_DATA *multi_locks[MAX_LOCK_COUNT];
1557 my_thread_init();
1558
1559 printf("Thread %s (%d) started\n",my_thread_name(),param); fflush(stdout);
1560
1561
1562 thr_lock_info_init(&lock_info);
1563 for (i=0; i < lock_counts[param] ; i++)
1564 thr_lock_data_init(locks+tests[param][i].lock_nr,data+i,NULL);
1565 for (j=1 ; j < 10 ; j++) /* try locking 10 times */
1566 {
1567 for (i=0; i < lock_counts[param] ; i++)
1568 { /* Init multi locks */
1569 multi_locks[i]= &data[i];
1570 data[i].type= tests[param][i].lock_type;
1571 }
1572 thr_multi_lock(multi_locks, lock_counts[param], &lock_info, TEST_TIMEOUT);
1573 mysql_mutex_lock(&LOCK_thread_count);
1574 {
1575 int tmp=rand() & 7; /* Do something from 0-2 sec */
1576 if (tmp == 0)
1577 sleep(1);
1578 else if (tmp == 1)
1579 sleep(2);
1580 else
1581 {
1582 ulong k;
1583 for (k=0 ; k < (ulong) (tmp-2)*100000L ; k++)
1584 sum+=k;
1585 }
1586 }
1587 mysql_mutex_unlock(&LOCK_thread_count);
1588 thr_multi_unlock(multi_locks,lock_counts[param]);
1589 }
1590
1591 printf("Thread %s (%d) ended\n",my_thread_name(),param); fflush(stdout);
1592 thr_print_locks();
1593 mysql_mutex_lock(&LOCK_thread_count);
1594 thread_count--;
1595 mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */
1596 mysql_mutex_unlock(&LOCK_thread_count);
1597 free((uchar*) arg);
1598 return 0;
1599}
1600
1601
1602int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))

Callers

nothing calls this directly

Calls 7

my_thread_initFunction · 0.85
my_thread_nameFunction · 0.85
thr_lock_info_initFunction · 0.85
thr_lock_data_initFunction · 0.85
thr_multi_lockFunction · 0.85
thr_multi_unlockFunction · 0.85
thr_print_locksFunction · 0.85

Tested by

no test coverage detected