Files
0ad/source/lib/sysdep/unix/ucpu.cpp
T
Ykkrosh a3c21bdfa4 Implemented ucpu_CallByEachCPU
This was SVN commit r5158.
2007-06-09 22:45:50 +00:00

66 lines
1.1 KiB
C++

#include "precompiled.h"
#include "ucpu.h"
#if OS_MACOSX
#include <sys/sysctl.h>
#endif
int ucpu_IsThrottlingPossible()
{
return -1; // don't know
}
int ucpu_NumPackages()
{
#if OS_MACOSX
int mib[]={CTL_HW, HW_NCPU};
int ncpus;
size_t len = sizeof(ncpus);
if (sysctl(mib, 2, &ncpus, &len, NULL, 0) == -1)
return -1; // don't know
else
return ncpus;
#else
long res = sysconf(_SC_NPROCESSORS_CONF);
if (res == -1)
return 1;
else
return (int)res;
#endif
}
double ucpu_ClockFrequency()
{
return -1; // don't know
}
#if OS_LINUX
LibError ucpu_CallByEachCPU(CpuCallback cb, void* param)
{
long ncpus = sysconf(_SC_NPROCESSORS_CONF);
cpu_set_t set;
for (long i = 0; i < ncpus && i < CPU_SETSIZE; ++i)
{
CPU_ZERO(&set);
CPU_SET(i, &set);
int ret = sched_setaffinity(0, sizeof(set), &set);
if (ret)
WARN_RETURN(ERR::FAIL);
// (The process gets migrated immediately by the setaffinity call)
cb(param);
}
return INFO::OK;
}
#else
LibError ucpu_CallByEachCPU(CpuCallback cb, void* param)
{
// TODO: implement
return ERR::NOT_IMPLEMENTED;
}
#endif