Mercurial > cpython-lru_cache-weakref
annotate Modules/threadmodule.c @ 64209:dfd0229748ef 2.7
Merged revisions 84239 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r84239 | antoine.pitrou | 2010-08-21 21:09:32 +0200 (sam., 21 août 2010) | 4 lines
Issue #9617: Signals received during a low-level write operation aren't
ignored by the buffered IO layer anymore.
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 21 Aug 2010 19:17:25 +0000 |
| parents | 756f8b398230 |
| children | b2e8dcd15040 |
| rev | line source |
|---|---|
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Thread module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 /* Interface to Sjoerd's portable C thread library */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
| 4751 | 5 #include "Python.h" |
|
55704
e21c4c527e66
Add weakref support to the thread.lock type.
Gregory P. Smith <greg@mad-scientist.com>
parents:
54321
diff
changeset
|
6 #include "structmember.h" /* offsetof */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
8 #ifndef WITH_THREAD |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
9 #error "Error! The rest of Python is not compiled with thread support." |
|
25127
5165a0ee84c6
--with(out)-thread is deprecated according to configure --help
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
10 #error "Rerun configure, adding a --with-threads option." |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
11 #error "Then run `make clean' followed by `make'." |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
12 #endif |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
13 |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
14 #include "pythread.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
| 4751 | 16 static PyObject *ThreadError; |
|
56980
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
17 static long nb_threads = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 /* Lock objects */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 typedef struct { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
22 PyObject_HEAD |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
23 PyThread_type_lock lock_lock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
24 PyObject *in_weakreflist; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 } lockobject; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 static void |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
28 lock_dealloc(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
30 if (self->in_weakreflist != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
31 PyObject_ClearWeakRefs((PyObject *) self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
32 if (self->lock_lock != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
33 /* Unlock the lock so it's safe to free it */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
34 PyThread_acquire_lock(self->lock_lock, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
35 PyThread_release_lock(self->lock_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
36 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
37 PyThread_free_lock(self->lock_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
38 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
39 PyObject_Del(self); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
| 4751 | 42 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
43 lock_PyThread_acquire_lock(lockobject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
45 int i = 1; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
47 if (!PyArg_ParseTuple(args, "|i:acquire", &i)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
48 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
50 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
51 i = PyThread_acquire_lock(self->lock_lock, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
52 Py_END_ALLOW_THREADS |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
54 return PyBool_FromLong((long)i); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
57 PyDoc_STRVAR(acquire_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
58 "acquire([wait]) -> None or bool\n\ |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
59 (acquire_lock() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
60 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
61 Lock the lock. Without argument, this blocks if the lock is already\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
62 locked (even by the same thread), waiting for another thread to release\n\ |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
63 the lock, and return None once the lock is acquired.\n\ |
|
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
64 With an argument, this will only block if the argument is true,\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
65 and the return value reflects whether the lock is acquired.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
66 The blocking operation is not interruptible."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
67 |
| 4751 | 68 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
69 lock_PyThread_release_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
71 /* Sanity check: the lock must be locked */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
72 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
73 PyThread_release_lock(self->lock_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
74 PyErr_SetString(ThreadError, "release unlocked lock"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
75 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
76 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
78 PyThread_release_lock(self->lock_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
79 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
80 return Py_None; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
83 PyDoc_STRVAR(release_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
84 "release()\n\ |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
85 (release_lock() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
86 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
87 Release the lock, allowing another thread that is blocked waiting for\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
88 the lock to acquire the lock. The lock must be in the locked state,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
89 but it needn't be locked by the same thread that unlocks it."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
90 |
| 4751 | 91 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
92 lock_locked_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
94 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
95 PyThread_release_lock(self->lock_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
96 return PyBool_FromLong(0L); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
97 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
98 return PyBool_FromLong(1L); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
101 PyDoc_STRVAR(locked_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
102 "locked() -> bool\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
103 (locked_lock() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
104 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
105 Return whether the lock is in the locked state."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
106 |
| 4751 | 107 static PyMethodDef lock_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
108 {"acquire_lock", (PyCFunction)lock_PyThread_acquire_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
109 METH_VARARGS, acquire_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
110 {"acquire", (PyCFunction)lock_PyThread_acquire_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
111 METH_VARARGS, acquire_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
112 {"release_lock", (PyCFunction)lock_PyThread_release_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
113 METH_NOARGS, release_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
114 {"release", (PyCFunction)lock_PyThread_release_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
115 METH_NOARGS, release_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
116 {"locked_lock", (PyCFunction)lock_locked_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
117 METH_NOARGS, locked_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
118 {"locked", (PyCFunction)lock_locked_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
119 METH_NOARGS, locked_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
120 {"__enter__", (PyCFunction)lock_PyThread_acquire_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
121 METH_VARARGS, acquire_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
122 {"__exit__", (PyCFunction)lock_PyThread_release_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
123 METH_VARARGS, release_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
124 {NULL} /* sentinel */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 |
| 4751 | 127 static PyTypeObject Locktype = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
128 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
129 "thread.lock", /*tp_name*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
130 sizeof(lockobject), /*tp_size*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
131 0, /*tp_itemsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
132 /* methods */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
133 (destructor)lock_dealloc, /*tp_dealloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
134 0, /*tp_print*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
135 0, /*tp_getattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
136 0, /*tp_setattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
137 0, /*tp_compare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
138 0, /*tp_repr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
139 0, /* tp_as_number */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
140 0, /* tp_as_sequence */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
141 0, /* tp_as_mapping */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
142 0, /* tp_hash */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
143 0, /* tp_call */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
144 0, /* tp_str */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
145 0, /* tp_getattro */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
146 0, /* tp_setattro */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
147 0, /* tp_as_buffer */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
148 Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
149 0, /* tp_doc */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
150 0, /* tp_traverse */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
151 0, /* tp_clear */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
152 0, /* tp_richcompare */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
153 offsetof(lockobject, in_weakreflist), /* tp_weaklistoffset */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
154 0, /* tp_iter */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
155 0, /* tp_iternext */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
156 lock_methods, /* tp_methods */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
159 static lockobject * |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
160 newlockobject(void) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
161 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
162 lockobject *self; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
163 self = PyObject_New(lockobject, &Locktype); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
164 if (self == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
165 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
166 self->lock_lock = PyThread_allocate_lock(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
167 self->in_weakreflist = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
168 if (self->lock_lock == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
169 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
170 PyErr_SetString(ThreadError, "can't allocate lock"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
171 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
172 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
173 return self; |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
174 } |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
175 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
176 /* Thread-local objects */ |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
177 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
178 #include "structmember.h" |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
179 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
180 /* Quick overview: |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
181 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
182 We need to be able to reclaim reference cycles as soon as possible |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
183 (both when a thread is being terminated, or a thread-local object |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
184 becomes unreachable from user data). Constraints: |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
185 - it must not be possible for thread-state dicts to be involved in |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
186 reference cycles (otherwise the cyclic GC will refuse to consider |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
187 objects referenced from a reachable thread-state dict, even though |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
188 local_dealloc would clear them) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
189 - the death of a thread-state dict must still imply destruction of the |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
190 corresponding local dicts in all thread-local objects. |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
191 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
192 Our implementation uses small "localdummy" objects in order to break |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
193 the reference chain. These trivial objects are hashable (using the |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
194 default scheme of identity hashing) and weakrefable. |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
195 Each thread-state holds a separate localdummy for each local object |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
196 (as a /strong reference/), |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
197 and each thread-local object holds a dict mapping /weak references/ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
198 of localdummies to local dicts. |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
199 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
200 Therefore: |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
201 - only the thread-state dict holds a strong reference to the dummies |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
202 - only the thread-local object holds a strong reference to the local dicts |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
203 - only outside objects (application- or library-level) hold strong |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
204 references to the thread-local objects |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
205 - as soon as a thread-state dict is destroyed, the weakref callbacks of all |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
206 dummies attached to that thread are called, and destroy the corresponding |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
207 local dicts from thread-local objects |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
208 - as soon as a thread-local object is destroyed, its local dicts are |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
209 destroyed and its dummies are manually removed from all thread states |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
210 - the GC can do its work correctly when a thread-local object is dangling, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
211 without any interference from the thread-state dicts |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
212 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
213 As an additional optimization, each localdummy holds a borrowed reference |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
214 to the corresponding localdict. This borrowed reference is only used |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
215 by the thread-local object which has created the localdummy, which should |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
216 guarantee that the localdict still exists when accessed. |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
217 */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
218 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
219 typedef struct { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
220 PyObject_HEAD |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
221 PyObject *localdict; /* Borrowed reference! */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
222 PyObject *weakreflist; /* List of weak references to self */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
223 } localdummyobject; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
224 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
225 static void |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
226 localdummy_dealloc(localdummyobject *self) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
227 { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
228 if (self->weakreflist != NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
229 PyObject_ClearWeakRefs((PyObject *) self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
230 Py_TYPE(self)->tp_free((PyObject*)self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
231 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
232 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
233 static PyTypeObject localdummytype = { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
234 PyVarObject_HEAD_INIT(NULL, 0) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
235 /* tp_name */ "_thread._localdummy", |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
236 /* tp_basicsize */ sizeof(localdummyobject), |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
237 /* tp_itemsize */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
238 /* tp_dealloc */ (destructor)localdummy_dealloc, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
239 /* tp_print */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
240 /* tp_getattr */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
241 /* tp_setattr */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
242 /* tp_reserved */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
243 /* tp_repr */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
244 /* tp_as_number */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
245 /* tp_as_sequence */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
246 /* tp_as_mapping */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
247 /* tp_hash */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
248 /* tp_call */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
249 /* tp_str */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
250 /* tp_getattro */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
251 /* tp_setattro */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
252 /* tp_as_buffer */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
253 /* tp_flags */ Py_TPFLAGS_DEFAULT, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
254 /* tp_doc */ "Thread-local dummy", |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
255 /* tp_traverse */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
256 /* tp_clear */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
257 /* tp_richcompare */ 0, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
258 /* tp_weaklistoffset */ offsetof(localdummyobject, weakreflist) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
259 }; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
260 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
261 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
262 typedef struct { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
263 PyObject_HEAD |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
264 PyObject *key; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
265 PyObject *args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
266 PyObject *kw; |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
267 /* The current thread's local dict (necessary for tp_dictoffset) */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
268 PyObject *dict; |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
269 PyObject *weakreflist; /* List of weak references to self */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
270 /* A {localdummy weakref -> localdict} dict */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
271 PyObject *dummies; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
272 /* The callback for weakrefs to localdummies */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
273 PyObject *wr_callback; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
274 } localobject; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
275 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
276 /* Forward declaration */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
277 static PyObject *_ldict(localobject *self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
278 static PyObject *_localdummy_destroyed(PyObject *meth_self, PyObject *dummyweakref); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
279 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
280 /* Create and register the dummy for the current thread, as well as the |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
281 corresponding local dict */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
282 static int |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
283 _local_create_dummy(localobject *self) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
284 { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
285 PyObject *tdict, *ldict = NULL, *wr = NULL; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
286 localdummyobject *dummy = NULL; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
287 int r; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
288 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
289 tdict = PyThreadState_GetDict(); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
290 if (tdict == NULL) { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
291 PyErr_SetString(PyExc_SystemError, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
292 "Couldn't get thread-state dictionary"); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
293 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
294 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
295 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
296 ldict = PyDict_New(); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
297 if (ldict == NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
298 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
299 dummy = (localdummyobject *) localdummytype.tp_alloc(&localdummytype, 0); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
300 if (dummy == NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
301 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
302 dummy->localdict = ldict; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
303 wr = PyWeakref_NewRef((PyObject *) dummy, self->wr_callback); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
304 if (wr == NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
305 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
306 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
307 /* As a side-effect, this will cache the weakref's hash before the |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
308 dummy gets deleted */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
309 r = PyDict_SetItem(self->dummies, wr, ldict); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
310 if (r < 0) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
311 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
312 Py_CLEAR(wr); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
313 r = PyDict_SetItem(tdict, self->key, (PyObject *) dummy); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
314 if (r < 0) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
315 goto err; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
316 Py_CLEAR(dummy); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
317 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
318 Py_CLEAR(self->dict); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
319 self->dict = ldict; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
320 return 0; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
321 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
322 err: |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
323 Py_XDECREF(ldict); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
324 Py_XDECREF(wr); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
325 Py_XDECREF(dummy); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
326 return -1; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
327 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
328 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
329 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
330 local_new(PyTypeObject *type, PyObject *args, PyObject *kw) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
331 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
332 localobject *self; |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
333 PyObject *wr; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
334 static PyMethodDef wr_callback_def = { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
335 "_localdummy_destroyed", (PyCFunction) _localdummy_destroyed, METH_O |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
336 }; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
337 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
338 if (type->tp_init == PyBaseObject_Type.tp_init |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
339 && ((args && PyObject_IsTrue(args)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
340 || (kw && PyObject_IsTrue(kw)))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
341 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
342 "Initialization arguments are not supported"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
343 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
344 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
345 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
346 self = (localobject *)type->tp_alloc(type, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
347 if (self == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
348 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
349 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
350 Py_XINCREF(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
351 self->args = args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
352 Py_XINCREF(kw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
353 self->kw = kw; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
354 self->key = PyString_FromFormat("thread.local.%p", self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
355 if (self->key == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
356 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
357 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
358 self->dummies = PyDict_New(); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
359 if (self->dummies == NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
360 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
361 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
362 /* We use a weak reference to self in the callback closure |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
363 in order to avoid spurious reference cycles */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
364 wr = PyWeakref_NewRef((PyObject *) self, NULL); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
365 if (wr == NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
366 goto err; |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
367 self->wr_callback = PyCFunction_New(&wr_callback_def, wr); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
368 Py_DECREF(wr); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
369 if (self->wr_callback == NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
370 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
371 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
372 if (_local_create_dummy(self) < 0) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
373 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
374 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
375 return (PyObject *)self; |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
376 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
377 err: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
378 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
379 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
380 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
381 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
382 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
383 local_traverse(localobject *self, visitproc visit, void *arg) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
384 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
385 Py_VISIT(self->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
386 Py_VISIT(self->kw); |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
387 Py_VISIT(self->dummies); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
388 Py_VISIT(self->dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
389 return 0; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
390 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
391 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
392 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
393 local_clear(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
394 { |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
395 PyThreadState *tstate; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
396 Py_CLEAR(self->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
397 Py_CLEAR(self->kw); |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
398 Py_CLEAR(self->dummies); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
399 Py_CLEAR(self->dict); |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
400 Py_CLEAR(self->wr_callback); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
401 /* Remove all strong references to dummies from the thread states */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
402 if (self->key |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
403 && (tstate = PyThreadState_Get()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
404 && tstate->interp) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
405 for(tstate = PyInterpreterState_ThreadHead(tstate->interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
406 tstate; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
407 tstate = PyThreadState_Next(tstate)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
408 if (tstate->dict && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
409 PyDict_GetItem(tstate->dict, self->key)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
410 PyDict_DelItem(tstate->dict, self->key); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
411 } |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
412 return 0; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
413 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
414 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
415 static void |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
416 local_dealloc(localobject *self) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
417 { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
418 /* Weakrefs must be invalidated right now, otherwise they can be used |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
419 from code called below, which is very dangerous since Py_REFCNT(self) == 0 */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
420 if (self->weakreflist != NULL) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
421 PyObject_ClearWeakRefs((PyObject *) self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
422 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
423 PyObject_GC_UnTrack(self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
424 |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
425 local_clear(self); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
426 Py_XDECREF(self->key); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
427 Py_TYPE(self)->tp_free((PyObject*)self); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
428 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
429 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
430 /* Returns a borrowed reference to the local dict, creating it if necessary */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
431 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
432 _ldict(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
433 { |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
434 PyObject *tdict, *ldict, *dummy; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
435 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
436 tdict = PyThreadState_GetDict(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
437 if (tdict == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
438 PyErr_SetString(PyExc_SystemError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
439 "Couldn't get thread-state dictionary"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
440 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
441 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
442 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
443 dummy = PyDict_GetItem(tdict, self->key); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
444 if (dummy == NULL) { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
445 if (_local_create_dummy(self) < 0) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
446 return NULL; |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
447 ldict = self->dict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
448 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
449 if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
450 Py_TYPE(self)->tp_init((PyObject*)self, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
451 self->args, self->kw) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
452 /* we need to get rid of ldict from thread so |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
453 we create a new one the next time we do an attr |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
454 acces */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
455 PyDict_DelItem(tdict, self->key); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
456 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
457 } |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
458 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
459 else { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
460 assert(Py_TYPE(dummy) == &localdummytype); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
461 ldict = ((localdummyobject *) dummy)->localdict; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
462 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
463 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
464 /* The call to tp_init above may have caused another thread to run. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
465 Install our ldict again. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
466 if (self->dict != ldict) { |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
467 Py_INCREF(ldict); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
468 Py_CLEAR(self->dict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
469 self->dict = ldict; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
470 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
471 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
472 return ldict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
473 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
474 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
475 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
476 local_setattro(localobject *self, PyObject *name, PyObject *v) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
477 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
478 PyObject *ldict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
479 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
480 ldict = _ldict(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
481 if (ldict == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
482 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
483 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
484 return PyObject_GenericSetAttr((PyObject *)self, name, v); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
485 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
486 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
487 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
488 local_getdict(localobject *self, void *closure) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
489 { |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
490 PyObject *ldict; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
491 ldict = _ldict(self); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
492 Py_XINCREF(ldict); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
493 return ldict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
494 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
495 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
496 static PyGetSetDef local_getset[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
497 {"__dict__", (getter)local_getdict, (setter)NULL, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
498 "Local-data dictionary", NULL}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
499 {NULL} /* Sentinel */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
500 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
501 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
502 static PyObject *local_getattro(localobject *, PyObject *); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
503 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
504 static PyTypeObject localtype = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
505 PyVarObject_HEAD_INIT(NULL, 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
506 /* tp_name */ "thread._local", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
507 /* tp_basicsize */ sizeof(localobject), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
508 /* tp_itemsize */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
509 /* tp_dealloc */ (destructor)local_dealloc, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
510 /* tp_print */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
511 /* tp_getattr */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
512 /* tp_setattr */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
513 /* tp_compare */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
514 /* tp_repr */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
515 /* tp_as_number */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
516 /* tp_as_sequence */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
517 /* tp_as_mapping */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
518 /* tp_hash */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
519 /* tp_call */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
520 /* tp_str */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
521 /* tp_getattro */ (getattrofunc)local_getattro, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
522 /* tp_setattro */ (setattrofunc)local_setattro, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
523 /* tp_as_buffer */ 0, |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
524 /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
525 | Py_TPFLAGS_HAVE_GC, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
526 /* tp_doc */ "Thread-local data", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
527 /* tp_traverse */ (traverseproc)local_traverse, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
528 /* tp_clear */ (inquiry)local_clear, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
529 /* tp_richcompare */ 0, |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
530 /* tp_weaklistoffset */ offsetof(localobject, weakreflist), |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
531 /* tp_iter */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
532 /* tp_iternext */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
533 /* tp_methods */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
534 /* tp_members */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
535 /* tp_getset */ local_getset, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
536 /* tp_base */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
537 /* tp_dict */ 0, /* internal use */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
538 /* tp_descr_get */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
539 /* tp_descr_set */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
540 /* tp_dictoffset */ offsetof(localobject, dict), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
541 /* tp_init */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
542 /* tp_alloc */ 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
543 /* tp_new */ local_new, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
544 /* tp_free */ 0, /* Low-level free-mem routine */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
545 /* tp_is_gc */ 0, /* For PyObject_IS_GC */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
546 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
547 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
548 static PyObject * |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
549 local_getattro(localobject *self, PyObject *name) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
550 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
551 PyObject *ldict, *value; |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
552 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
553 ldict = _ldict(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
554 if (ldict == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
555 return NULL; |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
556 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
557 if (Py_TYPE(self) != &localtype) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
558 /* use generic lookup for subtypes */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
559 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
560 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
561 /* Optimization: just look in dict ourselves */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
562 value = PyDict_GetItem(ldict, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
563 if (value == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
564 /* Fall back on generic to get __class__ and __dict__ */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
565 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
566 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
567 Py_INCREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
568 return value; |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
569 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
570 |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
571 /* Called when a dummy is destroyed. */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
572 static PyObject * |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
573 _localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
574 { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
575 PyObject *obj; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
576 localobject *self; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
577 assert(PyWeakref_CheckRef(localweakref)); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
578 obj = PyWeakref_GET_OBJECT(localweakref); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
579 if (obj == Py_None) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
580 Py_RETURN_NONE; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
581 Py_INCREF(obj); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
582 assert(PyObject_TypeCheck(obj, &localtype)); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
583 /* If the thread-local object is still alive and not being cleared, |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
584 remove the corresponding local dict */ |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
585 self = (localobject *) obj; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
586 if (self->dummies != NULL) { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
587 PyObject *ldict; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
588 ldict = PyDict_GetItem(self->dummies, dummyweakref); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
589 if (ldict != NULL) { |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
590 if (ldict == self->dict) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
591 Py_CLEAR(self->dict); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
592 PyDict_DelItem(self->dummies, dummyweakref); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
593 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
594 if (PyErr_Occurred()) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
595 PyErr_WriteUnraisable(obj); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
596 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
597 Py_DECREF(obj); |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
598 Py_RETURN_NONE; |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
599 } |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
600 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 /* Module functions */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
603 struct bootstate { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
604 PyInterpreterState *interp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
605 PyObject *func; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
606 PyObject *args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
607 PyObject *keyw; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
608 PyThreadState *tstate; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
609 }; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
611 static void |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
612 t_bootstrap(void *boot_raw) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
613 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
614 struct bootstate *boot = (struct bootstate *) boot_raw; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
615 PyThreadState *tstate; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
616 PyObject *res; |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
617 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
618 tstate = boot->tstate; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
619 tstate->thread_id = PyThread_get_thread_ident(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
620 _PyThreadState_Init(tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
621 PyEval_AcquireThread(tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
622 nb_threads++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
623 res = PyEval_CallObjectWithKeywords( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
624 boot->func, boot->args, boot->keyw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
625 if (res == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
626 if (PyErr_ExceptionMatches(PyExc_SystemExit)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
627 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
628 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
629 PyObject *file; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
630 PySys_WriteStderr( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
631 "Unhandled exception in thread started by "); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
632 file = PySys_GetObject("stderr"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
633 if (file) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
634 PyFile_WriteObject(boot->func, file, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
635 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
636 PyObject_Print(boot->func, stderr, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
637 PySys_WriteStderr("\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
638 PyErr_PrintEx(0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
639 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
640 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
641 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
642 Py_DECREF(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
643 Py_DECREF(boot->func); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
644 Py_DECREF(boot->args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
645 Py_XDECREF(boot->keyw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
646 PyMem_DEL(boot_raw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
647 nb_threads--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
648 PyThreadState_Clear(tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
649 PyThreadState_DeleteCurrent(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
650 PyThread_exit_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
652 |
| 4751 | 653 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
654 thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
656 PyObject *func, *args, *keyw = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
657 struct bootstate *boot; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
658 long ident; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
660 if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
661 &func, &args, &keyw)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
662 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
663 if (!PyCallable_Check(func)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
664 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
665 "first arg must be callable"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
666 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
667 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
668 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
669 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
670 "2nd arg must be a tuple"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
671 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
672 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
673 if (keyw != NULL && !PyDict_Check(keyw)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
674 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
675 "optional 3rd arg must be a dictionary"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
676 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
677 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
678 boot = PyMem_NEW(struct bootstate, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
679 if (boot == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
680 return PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
681 boot->interp = PyThreadState_GET()->interp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
682 boot->func = func; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
683 boot->args = args; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
684 boot->keyw = keyw; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
685 boot->tstate = _PyThreadState_Prealloc(boot->interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
686 if (boot->tstate == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
687 PyMem_DEL(boot); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
688 return PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
689 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
690 Py_INCREF(func); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
691 Py_INCREF(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
692 Py_XINCREF(keyw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
693 PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
694 ident = PyThread_start_new_thread(t_bootstrap, (void*) boot); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
695 if (ident == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
696 PyErr_SetString(ThreadError, "can't start new thread"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
697 Py_DECREF(func); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
698 Py_DECREF(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
699 Py_XDECREF(keyw); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
700 PyThreadState_Clear(boot->tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
701 PyMem_DEL(boot); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
702 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
703 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
704 return PyInt_FromLong(ident); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
707 PyDoc_STRVAR(start_new_doc, |
| 20266 | 708 "start_new_thread(function, args[, kwargs])\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
709 (start_new() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
710 \n\ |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
711 Start a new thread and return its identifier. The thread will call the\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
712 function with positional arguments from the tuple args and keyword arguments\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
713 taken from the optional dictionary kwargs. The thread exits when the\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
714 function returns; the return value is ignored. The thread will also exit\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
715 when the function raises an unhandled exception; a stack trace will be\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
716 printed unless the exception is SystemExit.\n"); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
717 |
| 4751 | 718 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
719 thread_PyThread_exit_thread(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
721 PyErr_SetNone(PyExc_SystemExit); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
722 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
725 PyDoc_STRVAR(exit_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
726 "exit()\n\ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
727 (PyThread_exit_thread() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
728 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
729 This is synonymous to ``raise SystemExit''. It will cause the current\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
730 thread to exit silently unless the exception is caught."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
731 |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
732 static PyObject * |
| 29498 | 733 thread_PyThread_interrupt_main(PyObject * self) |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
734 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
735 PyErr_SetInterrupt(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
736 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
737 return Py_None; |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
738 } |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
739 |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
740 PyDoc_STRVAR(interrupt_doc, |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
741 "interrupt_main()\n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
742 \n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
743 Raise a KeyboardInterrupt in the main thread.\n\ |
| 29498 | 744 A subthread can use this function to interrupt the main thread." |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
745 ); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
746 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
747 static lockobject *newlockobject(void); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
748 |
| 4751 | 749 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
750 thread_PyThread_allocate_lock(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
751 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
752 return (PyObject *) newlockobject(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
755 PyDoc_STRVAR(allocate_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
756 "allocate_lock() -> lock object\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
757 (allocate() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
758 \n\ |
|
64078
756f8b398230
Merged revisions 84106 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
63899
diff
changeset
|
759 Create a new lock object. See help(LockType) for information about locks."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
760 |
| 4751 | 761 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
762 thread_get_ident(PyObject *self) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
763 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
764 long ident; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
765 ident = PyThread_get_thread_ident(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
766 if (ident == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
767 PyErr_SetString(ThreadError, "no current thread ident"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
768 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
769 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
770 return PyInt_FromLong(ident); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
771 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
772 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
773 PyDoc_STRVAR(get_ident_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
774 "get_ident() -> integer\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
775 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
776 Return a non-zero integer that uniquely identifies the current thread\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
777 amongst other threads that exist simultaneously.\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
778 This may be used to identify per-thread resources.\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
779 Even though on some platforms threads identities may appear to be\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
780 allocated consecutive numbers starting at 1, this behavior should not\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
781 be relied upon, and the number should be seen purely as a magic cookie.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
782 A thread's identity may be reused for another thread after it exits."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
783 |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
784 static PyObject * |
|
56980
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
785 thread__count(PyObject *self) |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
786 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
787 return PyInt_FromLong(nb_threads); |
|
56980
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
788 } |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
789 |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
790 PyDoc_STRVAR(_count_doc, |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
791 "_count() -> integer\n\ |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
792 \n\ |
|
56991
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
793 \ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
794 Return the number of currently running Python threads, excluding \n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
795 the main thread. The returned number comprises all threads created\n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
796 through `start_new_thread()` as well as `threading.Thread`, and not\n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
797 yet finished.\n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
798 \n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
799 This function is meant for internal and specialized purposes only.\n\ |
|
d56b103490a5
Remove official documentation entry for thread._count() and make the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56980
diff
changeset
|
800 In most applications `threading.enumerate()` should be used instead."); |
|
56980
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
801 |
|
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
802 static PyObject * |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
803 thread_stack_size(PyObject *self, PyObject *args) |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
804 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
805 size_t old_size; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
806 Py_ssize_t new_size = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
807 int rc; |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
808 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
809 if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
810 return NULL; |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
811 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
812 if (new_size < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
813 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
814 "size must be 0 or a positive value"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
815 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
816 } |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
817 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
818 old_size = PyThread_get_stacksize(); |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
819 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
820 rc = PyThread_set_stacksize((size_t) new_size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
821 if (rc == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
822 PyErr_Format(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
823 "size not valid: %zd bytes", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
824 new_size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
825 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
826 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
827 if (rc == -2) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
828 PyErr_SetString(ThreadError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
829 "setting stack size not supported"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
830 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
831 } |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
832 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
833 return PyInt_FromSsize_t((Py_ssize_t) old_size); |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
834 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
835 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
836 PyDoc_STRVAR(stack_size_doc, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
837 "stack_size([size]) -> size\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
838 \n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
839 Return the thread stack size used when creating new threads. The\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
840 optional size argument specifies the stack size (in bytes) to be used\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
841 for subsequently created threads, and must be 0 (use platform or\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
842 configured default) or a positive integer value of at least 32,768 (32k).\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
843 If changing the thread stack size is unsupported, a ThreadError\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
844 exception is raised. If the specified size is invalid, a ValueError\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
845 exception is raised, and the stack size is unmodified. 32k bytes\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
846 currently the minimum supported stack size value to guarantee\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
847 sufficient stack space for the interpreter itself.\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
848 \n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
849 Note that some platforms may have particular restrictions on values for\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
850 the stack size, such as requiring a minimum stack size larger than 32kB or\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
851 requiring allocation in multiples of the system memory page size\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
852 - platform documentation should be referred to for more information\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
853 (4kB pages are common; using multiples of 4096 for the stack size is\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
854 the suggested approach in the absence of more specific information)."); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
855 |
| 4751 | 856 static PyMethodDef thread_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
857 {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
858 METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
859 start_new_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
860 {"start_new", (PyCFunction)thread_PyThread_start_new_thread, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
861 METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
862 start_new_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
863 {"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
864 METH_NOARGS, allocate_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
865 {"allocate", (PyCFunction)thread_PyThread_allocate_lock, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
866 METH_NOARGS, allocate_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
867 {"exit_thread", (PyCFunction)thread_PyThread_exit_thread, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
868 METH_NOARGS, exit_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
869 {"exit", (PyCFunction)thread_PyThread_exit_thread, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
870 METH_NOARGS, exit_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
871 {"interrupt_main", (PyCFunction)thread_PyThread_interrupt_main, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
872 METH_NOARGS, interrupt_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
873 {"get_ident", (PyCFunction)thread_get_ident, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
874 METH_NOARGS, get_ident_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
875 {"_count", (PyCFunction)thread__count, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
876 METH_NOARGS, _count_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
877 {"stack_size", (PyCFunction)thread_stack_size, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
878 METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
879 stack_size_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
880 {NULL, NULL} /* sentinel */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
881 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
882 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
883 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
884 /* Initialization function */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
885 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
886 PyDoc_STRVAR(thread_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
887 "This module provides primitive operations to write multi-threaded programs.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
888 The 'threading' module provides a more convenient interface."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
889 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
890 PyDoc_STRVAR(lock_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
891 "A lock object is a synchronization primitive. To create a lock,\n\ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
892 call the PyThread_allocate_lock() function. Methods are:\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
893 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
894 acquire() -- lock the lock, possibly blocking until it can be obtained\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
895 release() -- unlock of the lock\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
896 locked() -- test whether the lock is currently locked\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
897 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
898 A lock is not owned by the thread that locked it; another thread may\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
899 unlock it. A thread attempting to lock a lock that it has already locked\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
900 will block until another thread unlocks it. Deadlocks may ensue."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
901 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
902 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13497
diff
changeset
|
903 initthread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
904 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
905 PyObject *m, *d; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
906 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
907 /* Initialize types: */ |
|
63899
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
908 if (PyType_Ready(&localdummytype) < 0) |
|
b65dce5902a2
Merged revisions 83918 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
909 return; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
910 if (PyType_Ready(&localtype) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
911 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
912 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
913 /* Create the module and add the functions */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
914 m = Py_InitModule3("thread", thread_methods, thread_doc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
915 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
916 return; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
917 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
918 /* Add a symbolic constant */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
919 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
920 ThreadError = PyErr_NewException("thread.error", NULL, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
921 PyDict_SetItemString(d, "error", ThreadError); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
922 Locktype.tp_doc = lock_doc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
923 if (PyType_Ready(&Locktype) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
924 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
925 Py_INCREF(&Locktype); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
926 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
928 Py_INCREF(&localtype); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
929 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
930 return; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
931 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
932 nb_threads = 0; |
|
56980
29fe5e7bd6ee
Issue #7222: Make thread "reaping" more reliable so that reference
Antoine Pitrou <solipsis@pitrou.net>
parents:
56274
diff
changeset
|
933 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
934 /* Initialize the C thread library */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59315
diff
changeset
|
935 PyThread_init_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
936 } |
