Speaking of testing features rather than the OS/compiler/library, I have heard
quite a lot about it but I am not sure I understand it. Here is an example
where I want to write a function bind_thread() that can run on both Solaris and
Linux:
[code]
#if defined (__sun)
#include <sys/pset.h> /* P_PID, processor_bind() */
#include <unistd.h> /* getpid() */
#elif (defined (__gnu_linux__) || defined (__gnu__linux) || defined (__linux__))
#define _GNU_SOURCE
#include <sched.h> /* CPU_SET, CPU_ZERO, cpu_set_t, sched_setaffinity() */
#endif
#if defined (__sun)
int bind_thread(unsigned int cpu_id)
{
int ret;
ret = processor_bind(P_PID, getpid(), cpu_id, NULL);
if (ret == -1)
perror("bind_thread:processor_bind");
return ret;
}
#endif
#if (defined (__gnu_linux__) || defined (__gnu__linux) || defined (__linux__))
int bind_thread(unsigned int cpu_id)
{
int ret = 0;
cpu_set_t mask;
unsigned int len = sizeof(mask);
CPU_ZERO(&mask);
CPU_SET(cpu_id, &mask);
ret = sched_setaffinity(0, len, &mask);
if (ret == -1)
perror("bind_thread:sched_setaffinity");
return ret;
}
#endif
[/code]
Here, the prototype of processor_bind() is actually in <sys/processor.h> which
is #included in <sys/pset.h>. Instead of testing the OS (Solaris vs Linux),
can anyone tell me how to "test for individual feature" in this case?
--
This message posted from opensolaris.org
_______________________________________________
opensolaris-discuss mailing list
[email protected]