|
31 | 31 |
|
32 | 32 | /* Global Thread counter */ |
33 | 33 | uint counter; |
| 34 | +pthread_mutex_t init_mutex; |
34 | 35 | pthread_mutex_t counter_mutex; |
35 | 36 | pthread_cond_t count_threshhold; |
36 | 37 |
|
@@ -425,8 +426,13 @@ static MYSQL *db_connect(char *host, char *database, |
425 | 426 | MYSQL *mysql; |
426 | 427 | if (verbose) |
427 | 428 | fprintf(stdout, "Connecting to %s\n", host ? host : "localhost"); |
| 429 | + pthread_mutex_lock(&init_mutex); |
428 | 430 | if (!(mysql= mysql_init(NULL))) |
| 431 | + { |
| 432 | + pthread_mutex_unlock(&init_mutex); |
429 | 433 | return 0; |
| 434 | + } |
| 435 | + pthread_mutex_unlock(&init_mutex); |
430 | 436 | if (opt_compress) |
431 | 437 | mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS); |
432 | 438 | if (opt_local_file) |
@@ -645,6 +651,7 @@ int main(int argc, char **argv) |
645 | 651 | pthread_attr_setdetachstate(&attr, |
646 | 652 | PTHREAD_CREATE_JOINABLE); |
647 | 653 |
|
| 654 | + pthread_mutex_init(&init_mutex, NULL); |
648 | 655 | pthread_mutex_init(&counter_mutex, NULL); |
649 | 656 | pthread_cond_init(&count_threshhold, NULL); |
650 | 657 |
|
@@ -699,6 +706,7 @@ int main(int argc, char **argv) |
699 | 706 | pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime); |
700 | 707 | } |
701 | 708 | pthread_mutex_unlock(&counter_mutex); |
| 709 | + pthread_mutex_destroy(&init_mutex); |
702 | 710 | pthread_mutex_destroy(&counter_mutex); |
703 | 711 | pthread_cond_destroy(&count_threshhold); |
704 | 712 | pthread_attr_destroy(&attr); |
|
0 commit comments