Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Delta Between Two Patch Sets: Python/thread.c

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Python/random.c ('k') | setup_info.in » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 1
2 /* Thread package. 2 /* Thread package.
3 This is intended to be usable independently from Python. 3 This is intended to be usable independently from Python.
4 The implementation for system foobar is in a file thread_foobar.h 4 The implementation for system foobar is in a file thread_foobar.h
5 which is included by this file dependent on config settings. 5 which is included by this file dependent on config settings.
6 Stuff shared by all thread_*.h files is collected here. */ 6 Stuff shared by all thread_*.h files is collected here. */
7 7
8 #include "Python.h" 8 #include "Python.h"
9 9
10 #ifdef __MINGW32__
11 /* GCC 4.4+ (mingw) support posix threads!
12 Note: macro __MINGW_GCC is defined for GCC 4.4+ but
13 not for GCC 3.4.5 (last stable from 3.x )
14 Instead to use __MINGW_GCC we will use more common
15 __MINGW32__ to prevent case when in GCC 3.4.5 build
16 envirionment is installed posix thread package.
17 */
18 # undef _POSIX_THREADS
19 # undef HAVE_PTHREAD_H
20 #endif
10 21
11 #ifndef _POSIX_THREADS 22 #ifndef _POSIX_THREADS
12 /* This means pthreads are not implemented in libc headers, hence the macro 23 /* This means pthreads are not implemented in libc headers, hence the macro
13 not present in unistd.h. But they still can be implemented as an external 24 not present in unistd.h. But they still can be implemented as an external
14 library (e.g. gnu pth in pthread emulation) */ 25 library (e.g. gnu pth in pthread emulation) */
15 # if defined(HAVE_PTHREAD_H) && !defined(NT_THREADS) 26 # ifdef HAVE_PTHREAD_H
16 # include <pthread.h> /* _POSIX_THREADS */ 27 # include <pthread.h> /* _POSIX_THREADS */
17 # endif 28 # endif
18 #endif 29 #endif
19 30
20 #ifndef DONT_HAVE_STDIO_H 31 #ifndef DONT_HAVE_STDIO_H
21 #include <stdio.h> 32 #include <stdio.h>
22 #endif 33 #endif
23 34
24 #include <stdlib.h> 35 #include <stdlib.h>
25 36
26 #include "pythread.h" 37 #include "pythread.h"
27 38
28 #ifndef _POSIX_THREADS 39 #ifndef _POSIX_THREADS
29 40
30 #ifdef __sgi
31 #define SGI_THREADS
32 #endif
33
34 #ifdef HAVE_THREAD_H
35 #define SOLARIS_THREADS
36 #endif
37
38 #if defined(sun) && !defined(SOLARIS_THREADS)
39 #define SUN_LWP
40 #endif
41
42 /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then 41 /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then
43 enough of the Posix threads package is implimented to support python 42 enough of the Posix threads package is implemented to support python
44 threads. 43 threads.
45 44
46 This is valid for HP-UX 11.23 running on an ia64 system. If needed, add 45 This is valid for HP-UX 11.23 running on an ia64 system. If needed, add
47 a check of __ia64 to verify that we're running on a ia64 system instead 46 a check of __ia64 to verify that we're running on a ia64 system instead
48 of a pa-risc system. 47 of a pa-risc system.
49 */ 48 */
50 #ifdef __hpux 49 #ifdef __hpux
51 #ifdef _SC_THREADS 50 #ifdef _SC_THREADS
52 #define _POSIX_THREADS 51 #define _POSIX_THREADS
53 #endif 52 #endif
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 initialized = 1; 86 initialized = 1;
88 dprintf(("PyThread_init_thread called\n")); 87 dprintf(("PyThread_init_thread called\n"));
89 PyThread__init_thread(); 88 PyThread__init_thread();
90 } 89 }
91 90
92 /* Support for runtime thread stack size tuning. 91 /* Support for runtime thread stack size tuning.
93 A value of 0 means using the platform's default stack size 92 A value of 0 means using the platform's default stack size
94 or the size specified by the THREAD_STACK_SIZE macro. */ 93 or the size specified by the THREAD_STACK_SIZE macro. */
95 static size_t _pythread_stacksize = 0; 94 static size_t _pythread_stacksize = 0;
96 95
97 #ifdef SGI_THREADS
98 #error SGI Irix threads are now unsupported, and code will be removed in 3.3.
99 #include "thread_sgi.h"
100 #endif
101
102 #ifdef SOLARIS_THREADS
103 #include "thread_solaris.h"
104 #endif
105
106 #ifdef SUN_LWP
107 #error SunOS lightweight processes are now unsupported, and code will be removed in 3.3.
108 #include "thread_lwp.h"
109 #endif
110
111 #ifdef HAVE_PTH
112 #error GNU pth threads are now unsupported, and code will be removed in 3.3.
113 #include "thread_pth.h"
114 #undef _POSIX_THREADS
115 #endif
116
117 #ifdef _POSIX_THREADS 96 #ifdef _POSIX_THREADS
97 #define PYTHREAD_NAME "pthread"
118 #include "thread_pthread.h" 98 #include "thread_pthread.h"
119 #endif 99 #endif
120 100
121 #ifdef C_THREADS
122 #error Mach C Threads are now unsupported, and code will be removed in 3.3.
123 #include "thread_cthread.h"
124 #endif
125
126 #ifdef NT_THREADS 101 #ifdef NT_THREADS
102 #define PYTHREAD_NAME "nt"
127 #include "thread_nt.h" 103 #include "thread_nt.h"
128 #endif 104 #endif
129 105
130 #ifdef OS2_THREADS 106 #ifdef OS2_THREADS
107 #define PYTHREAD_NAME "os2"
131 #include "thread_os2.h" 108 #include "thread_os2.h"
132 #endif
133
134 #ifdef PLAN9_THREADS
135 #include "thread_plan9.h"
136 #endif 109 #endif
137 110
138 /* 111 /*
139 #ifdef FOOBAR_THREADS 112 #ifdef FOOBAR_THREADS
140 #include "thread_foobar.h" 113 #include "thread_foobar.h"
141 #endif 114 #endif
142 */ 115 */
143 116
144 /* return the current thread stack size */ 117 /* return the current thread stack size */
145 size_t 118 size_t
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 *q = p->next; 375 *q = p->next;
403 free((void *)p); 376 free((void *)p);
404 /* NB This does *not* free p->value! */ 377 /* NB This does *not* free p->value! */
405 } 378 }
406 else 379 else
407 q = &p->next; 380 q = &p->next;
408 } 381 }
409 } 382 }
410 383
411 #endif /* Py_HAVE_NATIVE_TLS */ 384 #endif /* Py_HAVE_NATIVE_TLS */
385
386 PyDoc_STRVAR(threadinfo__doc__,
387 "sys.thread_info\n\
388 \n\
389 A struct sequence holding information about the thread implementation.");
390
391 static PyStructSequence_Field threadinfo_fields[] = {
392 {"name", "name of the thread implementation"},
393 {"lock", "name of the lock implementation"},
394 {"version", "name and version of the thread library"},
395 {0}
396 };
397
398 static PyStructSequence_Desc threadinfo_desc = {
399 "sys.thread_info", /* name */
400 threadinfo__doc__, /* doc */
401 threadinfo_fields, /* fields */
402 3
403 };
404
405 static PyTypeObject ThreadInfoType;
406
407 PyObject*
408 PyThread_GetInfo(void)
409 {
410 PyObject *threadinfo, *value;
411 int pos = 0;
412 #if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
413 && defined(_CS_GNU_LIBPTHREAD_VERSION))
414 char buffer[255];
415 int len;
416 #endif
417
418 if (ThreadInfoType.tp_name == 0)
419 PyStructSequence_InitType(&ThreadInfoType, &threadinfo_desc);
420
421 threadinfo = PyStructSequence_New(&ThreadInfoType);
422 if (threadinfo == NULL)
423 return NULL;
424
425 value = PyUnicode_FromString(PYTHREAD_NAME);
426 if (value == NULL) {
427 Py_DECREF(threadinfo);
428 return NULL;
429 }
430 PyStructSequence_SET_ITEM(threadinfo, pos++, value);
431
432 #ifdef _POSIX_THREADS
433 #ifdef USE_SEMAPHORES
434 value = PyUnicode_FromString("semaphore");
435 #else
436 value = PyUnicode_FromString("mutex+cond");
437 #endif
438 if (value == NULL) {
439 Py_DECREF(threadinfo);
440 return NULL;
441 }
442 #else
443 Py_INCREF(Py_None);
444 value = Py_None;
445 #endif
446 PyStructSequence_SET_ITEM(threadinfo, pos++, value);
447
448 #if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
449 && defined(_CS_GNU_LIBPTHREAD_VERSION))
450 value = NULL;
451 len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
452 if (1 < len && len < sizeof(buffer)) {
453 value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
454 if (value == NULL)
455 PyErr_Clear();
456 }
457 if (value == NULL)
458 #endif
459 {
460 Py_INCREF(Py_None);
461 value = Py_None;
462 }
463 PyStructSequence_SET_ITEM(threadinfo, pos++, value);
464 return threadinfo;
465 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+