diff options
author | lantw44 <lantw44@gmail.com> | 2013-01-26 20:29:09 +0800 |
---|---|---|
committer | lantw44 <lantw44@gmail.com> | 2013-01-26 20:29:09 +0800 |
commit | c41f897304100c89451e91acb0a47b3f07fc7b51 (patch) | |
tree | 474fb9045318b674cf01c70f087cb6efabbdf3a9 /src/checktle.c | |
parent | e5ee20baf2abee4527a01193a30ea27a33ca1e31 (diff) | |
download | sctjudge-c41f897304100c89451e91acb0a47b3f07fc7b51.tar.gz sctjudge-c41f897304100c89451e91acb0a47b3f07fc7b51.tar.zst sctjudge-c41f897304100c89451e91acb0a47b3f07fc7b51.zip |
清除所有 pthread_cancel()
已使用 sem_timedwait 和 sem_post 取代所有以往需要 pthread_cancel 的地方
Diffstat (limited to 'src/checktle.c')
-rw-r--r-- | src/checktle.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/checktle.c b/src/checktle.c index 9aec3f7..461147b 100644 --- a/src/checktle.c +++ b/src/checktle.c @@ -17,24 +17,21 @@ volatile sig_atomic_t break_flag; static void break_handler(int signo){ break_flag = 1; + sem_post(&tlethr); } void* sctjudge_checktle(void* arg){ pid_t pidcopy; long long sleeptime = (long long)(*(int*)arg) * 1000000; struct sigaction break_catch; - struct timespec timelimit, timeinit, timecur, timetmp; + struct timespec timelimit, timeinit, timecur, timeexpire; const struct timespec nanslparg = {0, SCT_CHECKTLE_INTERVAL}; pthread_mutex_lock(&tkill_mx); tkill_yes = 1; pthread_mutex_unlock(&tkill_mx); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); - - sem_wait(&addthr); - pthread_testcancel(); + sem_wait(&tlethr); clock_gettime(CLOCK_REALTIME, &timeinit); #ifndef HAVE_CONF_CAP @@ -54,19 +51,13 @@ void* sctjudge_checktle(void* arg){ timelimit.tv_sec = timeinit.tv_sec + sleeptime / 1000000000; timelimit.tv_nsec = timeinit.tv_nsec + sleeptime % 1000000000; - pthread_testcancel(); - - for(clock_gettime(CLOCK_REALTIME, &timecur); - comparetimespec(&timecur, &timelimit) < 0 && !break_flag; - clock_gettime(CLOCK_REALTIME, &timecur)){ - difftimespec(&timecur, &timelimit, &timetmp); - if(comparetimespec(&timetmp, &nanslparg) > 0){ - nanosleep(&nanslparg, NULL); - }else{ - nanosleep(&timetmp, NULL); - } - pthread_testcancel(); - } + do{ + clock_gettime(CLOCK_REALTIME, &timecur); + timeexpire.tv_sec = timecur.tv_sec; + timeexpire.tv_nsec = timecur.tv_nsec + SCT_CHECKTLE_INTERVAL; + checktimespec(&timeexpire); + }while(comparetimespec(&timecur, &timelimit) < 0 && + sem_timedwait(&tlethr, &timeexpire)); if(!break_flag){ pthread_mutex_lock(&judge_tle_mx); |