Blame libringbuffer/smp.c

Packit c04fcb
/*
Packit c04fcb
 * libringbuffer/smp.c
Packit c04fcb
 *
Packit c04fcb
 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Packit c04fcb
 *
Packit c04fcb
 * This library is free software; you can redistribute it and/or
Packit c04fcb
 * modify it under the terms of the GNU Lesser General Public
Packit c04fcb
 * License as published by the Free Software Foundation; only
Packit c04fcb
 * version 2.1 of the License.
Packit c04fcb
 *
Packit c04fcb
 * This library is distributed in the hope that it will be useful,
Packit c04fcb
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c04fcb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit c04fcb
 * Lesser General Public License for more details.
Packit c04fcb
 *
Packit c04fcb
 * You should have received a copy of the GNU Lesser General Public
Packit c04fcb
 * License along with this library; if not, write to the Free Software
Packit c04fcb
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
#define _GNU_SOURCE
Packit c04fcb
#include <unistd.h>
Packit c04fcb
#include <pthread.h>
Packit c04fcb
#include "smp.h"
Packit c04fcb
Packit c04fcb
int __num_possible_cpus;
Packit c04fcb
Packit c04fcb
void _get_num_possible_cpus(void)
Packit c04fcb
{
Packit c04fcb
	int result;
Packit c04fcb
Packit c04fcb
	/* On Linux, when some processors are offline
Packit c04fcb
	 * _SC_NPROCESSORS_CONF counts the offline
Packit c04fcb
	 * processors, whereas _SC_NPROCESSORS_ONLN
Packit c04fcb
	 * does not. If we used _SC_NPROCESSORS_ONLN,
Packit c04fcb
	 * getcpu() could return a value greater than
Packit c04fcb
	 * this sysconf, in which case the arrays
Packit c04fcb
	 * indexed by processor would overflow.
Packit c04fcb
	 */
Packit c04fcb
	result = sysconf(_SC_NPROCESSORS_CONF);
Packit c04fcb
	if (result == -1)
Packit c04fcb
		return;
Packit c04fcb
	__num_possible_cpus = result;
Packit c04fcb
}