mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-23 12:40:25 +08:00
fix timer cond & mu
This commit is contained in:
11
server.c
11
server.c
@@ -612,10 +612,13 @@ static void accept_timer(void *p) {
|
|||||||
}
|
}
|
||||||
sleep(MAXWAITSEC / 4);
|
sleep(MAXWAITSEC / 4);
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&timer->tmc);
|
pthread_cond_destroy(&timer->tc);
|
||||||
|
printf("Destroy timer cond, ");
|
||||||
|
pthread_mutex_destroy(&timer->tmc);
|
||||||
|
printf("Destroy timer mutex, ");
|
||||||
timer->timerthread = NULL;
|
timer->timerthread = NULL;
|
||||||
timer->hastimerslept = 0;
|
timer->hastimerslept = 0;
|
||||||
pthread_mutex_unlock(&timer->tmc);
|
puts("Clear timer thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup_thread(thread_timer_t* timer) {
|
static void cleanup_thread(thread_timer_t* timer) {
|
||||||
@@ -879,6 +882,7 @@ static void accept_client(int fd) {
|
|||||||
printf("Creating timer thread...");
|
printf("Creating timer thread...");
|
||||||
pthread_cond_init(&timer->tc, NULL);
|
pthread_cond_init(&timer->tc, NULL);
|
||||||
pthread_mutex_init(&timer->tmc, NULL);
|
pthread_mutex_init(&timer->tmc, NULL);
|
||||||
|
timer->hastimerslept = 0;
|
||||||
if (pthread_create(&timer->timerthread, &attr, (void *)&accept_timer, timer)) {
|
if (pthread_create(&timer->timerthread, &attr, (void *)&accept_timer, timer)) {
|
||||||
perror("Error creating timer thread");
|
perror("Error creating timer thread");
|
||||||
cleanup_thread(timer);
|
cleanup_thread(timer);
|
||||||
@@ -886,9 +890,6 @@ static void accept_client(int fd) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
puts("succeeded");
|
puts("succeeded");
|
||||||
pthread_mutex_lock(&timer->tmc);
|
|
||||||
timer->hastimerslept = 0;
|
|
||||||
pthread_mutex_unlock(&timer->tmc);
|
|
||||||
} else if(hastimerslept) {
|
} else if(hastimerslept) {
|
||||||
printf("Waking up timer thread...");
|
printf("Waking up timer thread...");
|
||||||
pthread_mutex_lock(&timer->tmc);
|
pthread_mutex_lock(&timer->tmc);
|
||||||
|
|||||||
Reference in New Issue
Block a user