[Python-checkins] cpython: sched.h can exist without sched affinity support

benjamin.peterson python-checkins at python.org
Wed Aug 3 00:41:43 CEST 2011


http://hg.python.org/cpython/rev/4b8e407e9a32
changeset:   71705:4b8e407e9a32
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Aug 02 17:41:34 2011 -0500
summary:
  sched.h can exist without sched affinity support

files:
  Lib/test/test_posix.py |  10 ++++++----
  Modules/posixmodule.c  |   8 ++++++++
  configure              |   1 +
  configure.in           |   1 +
  pyconfig.h.in          |   3 +++
  5 files changed, 19 insertions(+), 4 deletions(-)


diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -831,6 +831,8 @@
 
     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 @@
         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 @@
         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 @@
         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 @@
         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
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4753,6 +4753,8 @@
     Py_RETURN_NONE;
 }
 
+#ifdef HAVE_SCHED_SETAFFINITY
+
 typedef struct {
     PyObject_HEAD;
     Py_ssize_t size;
@@ -5083,6 +5085,8 @@
     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 @@
     {"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 @@
     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
--- a/configure
+++ b/configure
@@ -9339,6 +9339,7 @@
  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
--- a/configure.in
+++ b/configure.in
@@ -2537,6 +2537,7 @@
  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
--- 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
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list