X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libust%2Fbuffers.c;h=776823ea2789e718c1a82ea11de93f8bcb7d215a;hb=c7dc133cff3db7336bb97fcb57c2dec559942518;hp=9651beb916db5d78b8acbae83ded896513963c3f;hpb=a09dac63957396890b1085cac0fee92ecc5db87a;p=lttng-ust.git diff --git a/libust/buffers.c b/libust/buffers.c index 9651beb9..776823ea 100644 --- a/libust/buffers.c +++ b/libust/buffers.c @@ -49,26 +49,24 @@ static int get_n_cpus(void) int result; static int n_cpus = 0; - if(n_cpus) { - return n_cpus; - } + if(!n_cpus) { + /* On Linux, when some processors are offline + * _SC_NPROCESSORS_CONF counts the offline + * processors, whereas _SC_NPROCESSORS_ONLN + * does not. If we used _SC_NPROCESSORS_ONLN, + * getcpu() could return a value greater than + * this sysconf, in which case the arrays + * indexed by processor would overflow. + */ + result = sysconf(_SC_NPROCESSORS_CONF); + if(result == -1) { + return -1; + } - /* On Linux, when some processors are offline - * _SC_NPROCESSORS_CONF counts the offline - * processors, whereas _SC_NPROCESSORS_ONLN - * does not. If we used _SC_NPROCESSORS_ONLN, - * getcpu() could return a value greater than - * this sysconf, in which case the arrays - * indexed by processor would overflow. - */ - result = sysconf(_SC_NPROCESSORS_CONF); - if(result == -1) { - return -1; + n_cpus = result; } - n_cpus = result; - - return result; + return n_cpus; } /* _ust_buffers_write()