minor fix

This commit is contained in:
Yatao Li 2022-01-23 03:54:20 +08:00
parent 8e96174e1f
commit de187eff1c

View File

@ -118,7 +118,7 @@ int tpool_add_work(tpool_t *pool, thread_func_t func, void *arg) {
* see: https://github.com/htop-dev/htop/blob/f782f821f7f8081cb43bbad1c37f32830a260a81/linux/LinuxProcessList.c * see: https://github.com/htop-dev/htop/blob/f782f821f7f8081cb43bbad1c37f32830a260a81/linux/LinuxProcessList.c
*/ */
__always_inline __always_inline
static size_t _get_total_mem_mb() { static size_t _get_total_mem() {
FILE* statmfile = fopen("/proc/self/statm", "r"); FILE* statmfile = fopen("/proc/self/statm", "r");
if (!statmfile) if (!statmfile)
return 0; return 0;
@ -137,7 +137,7 @@ static size_t _get_total_mem_mb() {
fclose(statmfile); fclose(statmfile);
if (r == 7) { if (r == 7) {
return m_resident * 4 / 1024; // XXX assume 4KB pages. return m_resident * 4096; // XXX assume 4KB pages.
} else { } else {
return 0; return 0;
} }
@ -167,16 +167,13 @@ static void *tpool_worker(void *arg) {
pthread_mutex_unlock(&(pool->work_mutex)); pthread_mutex_unlock(&(pool->work_mutex));
if (work != NULL) { if (work != NULL) {
if (pool->stop) { while(!pool->stop && ScanCtx.mem_limit > 0 && _get_total_mem() >= ScanCtx.mem_limit) {
break; usleep(10000);
} }
while(ScanCtx.mem_limit > 0 && _get_total_mem_mb() >= ScanCtx.mem_limit) {
if (pool->stop) { if (pool->stop) {
break; break;
} }
usleep(10000);
}
work->func(work->arg); work->func(work->arg);
if (pool->free_arg) { if (pool->free_arg) {