1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-21 11:20:34 +08:00

add more log

This commit is contained in:
源文雨
2022-10-15 10:10:40 +08:00
parent e258bf67f5
commit 3aa0067b50
2 changed files with 13 additions and 3 deletions

View File

@@ -10,6 +10,10 @@ ELSE()
add_definitions("-DCPUBIT32") add_definitions("-DCPUBIT32")
ENDIF() ENDIF()
if(DEFINED ENV{DEBUG})
message("compile in debug mode")
add_definitions(-DDEBUG)
endif()
if(DEFINED ENV{DICTKEYSZ}) if(DEFINED ENV{DICTKEYSZ})
message("custom dict key size: $ENV{DICTKEYSZ}") message("custom dict key size: $ENV{DICTKEYSZ}")
add_definitions(-DDICTKEYSZ=$ENV{DICTKEYSZ}) add_definitions(-DDICTKEYSZ=$ENV{DICTKEYSZ})

View File

@@ -557,16 +557,18 @@ static int s5_md5(thread_timer_t *timer) {
static void handle_quit(int signo) { static void handle_quit(int signo) {
puts("Handle sigquit"); puts("Handle sigquit");
fflush(stdout);
pthread_exit(NULL); pthread_exit(NULL);
} }
static void handle_segv(int signo) { static void handle_segv(int signo) {
puts("Handle segv"); puts("Handle sigsegv");
fflush(stdout);
pthread_exit(NULL); pthread_exit(NULL);
} }
static void handle_kill(int signo) { static void handle_kill(int signo) {
puts("Handle kill/term"); puts("Handle sigkill/sigterm");
for(int i = 0; i < THREADCNT; i++) { for(int i = 0; i < THREADCNT; i++) {
if(timers[i].thread) pthread_kill(timers[i].thread, SIGQUIT); if(timers[i].thread) pthread_kill(timers[i].thread, SIGQUIT);
if(timers[i].timerthread) pthread_kill(timers[i].timerthread, SIGQUIT); if(timers[i].timerthread) pthread_kill(timers[i].timerthread, SIGQUIT);
@@ -594,7 +596,7 @@ static void accept_timer(void *p) {
puts("Timer sleep"); puts("Timer sleep");
pthread_cond_wait(&timer->tc, &timer->tmc); pthread_cond_wait(&timer->tc, &timer->tmc);
pthread_mutex_unlock(&timer->tmc); pthread_mutex_unlock(&timer->tmc);
puts("Timer woke up"); puts("Timer wake up");
} }
if(is_dict_opening) touch_timer(p); if(is_dict_opening) touch_timer(p);
time_t waitsec = time(NULL) - timer->touch; time_t waitsec = time(NULL) - timer->touch;
@@ -643,6 +645,7 @@ static void handle_int(int signo) {
static void handle_pipe(int signo) { static void handle_pipe(int signo) {
puts("Pipe error, exit thread..."); puts("Pipe error, exit thread...");
fflush(stdout);
pthread_exit(NULL); pthread_exit(NULL);
} }
@@ -654,16 +657,19 @@ static void handle_accept(void *p) {
while(1) { while(1) {
pthread_t thread = timer_pointer_of(p)->timerthread; pthread_t thread = timer_pointer_of(p)->timerthread;
if(!thread || pthread_kill(thread, 0)) { if(!thread || pthread_kill(thread, 0)) {
printf("Creating timer thread...");
pthread_cond_init(&timer_pointer_of(p)->tc, NULL); pthread_cond_init(&timer_pointer_of(p)->tc, NULL);
pthread_mutex_init(&timer_pointer_of(p)->tmc, NULL); pthread_mutex_init(&timer_pointer_of(p)->tmc, NULL);
if (pthread_create(&thread, &attr, (void *)&accept_timer, p)) { if (pthread_create(&thread, &attr, (void *)&accept_timer, p)) {
perror("Error creating timer thread"); perror("Error creating timer thread");
cleanup_thread(timer_pointer_of(p)); cleanup_thread(timer_pointer_of(p));
putchar('\n');
return; return;
} }
timer_pointer_of(p)->timerthread = thread; timer_pointer_of(p)->timerthread = thread;
puts("Creating timer thread succeeded"); puts("Creating timer thread succeeded");
} else { } else {
printf("Waking up timer thread...");
pthread_mutex_lock(&timer_pointer_of(p)->tmc); pthread_mutex_lock(&timer_pointer_of(p)->tmc);
pthread_cond_signal(&timer_pointer_of(p)->tc); // wakeup thread pthread_cond_signal(&timer_pointer_of(p)->tc); // wakeup thread
pthread_mutex_unlock(&timer_pointer_of(p)->tmc); pthread_mutex_unlock(&timer_pointer_of(p)->tmc);