summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-08-02 22:41:34 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-08-02 22:41:34 (GMT)
commit2740af8cc48b0f310557c0630d613301b7a5c2d4 (patch)
treee0e43ab66e547579f31fd01f221bf011eb909943
parent94b580d423524188bcf7136f9829fb68eb6d15d3 (diff)
downloadcpython-2740af8cc48b0f310557c0630d613301b7a5c2d4.zip
cpython-2740af8cc48b0f310557c0630d613301b7a5c2d4.tar.gz
cpython-2740af8cc48b0f310557c0630d613301b7a5c2d4.tar.bz2
sched.h can exist without sched affinity support
-rw-r--r--Lib/test/test_posix.py10
-rw-r--r--Modules/posixmodule.c8
-rwxr-xr-xconfigure1
-rw-r--r--configure.in1
-rw-r--r--pyconfig.h.in3
5 files changed, 19 insertions, 4 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index b649cd9..1c2a4da 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -831,6 +831,8 @@ class PosixTester(unittest.TestCase):
requires_sched_h = unittest.skipUnless(hasattr(posix, 'sched_yield'),
"don't have scheduling support")
+ requires_sched_affinity = unittest.skipUnless(hasattr(posix, 'cpu_set'),
+ "dont' have sched affinity support")
@requires_sched_h
def test_sched_yield(self):
@@ -888,7 +890,7 @@ class PosixTester(unittest.TestCase):
self.assertGreaterEqual(interval, 0.)
self.assertLess(interval, 1.)
- @requires_sched_h
+ @requires_sched_affinity
def test_sched_affinity(self):
mask = posix.sched_getaffinity(0, 1024)
self.assertGreaterEqual(mask.count(), 1)
@@ -899,7 +901,7 @@ class PosixTester(unittest.TestCase):
self.assertRaises(OSError, posix.sched_setaffinity, 0, empty)
self.assertRaises(OSError, posix.sched_setaffinity, -1, mask)
- @requires_sched_h
+ @requires_sched_affinity
def test_cpu_set_basic(self):
s = posix.cpu_set(10)
self.assertEqual(len(s), 10)
@@ -924,7 +926,7 @@ class PosixTester(unittest.TestCase):
self.assertRaises(ValueError, s.isset, -1)
self.assertRaises(ValueError, s.isset, 10)
- @requires_sched_h
+ @requires_sched_affinity
def test_cpu_set_cmp(self):
self.assertNotEqual(posix.cpu_set(11), posix.cpu_set(12))
l = posix.cpu_set(10)
@@ -935,7 +937,7 @@ class PosixTester(unittest.TestCase):
r.set(1)
self.assertEqual(l, r)
- @requires_sched_h
+ @requires_sched_affinity
def test_cpu_set_bitwise(self):
l = posix.cpu_set(5)
l.set(0)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ef8f82e..bb13f47 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4753,6 +4753,8 @@ posix_sched_yield(PyObject *self, PyObject *noargs)
Py_RETURN_NONE;
}
+#ifdef HAVE_SCHED_SETAFFINITY
+
typedef struct {
PyObject_HEAD;
Py_ssize_t size;
@@ -5083,6 +5085,8 @@ posix_sched_getaffinity(PyObject *self, PyObject *args)
return (PyObject *)res;
}
+#endif /* HAVE_SCHED_SETAFFINITY */
+
#endif /* HAVE_SCHED_H */
/* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */
@@ -10056,9 +10060,11 @@ static PyMethodDef posix_methods[] = {
{"sched_setparam", posix_sched_setparam, METH_VARARGS, posix_sched_setparam__doc__},
{"sched_setscheduler", posix_sched_setscheduler, METH_VARARGS, posix_sched_setscheduler__doc__},
{"sched_yield", posix_sched_yield, METH_NOARGS, posix_sched_yield__doc__},
+#ifdef HAVE_SCHED_SETAFFINITY
{"sched_setaffinity", posix_sched_setaffinity, METH_VARARGS, posix_sched_setaffinity__doc__},
{"sched_getaffinity", posix_sched_getaffinity, METH_VARARGS, posix_sched_getaffinity__doc__},
#endif
+#endif
#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
{"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__},
#endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
@@ -10876,10 +10882,12 @@ INITFUNC(void)
Py_INCREF(PyExc_OSError);
PyModule_AddObject(m, "error", PyExc_OSError);
+#ifdef HAVE_SCHED_SETAFFINITY
if (PyType_Ready(&cpu_set_type) < 0)
return NULL;
Py_INCREF(&cpu_set_type);
PyModule_AddObject(m, "cpu_set", (PyObject *)&cpu_set_type);
+#endif
#ifdef HAVE_PUTENV
if (posix_putenv_garbage == NULL)
diff --git a/configure b/configure
index ca13d70..c4b28d6 100755
--- a/configure
+++ b/configure
@@ -9339,6 +9339,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
setgid sethostname \
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
+ sched_setaffinity \
sigaction sigaltstack siginterrupt sigpending sigrelse \
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
diff --git a/configure.in b/configure.in
index 86e1a98..ae1caa6 100644
--- a/configure.in
+++ b/configure.in
@@ -2537,6 +2537,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
setgid sethostname \
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
+ sched_setaffinity \
sigaction sigaltstack siginterrupt sigpending sigrelse \
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index e9a4cac..0544ba3 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -653,6 +653,9 @@
/* Define to 1 if you have the <sched.h> header file. */
#undef HAVE_SCHED_H
+/* Define to 1 if you have the `sched_setaffinity' function. */
+#undef HAVE_SCHED_SETAFFINITY
+
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT