Mercurial > cpython-lru_cache-weakref
annotate Python/thread_nt.h @ 45151:643c1397f954 legacy-trunk
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> |
|---|---|
| date | Mon, 04 Feb 2008 21:45:05 +0000 |
| parents | 1c1705bf36b8 |
| children | e38335d4df91 fdcca8793eb9 |
| rev | line source |
|---|---|
| 2152 | 1 |
| 2 /* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */ | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
3 /* Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru */ |
|
22092
7a3e03b541ff
SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
Tim Peters <tim.peters@gmail.com>
parents:
21766
diff
changeset
|
4 /* Eliminated some memory leaks, gsw@agere.com */ |
| 2152 | 5 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
6 #include <windows.h> |
|
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
7 #include <limits.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38592
diff
changeset
|
8 #ifdef HAVE_PROCESS_H |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
9 #include <process.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38592
diff
changeset
|
10 #endif |
| 2152 | 11 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
12 typedef struct NRMUTEX { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
13 LONG owned ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
14 DWORD thread_id ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
15 HANDLE hevent ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
16 } NRMUTEX, *PNRMUTEX ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
17 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
18 |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
19 BOOL |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
20 InitializeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
21 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
22 mutex->owned = -1 ; /* No threads have entered NonRecursiveMutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
23 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
24 mutex->hevent = CreateEvent(NULL, FALSE, FALSE, NULL) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
25 return mutex->hevent != NULL ; /* TRUE if the mutex is created */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
26 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
27 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
28 VOID |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
29 DeleteNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
30 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
31 /* No in-use check */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
32 CloseHandle(mutex->hevent) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
33 mutex->hevent = NULL ; /* Just in case */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
34 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
35 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
36 DWORD |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
37 EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
38 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
39 /* Assume that the thread waits successfully */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
40 DWORD ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
41 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
42 /* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
43 if (!wait) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
44 { |
|
41590
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
45 if (InterlockedCompareExchange(&mutex->owned, 0, -1) != -1) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
46 return WAIT_TIMEOUT ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
47 ret = WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
48 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
49 else |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
50 ret = InterlockedIncrement(&mutex->owned) ? |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
51 /* Some thread owns the mutex, let's wait... */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
52 WaitForSingleObject(mutex->hevent, INFINITE) : WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
53 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
54 mutex->thread_id = GetCurrentThreadId() ; /* We own it */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
55 return ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
56 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
57 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
58 BOOL |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
59 LeaveNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
60 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
61 /* We don't own the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
62 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
63 return |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
64 InterlockedDecrement(&mutex->owned) < 0 || |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
65 SetEvent(mutex->hevent) ; /* Other threads are waiting, wake one on them up */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
66 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
67 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
68 PNRMUTEX |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
69 AllocNonRecursiveMutex(void) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
70 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
71 PNRMUTEX mutex = (PNRMUTEX)malloc(sizeof(NRMUTEX)) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
72 if (mutex && !InitializeNonRecursiveMutex(mutex)) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
73 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
74 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
75 mutex = NULL ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
76 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
77 return mutex ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
78 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
79 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
80 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
81 FreeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
82 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
83 if (mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
84 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
85 DeleteNonRecursiveMutex(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
86 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
87 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
88 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
89 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
90 long PyThread_get_thread_ident(void); |
| 2152 | 91 |
| 92 /* | |
| 93 * Initialization of the C package, should not be needed. | |
| 94 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
95 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
96 PyThread__init_thread(void) |
| 2152 | 97 { |
| 98 } | |
| 99 | |
| 100 /* | |
| 101 * Thread support. | |
| 102 */ | |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
103 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
104 typedef struct { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
105 void (*func)(void*); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
106 void *arg; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
107 long id; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
108 HANDLE done; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
109 } callobj; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
110 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
111 static int |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
112 bootstrap(void *call) |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
113 { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
114 callobj *obj = (callobj*)call; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
115 /* copy callobj since other thread might free it before we're done */ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
116 void (*func)(void*) = obj->func; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
117 void *arg = obj->arg; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
118 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
119 obj->id = PyThread_get_thread_ident(); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
120 ReleaseSemaphore(obj->done, 1, NULL); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
121 func(arg); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
122 return 0; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
123 } |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
124 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
125 long |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
126 PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2152 | 127 { |
|
38232
aa620856e8a3
Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
128 Py_uintptr_t rv; |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
129 callobj obj; |
| 2152 | 130 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
131 dprintf(("%ld: PyThread_start_new_thread called\n", |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
132 PyThread_get_thread_ident())); |
| 2152 | 133 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
134 PyThread_init_thread(); |
| 2152 | 135 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
136 obj.id = -1; /* guilty until proved innocent */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
137 obj.func = func; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
138 obj.arg = arg; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
139 obj.done = CreateSemaphore(NULL, 0, 1, NULL); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
140 if (obj.done == NULL) |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
141 return -1; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
142 |
|
41590
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
143 rv = _beginthread(bootstrap, |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
144 Py_SAFE_DOWNCAST(_pythread_stacksize, |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
145 Py_ssize_t, int), |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
146 &obj); |
|
38232
aa620856e8a3
Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
147 if (rv == (Py_uintptr_t)-1) { |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
148 /* I've seen errno == EAGAIN here, which means "there are |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
149 * too many threads". |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
150 */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
151 dprintf(("%ld: PyThread_start_new_thread failed: %p errno %d\n", |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
152 PyThread_get_thread_ident(), (void*)rv, errno)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
153 obj.id = -1; |
| 2152 | 154 } |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
155 else { |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
156 dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
157 PyThread_get_thread_ident(), (void*)rv)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
158 /* wait for thread to initialize, so we can get its id */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
159 WaitForSingleObject(obj.done, INFINITE); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
160 assert(obj.id != -1); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
161 } |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
162 CloseHandle((HANDLE)obj.done); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
163 return obj.id; |
| 2152 | 164 } |
| 165 | |
| 166 /* | |
| 167 * Return the thread Id instead of an handle. The Id is said to uniquely identify the | |
| 168 * thread in the system | |
| 169 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
170 long |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
171 PyThread_get_thread_ident(void) |
| 2152 | 172 { |
| 173 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
174 PyThread_init_thread(); |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
175 |
| 2152 | 176 return GetCurrentThreadId(); |
| 177 } | |
| 178 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
179 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
180 do_PyThread_exit_thread(int no_cleanup) |
| 2152 | 181 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
182 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2152 | 183 if (!initialized) |
| 184 if (no_cleanup) | |
| 185 _exit(0); | |
| 186 else | |
| 187 exit(0); | |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
188 _endthread(); |
| 2152 | 189 } |
| 190 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
191 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
192 PyThread_exit_thread(void) |
| 2152 | 193 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
194 do_PyThread_exit_thread(0); |
| 2152 | 195 } |
| 196 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
197 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
198 PyThread__exit_thread(void) |
| 2152 | 199 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
200 do_PyThread_exit_thread(1); |
| 2152 | 201 } |
| 202 | |
| 203 #ifndef NO_EXIT_PROG | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
204 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
205 do_PyThread_exit_prog(int status, int no_cleanup) |
| 2152 | 206 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
207 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2152 | 208 if (!initialized) |
| 209 if (no_cleanup) | |
| 210 _exit(status); | |
| 211 else | |
| 212 exit(status); | |
| 213 } | |
| 214 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
215 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
216 PyThread_exit_prog(int status) |
| 2152 | 217 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
218 do_PyThread_exit_prog(status, 0); |
| 2152 | 219 } |
| 220 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
221 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
222 PyThread__exit_prog(int status) |
| 2152 | 223 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
224 do_PyThread_exit_prog(status, 1); |
| 2152 | 225 } |
| 226 #endif /* NO_EXIT_PROG */ | |
| 227 | |
| 228 /* | |
| 229 * Lock support. It has too be implemented as semaphores. | |
| 230 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 231 * tell whether a thread already own the lock or not. | |
| 232 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
233 PyThread_type_lock |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
234 PyThread_allocate_lock(void) |
| 2152 | 235 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
236 PNRMUTEX aLock; |
| 2152 | 237 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
238 dprintf(("PyThread_allocate_lock called\n")); |
| 2152 | 239 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
240 PyThread_init_thread(); |
| 2152 | 241 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
242 aLock = AllocNonRecursiveMutex() ; |
| 2152 | 243 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
244 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2152 | 245 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
246 return (PyThread_type_lock) aLock; |
| 2152 | 247 } |
| 248 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
249 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
250 PyThread_free_lock(PyThread_type_lock aLock) |
| 2152 | 251 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
252 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 253 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
254 FreeNonRecursiveMutex(aLock) ; |
| 2152 | 255 } |
| 256 | |
| 257 /* | |
| 258 * Return 1 on success if the lock was acquired | |
| 259 * | |
| 260 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 261 * if the lock has already been acquired by this thread! | |
| 262 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
263 int |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
264 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2152 | 265 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
266 int success ; |
| 2152 | 267 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
268 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag)); |
| 2152 | 269 |
|
35217
b86392f55b59
bug [ 1234979 ] Lock.acquire treats only 1 as True
Georg Brandl <georg@python.org>
parents:
29755
diff
changeset
|
270 success = aLock && EnterNonRecursiveMutex((PNRMUTEX) aLock, (waitflag ? INFINITE : 0)) == WAIT_OBJECT_0 ; |
| 2152 | 271 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
272 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2152 | 273 |
| 274 return success; | |
| 275 } | |
| 276 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
277 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
278 PyThread_release_lock(PyThread_type_lock aLock) |
| 2152 | 279 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
280 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 281 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
282 if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
283 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2152 | 284 } |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
285 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
286 /* minimum/maximum thread stack sizes supported */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
287 #define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
288 #define THREAD_MAX_STACKSIZE 0x10000000 /* 256MB */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
289 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
290 /* set the thread stack size. |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
291 * Return 0 if size is valid, -1 otherwise. |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
292 */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
293 static int |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
294 _pythread_nt_set_stacksize(size_t size) |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
295 { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
296 /* set to default */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
297 if (size == 0) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
298 _pythread_stacksize = 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
299 return 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
300 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
301 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
302 /* valid range? */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
303 if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
304 _pythread_stacksize = size; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
305 return 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
306 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
307 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
308 return -1; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
309 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
310 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
311 #define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x) |
