mirror of
https://github.com/simon987/sist2.git
synced 2025-04-19 18:26:43 +00:00
minor fix
This commit is contained in:
parent
8e96174e1f
commit
de187eff1c
11
src/tpool.c
11
src/tpool.c
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user