comparison Python/thread.c @ 69457:383a7301616b

Issue #11223: Add threading._info() function providing informations about the thread implementation. Skip test_lock_acquire_interruption() and test_rlock_acquire_interruption() of test_threadsignals if a thread lock is implemented using a POSIX mutex and a POSIX condition variable. A POSIX condition variable cannot be interrupted by a signal (e.g. on Linux, the futex system call is restarted).
author Victor Stinner <victor.stinner@haypocalc.com>
date Tue, 19 Apr 2011 23:58:51 +0200
parents dc245d681901
children 64008d17fb54
comparison
equal deleted inserted replaced
69456:73ccc552fef3 69457:383a7301616b
98 #error SGI Irix threads are now unsupported, and code will be removed in 3.3. 98 #error SGI Irix threads are now unsupported, and code will be removed in 3.3.
99 #include "thread_sgi.h" 99 #include "thread_sgi.h"
100 #endif 100 #endif
101 101
102 #ifdef SOLARIS_THREADS 102 #ifdef SOLARIS_THREADS
103 #define PYTHREAD_NAME "solaris"
103 #include "thread_solaris.h" 104 #include "thread_solaris.h"
104 #endif 105 #endif
105 106
106 #ifdef SUN_LWP 107 #ifdef SUN_LWP
107 #error SunOS lightweight processes are now unsupported, and code will be removed in 3.3. 108 #error SunOS lightweight processes are now unsupported, and code will be removed in 3.3.
113 #include "thread_pth.h" 114 #include "thread_pth.h"
114 #undef _POSIX_THREADS 115 #undef _POSIX_THREADS
115 #endif 116 #endif
116 117
117 #ifdef _POSIX_THREADS 118 #ifdef _POSIX_THREADS
119 #define PYTHREAD_NAME "pthread"
118 #include "thread_pthread.h" 120 #include "thread_pthread.h"
119 #endif 121 #endif
120 122
121 #ifdef C_THREADS 123 #ifdef C_THREADS
122 #error Mach C Threads are now unsupported, and code will be removed in 3.3. 124 #error Mach C Threads are now unsupported, and code will be removed in 3.3.
123 #include "thread_cthread.h" 125 #include "thread_cthread.h"
124 #endif 126 #endif
125 127
126 #ifdef NT_THREADS 128 #ifdef NT_THREADS
129 #define PYTHREAD_NAME "nt"
127 #include "thread_nt.h" 130 #include "thread_nt.h"
128 #endif 131 #endif
129 132
130 #ifdef OS2_THREADS 133 #ifdef OS2_THREADS
134 #define PYTHREAD_NAME "os2"
131 #include "thread_os2.h" 135 #include "thread_os2.h"
132 #endif 136 #endif
133 137
134 #ifdef PLAN9_THREADS 138 #ifdef PLAN9_THREADS
139 #define PYTHREAD_NAME "plan9"
135 #include "thread_plan9.h" 140 #include "thread_plan9.h"
136 #endif 141 #endif
137 142
138 /* 143 /*
139 #ifdef FOOBAR_THREADS 144 #ifdef FOOBAR_THREADS
407 q = &p->next; 412 q = &p->next;
408 } 413 }
409 } 414 }
410 415
411 #endif /* Py_HAVE_NATIVE_TLS */ 416 #endif /* Py_HAVE_NATIVE_TLS */
417
418 PyObject*
419 _PyThread_Info(void)
420 {
421 PyObject *info, *value;
422 int ret;
423 char buffer[255];
424 int len;
425
426 info = PyDict_New();
427 if (info == NULL)
428 return NULL;
429
430 value = PyUnicode_FromString(PYTHREAD_NAME);
431 ret = PyDict_SetItemString(info, "name", value);
432 Py_DECREF(value);
433 if (ret)
434 goto error;
435
436 #ifdef _POSIX_THREADS
437 #ifdef USE_SEMAPHORES
438 value = PyUnicode_FromString("semaphore");
439 #else
440 value = PyUnicode_FromString("mutex+cond");
441 #endif
442 if (value == NULL)
443 return NULL;
444 ret = PyDict_SetItemString(info, "lock_implementation", value);
445 Py_DECREF(value);
446 if (ret)
447 goto error;
448
449 #if defined(HAVE_CONFSTR) && defined(_CS_GNU_LIBPTHREAD_VERSION)
450 len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
451 if (0 < len && len < sizeof(buffer)) {
452 value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
453 if (value == NULL)
454 goto error;
455 ret = PyDict_SetItemString(info, "pthread_version", value);
456 Py_DECREF(value);
457 if (ret)
458 goto error;
459 }
460 #endif
461 #endif
462
463 return info;
464
465 error:
466 Py_DECREF(info);
467 return NULL;
468 }