From 0fe90e35dab35dd34c770ccd4d17e8989764bb5f Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 4 Nov 2015 15:02:56 +0800 Subject: [PATCH] add function get_sys_cpu_count() --- HISTORY | 5 +++-- src/shared_func.c | 9 +++++++++ src/shared_func.h | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index f02cfe6..0527e9a 100644 --- a/HISTORY +++ b/HISTORY @@ -1,10 +1,11 @@ -Version 1.23 2015-11-03 +Version 1.23 2015-11-04 * sched_thread.c: task can execute in a new thread * sched_thread.c: support delay tasks * add function get_current_time_us and get_current_time_ms * mblock add stat function - * add function get_sys_total_mem_size, ONLY support Linux and FreeBSD + * add function get_sys_total_mem_size and get_sys_cpu_count, + ONLY support Linux and FreeBSD * delay task can execute in a new thread * fast_mblock reclaimed object pool diff --git a/src/shared_func.c b/src/shared_func.c index 83b57e6..20fc70b 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -2312,3 +2312,12 @@ int get_sys_total_mem_size(int64_t *mem_size) #endif } +int get_sys_cpu_count() +{ +#if defined(OS_LINUX) || defined(OS_FREEBSD) + return sysconf(_SC_NPROCESSORS_ONLN); +#else +#error port me! +#endif +} + diff --git a/src/shared_func.h b/src/shared_func.h index bd9cf48..e216a44 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -535,6 +535,13 @@ int64_t get_current_time_us(); */ int get_sys_total_mem_size(int64_t *mem_size); + +/** get system CPU count + * parameters: + * return: error no , 0 success, != 0 fail +*/ +int get_sys_cpu_count(); + #ifdef __cplusplus } #endif