Mercurial > cpython-lru_cache-weakref
annotate Modules/_threadmodule.c @ 57685:2fdcd73c32aa
Merged revisions 76785 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76785 | benjamin.peterson | 2009-12-13 08:18:08 -0600 (Sun, 13 Dec 2009) | 1 line
add 2.6.x point releases
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sun, 13 Dec 2009 14:21:46 +0000 |
| parents | 6d91aaadddd0 |
| children | 798e0d0c7246 |
| 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" |
|
56440
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
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; |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
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 { |
| 4751 | 22 PyObject_HEAD |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
23 PyThread_type_lock lock_lock; |
|
56440
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
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 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
30 assert(self->lock_lock); |
|
56440
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
diff
changeset
|
31 if (self->in_weakreflist != NULL) |
|
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
diff
changeset
|
32 PyObject_ClearWeakRefs((PyObject *) self); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 /* Unlock the lock so it's safe to free it */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
34 PyThread_acquire_lock(self->lock_lock, 0); |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
35 PyThread_release_lock(self->lock_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
37 PyThread_free_lock(self->lock_lock); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
38 PyObject_Del(self); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
| 4751 | 41 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
42 lock_PyThread_acquire_lock(lockobject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 { |
| 22709 | 44 int i = 1; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
| 22709 | 46 if (!PyArg_ParseTuple(args, "|i:acquire", &i)) |
| 47 return NULL; | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
| 4751 | 49 Py_BEGIN_ALLOW_THREADS |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
50 i = PyThread_acquire_lock(self->lock_lock, i); |
| 4751 | 51 Py_END_ALLOW_THREADS |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 |
|
34998
25a0e1faa8a5
Delete some vestigial code; execution will never reach the 'if' statement if args is NULL
Andrew M. Kuchling <amk@amk.ca>
parents:
34619
diff
changeset
|
53 return PyBool_FromLong((long)i); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
56 PyDoc_STRVAR(acquire_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
57 "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
|
58 (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
|
59 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
| 4751 | 67 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
|
68 lock_PyThread_release_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 /* Sanity check: the lock must be locked */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
71 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
72 PyThread_release_lock(self->lock_lock); |
| 4751 | 73 PyErr_SetString(ThreadError, "release unlocked lock"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
77 PyThread_release_lock(self->lock_lock); |
| 4751 | 78 Py_INCREF(Py_None); |
| 79 return Py_None; | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
82 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
|
83 "release()\n\ |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
84 (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
|
85 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 |
| 4751 | 90 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
|
91 lock_locked_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
93 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
94 PyThread_release_lock(self->lock_lock); |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
95 return PyBool_FromLong(0L); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
97 return PyBool_FromLong(1L); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
100 PyDoc_STRVAR(locked_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
101 "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
|
102 (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
|
103 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
104 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
|
105 |
| 4751 | 106 static PyMethodDef lock_methods[] = { |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
107 {"acquire_lock", (PyCFunction)lock_PyThread_acquire_lock, |
| 22709 | 108 METH_VARARGS, acquire_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
109 {"acquire", (PyCFunction)lock_PyThread_acquire_lock, |
| 22709 | 110 METH_VARARGS, acquire_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
111 {"release_lock", (PyCFunction)lock_PyThread_release_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
112 METH_NOARGS, release_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
113 {"release", (PyCFunction)lock_PyThread_release_lock, |
|
22562
303b6ad13a32
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22561
diff
changeset
|
114 METH_NOARGS, release_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
115 {"locked_lock", (PyCFunction)lock_locked_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
116 METH_NOARGS, locked_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
117 {"locked", (PyCFunction)lock_locked_lock, |
|
22562
303b6ad13a32
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22561
diff
changeset
|
118 METH_NOARGS, locked_doc}, |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36324
diff
changeset
|
119 {"__enter__", (PyCFunction)lock_PyThread_acquire_lock, |
|
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36324
diff
changeset
|
120 METH_VARARGS, acquire_doc}, |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
121 {"__exit__", (PyCFunction)lock_PyThread_release_lock, |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
122 METH_VARARGS, 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
|
123 {NULL, NULL} /* sentinel */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 |
| 4751 | 126 static PyTypeObject Locktype = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42122
diff
changeset
|
127 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
47285
afbde360dd1a
Create the dbm package from PEP 3108. #2881.
Georg Brandl <georg@python.org>
parents:
47266
diff
changeset
|
128 "_thread.lock", /*tp_name*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
129 sizeof(lockobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
130 0, /*tp_itemsize*/ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
132 (destructor)lock_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
133 0, /*tp_print*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
134 0, /*tp_getattr*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
135 0, /*tp_setattr*/ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48413
diff
changeset
|
136 0, /*tp_reserved*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
137 0, /*tp_repr*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
138 0, /*tp_as_number*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
139 0, /*tp_as_sequence*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
140 0, /*tp_as_mapping*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
141 0, /*tp_hash*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
142 0, /*tp_call*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
143 0, /*tp_str*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
144 0, /*tp_getattro*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
145 0, /*tp_setattro*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
146 0, /*tp_as_buffer*/ |
|
56428
5458c20aa0cf
rollback the merge of r74524 because it causes failures in test_multiprocessing
Benjamin Peterson <benjamin@python.org>
parents:
56376
diff
changeset
|
147 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
148 0, /*tp_doc*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
149 0, /*tp_traverse*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
150 0, /*tp_clear*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
151 0, /*tp_richcompare*/ |
|
56440
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
diff
changeset
|
152 offsetof(lockobject, in_weakreflist), /*tp_weaklistoffset*/ |
|
48413
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
153 0, /*tp_iter*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
154 0, /*tp_iternext*/ |
|
7e56016a6565
#3247 Get rid of Py_FindMethod; use tp_members instead.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48388
diff
changeset
|
155 lock_methods, /*tp_methods*/ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 |
|
57172
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
158 /* Recursive lock objects */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
159 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
160 typedef struct { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
161 PyObject_HEAD |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
162 PyThread_type_lock rlock_lock; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
163 long rlock_owner; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
164 unsigned long rlock_count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
165 PyObject *in_weakreflist; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
166 } rlockobject; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
167 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
168 static void |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
169 rlock_dealloc(rlockobject *self) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
170 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
171 assert(self->rlock_lock); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
172 if (self->in_weakreflist != NULL) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
173 PyObject_ClearWeakRefs((PyObject *) self); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
174 /* Unlock the lock so it's safe to free it */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
175 if (self->rlock_count > 0) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
176 PyThread_release_lock(self->rlock_lock); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
177 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
178 PyThread_free_lock(self->rlock_lock); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
179 Py_TYPE(self)->tp_free(self); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
180 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
181 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
182 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
183 rlock_acquire(rlockobject *self, PyObject *args, PyObject *kwds) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
184 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
185 char *kwlist[] = {"blocking", NULL}; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
186 int blocking = 1; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
187 long tid; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
188 int r = 1; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
189 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
190 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:acquire", kwlist, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
191 &blocking)) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
192 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
193 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
194 tid = PyThread_get_thread_ident(); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
195 if (self->rlock_count > 0 && tid == self->rlock_owner) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
196 unsigned long count = self->rlock_count + 1; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
197 if (count <= self->rlock_count) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
198 PyErr_SetString(PyExc_OverflowError, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
199 "Internal lock count overflowed"); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
200 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
201 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
202 self->rlock_count = count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
203 Py_RETURN_TRUE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
204 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
205 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
206 if (self->rlock_count > 0 || |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
207 !PyThread_acquire_lock(self->rlock_lock, 0)) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
208 if (!blocking) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
209 Py_RETURN_FALSE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
210 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
211 Py_BEGIN_ALLOW_THREADS |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
212 r = PyThread_acquire_lock(self->rlock_lock, blocking); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
213 Py_END_ALLOW_THREADS |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
214 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
215 if (r) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
216 assert(self->rlock_count == 0); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
217 self->rlock_owner = tid; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
218 self->rlock_count = 1; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
219 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
220 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
221 return PyBool_FromLong(r); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
222 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
223 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
224 PyDoc_STRVAR(rlock_acquire_doc, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
225 "acquire(blocking=True) -> bool\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
226 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
227 Lock the lock. `blocking` indicates whether we should wait\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
228 for the lock to be available or not. If `blocking` is False\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
229 and another thread holds the lock, the method will return False\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
230 immediately. If `blocking` is True and another thread holds\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
231 the lock, the method will wait for the lock to be released,\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
232 take it and then return True.\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
233 (note: the blocking operation is not interruptible.)\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
234 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
235 In all other cases, the method will return True immediately.\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
236 Precisely, if the current thread already holds the lock, its\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
237 internal counter is simply incremented. If nobody holds the lock,\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
238 the lock is taken and its internal counter initialized to 1."); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
239 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
240 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
241 rlock_release(rlockobject *self) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
242 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
243 long tid = PyThread_get_thread_ident(); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
244 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
245 if (self->rlock_count == 0 || self->rlock_owner != tid) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
246 PyErr_SetString(PyExc_RuntimeError, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
247 "cannot release un-acquired lock"); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
248 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
249 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
250 if (--self->rlock_count == 0) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
251 self->rlock_owner = 0; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
252 PyThread_release_lock(self->rlock_lock); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
253 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
254 Py_RETURN_NONE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
255 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
256 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
257 PyDoc_STRVAR(rlock_release_doc, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
258 "release()\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
259 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
260 Release the lock, allowing another thread that is blocked waiting for\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
261 the lock to acquire the lock. The lock must be in the locked state,\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
262 and must be locked by the same thread that unlocks it; otherwise a\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
263 `RuntimeError` is raised.\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
264 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
265 Do note that if the lock was acquire()d several times in a row by the\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
266 current thread, release() needs to be called as many times for the lock\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
267 to be available for other threads."); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
268 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
269 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
270 rlock_acquire_restore(rlockobject *self, PyObject *arg) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
271 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
272 long owner; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
273 unsigned long count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
274 int r = 1; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
275 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
276 if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner)) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
277 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
278 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
279 if (!PyThread_acquire_lock(self->rlock_lock, 0)) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
280 Py_BEGIN_ALLOW_THREADS |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
281 r = PyThread_acquire_lock(self->rlock_lock, 1); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
282 Py_END_ALLOW_THREADS |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
283 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
284 if (!r) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
285 PyErr_SetString(ThreadError, "couldn't acquire lock"); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
286 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
287 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
288 assert(self->rlock_count == 0); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
289 self->rlock_owner = owner; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
290 self->rlock_count = count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
291 Py_RETURN_NONE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
292 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
293 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
294 PyDoc_STRVAR(rlock_acquire_restore_doc, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
295 "_acquire_restore(state) -> None\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
296 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
297 For internal use by `threading.Condition`."); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
298 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
299 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
300 rlock_release_save(rlockobject *self) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
301 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
302 long owner; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
303 unsigned long count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
304 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
305 owner = self->rlock_owner; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
306 count = self->rlock_count; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
307 self->rlock_count = 0; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
308 self->rlock_owner = 0; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
309 PyThread_release_lock(self->rlock_lock); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
310 return Py_BuildValue("kl", count, owner); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
311 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
312 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
313 PyDoc_STRVAR(rlock_release_save_doc, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
314 "_release_save() -> tuple\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
315 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
316 For internal use by `threading.Condition`."); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
317 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
318 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
319 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
320 rlock_is_owned(rlockobject *self) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
321 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
322 long tid = PyThread_get_thread_ident(); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
323 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
324 if (self->rlock_count > 0 && self->rlock_owner == tid) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
325 Py_RETURN_TRUE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
326 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
327 Py_RETURN_FALSE; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
328 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
329 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
330 PyDoc_STRVAR(rlock_is_owned_doc, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
331 "_is_owned() -> bool\n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
332 \n\ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
333 For internal use by `threading.Condition`."); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
334 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
335 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
336 rlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
337 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
338 rlockobject *self; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
339 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
340 self = (rlockobject *) type->tp_alloc(type, 0); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
341 if (self != NULL) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
342 self->rlock_lock = PyThread_allocate_lock(); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
343 if (self->rlock_lock == NULL) { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
344 type->tp_free(self); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
345 PyErr_SetString(ThreadError, "can't allocate lock"); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
346 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
347 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
348 self->in_weakreflist = NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
349 self->rlock_owner = 0; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
350 self->rlock_count = 0; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
351 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
352 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
353 return (PyObject *) self; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
354 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
355 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
356 static PyObject * |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
357 rlock_repr(rlockobject *self) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
358 { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
359 return PyUnicode_FromFormat("<%s owner=%ld count=%lu>", |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
360 Py_TYPE(self)->tp_name, self->rlock_owner, self->rlock_count); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
361 } |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
362 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
363 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
364 static PyMethodDef rlock_methods[] = { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
365 {"acquire", (PyCFunction)rlock_acquire, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
366 METH_VARARGS | METH_KEYWORDS, rlock_acquire_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
367 {"release", (PyCFunction)rlock_release, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
368 METH_NOARGS, rlock_release_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
369 {"_is_owned", (PyCFunction)rlock_is_owned, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
370 METH_NOARGS, rlock_is_owned_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
371 {"_acquire_restore", (PyCFunction)rlock_acquire_restore, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
372 METH_O, rlock_acquire_restore_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
373 {"_release_save", (PyCFunction)rlock_release_save, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
374 METH_NOARGS, rlock_release_save_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
375 {"__enter__", (PyCFunction)rlock_acquire, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
376 METH_VARARGS | METH_KEYWORDS, rlock_acquire_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
377 {"__exit__", (PyCFunction)rlock_release, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
378 METH_VARARGS, rlock_release_doc}, |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
379 {NULL, NULL} /* sentinel */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
380 }; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
381 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
382 |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
383 static PyTypeObject RLocktype = { |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
384 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
385 "_thread.RLock", /*tp_name*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
386 sizeof(rlockobject), /*tp_size*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
387 0, /*tp_itemsize*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
388 /* methods */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
389 (destructor)rlock_dealloc, /*tp_dealloc*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
390 0, /*tp_print*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
391 0, /*tp_getattr*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
392 0, /*tp_setattr*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
393 0, /*tp_reserved*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
394 (reprfunc)rlock_repr, /*tp_repr*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
395 0, /*tp_as_number*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
396 0, /*tp_as_sequence*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
397 0, /*tp_as_mapping*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
398 0, /*tp_hash*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
399 0, /*tp_call*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
400 0, /*tp_str*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
401 0, /*tp_getattro*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
402 0, /*tp_setattro*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
403 0, /*tp_as_buffer*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
404 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
405 0, /*tp_doc*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
406 0, /*tp_traverse*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
407 0, /*tp_clear*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
408 0, /*tp_richcompare*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
409 offsetof(rlockobject, in_weakreflist), /*tp_weaklistoffset*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
410 0, /*tp_iter*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
411 0, /*tp_iternext*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
412 rlock_methods, /*tp_methods*/ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
413 0, /* tp_members */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
414 0, /* tp_getset */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
415 0, /* tp_base */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
416 0, /* tp_dict */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
417 0, /* tp_descr_get */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
418 0, /* tp_descr_set */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
419 0, /* tp_dictoffset */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
420 0, /* tp_init */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
421 PyType_GenericAlloc, /* tp_alloc */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
422 rlock_new /* tp_new */ |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
423 }; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
424 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
425 static lockobject * |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
426 newlockobject(void) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
427 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
428 lockobject *self; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
429 self = PyObject_New(lockobject, &Locktype); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
430 if (self == NULL) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
431 return NULL; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
432 self->lock_lock = PyThread_allocate_lock(); |
|
56440
29908f2bc93f
Merged revisions 74524 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56428
diff
changeset
|
433 self->in_weakreflist = NULL; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
434 if (self->lock_lock == NULL) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
435 PyObject_Del(self); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
436 self = NULL; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
437 PyErr_SetString(ThreadError, "can't allocate lock"); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
438 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
439 return self; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
440 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
441 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
442 /* Thread-local objects */ |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
443 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
444 #include "structmember.h" |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
445 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
446 typedef struct { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
447 PyObject_HEAD |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
448 PyObject *key; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
449 PyObject *args; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
450 PyObject *kw; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
451 PyObject *dict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
452 } localobject; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
453 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
454 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
455 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
|
456 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
457 localobject *self; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
458 PyObject *tdict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
459 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
460 if (type->tp_init == PyBaseObject_Type.tp_init |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
461 && ((args && PyObject_IsTrue(args)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
462 || (kw && PyObject_IsTrue(kw)))) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
463 PyErr_SetString(PyExc_TypeError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
464 "Initialization arguments are not supported"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
465 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
466 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
467 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
468 self = (localobject *)type->tp_alloc(type, 0); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
469 if (self == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
470 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
471 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
472 Py_XINCREF(args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
473 self->args = args; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
474 Py_XINCREF(kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
475 self->kw = kw; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
476 self->dict = NULL; /* making sure */ |
|
42122
6710f453cf4a
Make "thread.local" key a unicode object.
Walter Dörwald <walter@livinglogic.de>
parents:
40450
diff
changeset
|
477 self->key = PyUnicode_FromFormat("thread.local.%p", self); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
478 if (self->key == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
479 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
480 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
481 self->dict = PyDict_New(); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
482 if (self->dict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
483 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
484 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
485 tdict = PyThreadState_GetDict(); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
486 if (tdict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
487 PyErr_SetString(PyExc_SystemError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
488 "Couldn't get thread-state dictionary"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
489 goto err; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
490 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
491 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
492 if (PyDict_SetItem(tdict, self->key, self->dict) < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
493 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
494 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
495 return (PyObject *)self; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
496 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
497 err: |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
498 Py_DECREF(self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
499 return NULL; |
|
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 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
502 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
503 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
|
504 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
505 Py_VISIT(self->args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
506 Py_VISIT(self->kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
507 Py_VISIT(self->dict); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
508 return 0; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
509 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
510 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
511 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
512 local_clear(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
513 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
514 Py_CLEAR(self->args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
515 Py_CLEAR(self->kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
516 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
517 return 0; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
518 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
519 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
520 static void |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
521 local_dealloc(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
522 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
523 PyThreadState *tstate; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
524 if (self->key |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
525 && (tstate = PyThreadState_Get()) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
526 && tstate->interp) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
527 for(tstate = PyInterpreterState_ThreadHead(tstate->interp); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
528 tstate; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
529 tstate = PyThreadState_Next(tstate)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
530 if (tstate->dict && |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
531 PyDict_GetItem(tstate->dict, self->key)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
532 PyDict_DelItem(tstate->dict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
533 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
534 |
|
56277
74b18a267cd7
Merged revisions 75125 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
51271
diff
changeset
|
535 Py_XDECREF(self->key); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
536 local_clear(self); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
537 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
|
538 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
539 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
540 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
541 _ldict(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
542 { |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
543 PyObject *tdict, *ldict; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
544 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
545 tdict = PyThreadState_GetDict(); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
546 if (tdict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
547 PyErr_SetString(PyExc_SystemError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
548 "Couldn't get thread-state dictionary"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
549 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
550 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
551 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
552 ldict = PyDict_GetItem(tdict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
553 if (ldict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
554 ldict = PyDict_New(); /* we own ldict */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
555 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
556 if (ldict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
557 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
558 else { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
559 int i = PyDict_SetItem(tdict, self->key, ldict); |
| 36895 | 560 Py_DECREF(ldict); /* now ldict is borrowed */ |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
561 if (i < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
562 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
563 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
564 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
565 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
566 Py_INCREF(ldict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
567 self->dict = ldict; /* still borrowed */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
568 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
569 if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init && |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
570 Py_TYPE(self)->tp_init((PyObject*)self, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
571 self->args, self->kw) < 0) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
572 /* we need to get rid of ldict from thread so |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
573 we create a new one the next time we do an attr |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
574 acces */ |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
575 PyDict_DelItem(tdict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
576 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
577 } |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
578 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
579 } |
|
48388
e29b4ce641f9
Merged revisions 64601 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47580
diff
changeset
|
580 |
|
e29b4ce641f9
Merged revisions 64601 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47580
diff
changeset
|
581 /* The call to tp_init above may have caused another thread to run. |
|
e29b4ce641f9
Merged revisions 64601 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47580
diff
changeset
|
582 Install our ldict again. */ |
|
e29b4ce641f9
Merged revisions 64601 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47580
diff
changeset
|
583 if (self->dict != ldict) { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
584 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
585 Py_INCREF(ldict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
586 self->dict = ldict; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
587 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
588 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
589 return ldict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
590 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
591 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
592 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
593 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
|
594 { |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
595 PyObject *ldict; |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
596 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
597 ldict = _ldict(self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
598 if (ldict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
599 return -1; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
600 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
601 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
|
602 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
603 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
604 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
605 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
|
606 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
607 if (self->dict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
608 PyErr_SetString(PyExc_AttributeError, "__dict__"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
609 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
610 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
611 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
612 Py_INCREF(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
613 return self->dict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
614 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
615 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
616 static PyGetSetDef local_getset[] = { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
617 {"__dict__", (getter)local_getdict, (setter)NULL, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
618 "Local-data dictionary", NULL}, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
619 {NULL} /* Sentinel */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
620 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
621 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
622 static PyObject *local_getattro(localobject *, PyObject *); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
623 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
624 static PyTypeObject localtype = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42122
diff
changeset
|
625 PyVarObject_HEAD_INIT(NULL, 0) |
|
47285
afbde360dd1a
Create the dbm package from PEP 3108. #2881.
Georg Brandl <georg@python.org>
parents:
47266
diff
changeset
|
626 /* tp_name */ "_thread._local", |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
627 /* tp_basicsize */ sizeof(localobject), |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
628 /* tp_itemsize */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
629 /* tp_dealloc */ (destructor)local_dealloc, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
630 /* tp_print */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
631 /* tp_getattr */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
632 /* tp_setattr */ 0, |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48413
diff
changeset
|
633 /* tp_reserved */ 0, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
634 /* tp_repr */ 0, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
635 /* tp_as_number */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
636 /* tp_as_sequence */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
637 /* tp_as_mapping */ 0, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
638 /* tp_hash */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
639 /* tp_call */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
640 /* tp_str */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
641 /* tp_getattro */ (getattrofunc)local_getattro, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
642 /* tp_setattro */ (setattrofunc)local_setattro, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
643 /* tp_as_buffer */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
644 /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
645 /* tp_doc */ "Thread-local data", |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
646 /* tp_traverse */ (traverseproc)local_traverse, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
647 /* tp_clear */ (inquiry)local_clear, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
648 /* tp_richcompare */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
649 /* tp_weaklistoffset */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
650 /* tp_iter */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
651 /* tp_iternext */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
652 /* tp_methods */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
653 /* tp_members */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
654 /* tp_getset */ local_getset, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
655 /* tp_base */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
656 /* tp_dict */ 0, /* internal use */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
657 /* tp_descr_get */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
658 /* tp_descr_set */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
659 /* tp_dictoffset */ offsetof(localobject, dict), |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
660 /* tp_init */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
661 /* tp_alloc */ 0, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
662 /* tp_new */ local_new, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
663 /* tp_free */ 0, /* Low-level free-mem routine */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
664 /* 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
|
665 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
666 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
667 static PyObject * |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
668 local_getattro(localobject *self, PyObject *name) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
669 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
670 PyObject *ldict, *value; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
671 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
672 ldict = _ldict(self); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
673 if (ldict == NULL) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
674 return NULL; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
675 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
676 if (Py_TYPE(self) != &localtype) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
677 /* use generic lookup for subtypes */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
678 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
679 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
680 /* Optimization: just look in dict ourselves */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
681 value = PyDict_GetItem(ldict, name); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
682 if (value == NULL) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
683 /* Fall back on generic to get __class__ and __dict__ */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
684 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
685 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
686 Py_INCREF(value); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
687 return value; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
688 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 /* Module functions */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
692 struct bootstate { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
693 PyInterpreterState *interp; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
694 PyObject *func; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
695 PyObject *args; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
696 PyObject *keyw; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
697 }; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
699 static void |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
700 t_bootstrap(void *boot_raw) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
701 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
702 struct bootstate *boot = (struct bootstate *) boot_raw; |
| 35117 | 703 PyThreadState *tstate; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
704 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
|
705 |
| 35117 | 706 tstate = PyThreadState_New(boot->interp); |
| 707 | |
| 708 PyEval_AcquireThread(tstate); | |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
709 nb_threads++; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
710 res = PyEval_CallObjectWithKeywords( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
711 boot->func, boot->args, boot->keyw); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 if (res == NULL) { |
|
8433
7cdff8aa8318
t_bootstrap(): Use PyErr_ExceptionMatches(...) instead of PyErr_Occurred(...).
Fred Drake <fdrake@acm.org>
parents:
7211
diff
changeset
|
713 if (PyErr_ExceptionMatches(PyExc_SystemExit)) |
| 4751 | 714 PyErr_Clear(); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
715 else { |
|
28889
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
716 PyObject *file; |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
717 PySys_WriteStderr( |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
718 "Unhandled exception in thread started by "); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
719 file = PySys_GetObject("stderr"); |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
720 if (file != NULL && file != Py_None) |
|
28889
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
721 PyFile_WriteObject(boot->func, file, 0); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
722 else |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
723 PyObject_Print(boot->func, stderr, 0); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
724 PySys_WriteStderr("\n"); |
|
7211
c764217ae6eb
Don't store the exception info from an unhandled exception in a thread
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
725 PyErr_PrintEx(0); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
726 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
728 else |
| 4751 | 729 Py_DECREF(res); |
|
28889
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
730 Py_DECREF(boot->func); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
731 Py_DECREF(boot->args); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
732 Py_XDECREF(boot->keyw); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
733 PyMem_DEL(boot_raw); |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
734 nb_threads--; |
| 35117 | 735 PyThreadState_Clear(tstate); |
| 736 PyThreadState_DeleteCurrent(); | |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8567
diff
changeset
|
737 PyThread_exit_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
739 |
| 4751 | 740 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
741 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
|
742 { |
|
14363
5da406ebef55
The second argument to start_new_thread() is not a tuple, as pointed
Guido van Rossum <guido@python.org>
parents:
13820
diff
changeset
|
743 PyObject *func, *args, *keyw = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
744 struct bootstate *boot; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
745 long ident; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
747 if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3, |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
748 &func, &args, &keyw)) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 return NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
750 if (!PyCallable_Check(func)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
751 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
752 "first arg must be callable"); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
753 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
754 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
755 if (!PyTuple_Check(args)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
756 PyErr_SetString(PyExc_TypeError, |
|
14363
5da406ebef55
The second argument to start_new_thread() is not a tuple, as pointed
Guido van Rossum <guido@python.org>
parents:
13820
diff
changeset
|
757 "2nd arg must be a tuple"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
758 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
760 if (keyw != NULL && !PyDict_Check(keyw)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
761 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
762 "optional 3rd arg must be a dictionary"); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
763 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
764 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
765 boot = PyMem_NEW(struct bootstate, 1); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
766 if (boot == NULL) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
767 return PyErr_NoMemory(); |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
29498
diff
changeset
|
768 boot->interp = PyThreadState_GET()->interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
769 boot->func = func; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
770 boot->args = args; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
771 boot->keyw = keyw; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
772 Py_INCREF(func); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
773 Py_INCREF(args); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
774 Py_XINCREF(keyw); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
775 PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
776 ident = PyThread_start_new_thread(t_bootstrap, (void*) boot); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
777 if (ident == -1) { |
|
34619
0dd146fed9dd
The error message "can't start new thread" should not end in a
Guido van Rossum <guido@python.org>
parents:
33254
diff
changeset
|
778 PyErr_SetString(ThreadError, "can't start new thread"); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
779 Py_DECREF(func); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
780 Py_DECREF(args); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
781 Py_XDECREF(keyw); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
782 PyMem_DEL(boot); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
783 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
784 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43855
diff
changeset
|
785 return PyLong_FromLong(ident); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
786 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
787 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
788 PyDoc_STRVAR(start_new_doc, |
| 20266 | 789 "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
|
790 (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
|
791 \n\ |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 |
| 4751 | 799 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
|
800 thread_PyThread_exit_thread(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
801 { |
| 4751 | 802 PyErr_SetNone(PyExc_SystemExit); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
803 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
804 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
805 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
806 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
|
807 "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
|
808 (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
|
809 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
810 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
|
811 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
|
812 |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
813 static PyObject * |
| 29498 | 814 thread_PyThread_interrupt_main(PyObject * self) |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
815 { |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
816 PyErr_SetInterrupt(); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
817 Py_INCREF(Py_None); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
818 return Py_None; |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
819 } |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
820 |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
821 PyDoc_STRVAR(interrupt_doc, |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
822 "interrupt_main()\n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
823 \n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
824 Raise a KeyboardInterrupt in the main thread.\n\ |
| 29498 | 825 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
|
826 ); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
827 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
828 #ifndef NO_EXIT_PROG |
| 4751 | 829 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
830 thread_PyThread_exit_prog(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
831 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
832 int sts; |
| 22709 | 833 if (!PyArg_ParseTuple(args, "i:exit_prog", &sts)) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
834 return NULL; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
835 Py_Exit(sts); /* Calls PyThread_exit_prog(sts) or _PyThread_exit_prog(sts) */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
836 for (;;) { } /* Should not be reached */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
837 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
838 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
839 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
840 static lockobject *newlockobject(void); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36926
diff
changeset
|
841 |
| 4751 | 842 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
|
843 thread_PyThread_allocate_lock(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
844 { |
| 4751 | 845 return (PyObject *) newlockobject(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
846 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
847 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
848 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
|
849 "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
|
850 (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
|
851 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
852 Create a new lock object. See LockType.__doc__ 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
|
853 |
| 4751 | 854 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
|
855 thread_get_ident(PyObject *self) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
856 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
857 long ident; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
858 ident = PyThread_get_thread_ident(); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
859 if (ident == -1) { |
| 4751 | 860 PyErr_SetString(ThreadError, "no current thread ident"); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
861 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
862 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43855
diff
changeset
|
863 return PyLong_FromLong(ident); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
864 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
865 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
866 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
|
867 "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
|
868 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 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
|
876 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
877 static PyObject * |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
878 thread__count(PyObject *self) |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
879 { |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
880 return PyLong_FromLong(nb_threads); |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
881 } |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
882 |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
883 PyDoc_STRVAR(_count_doc, |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
884 "_count() -> integer\n\ |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
885 \n\ |
|
56992
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
886 \ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
887 Return the number of currently running Python threads, excluding \n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
888 the main thread. The returned number comprises all threads created\n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
889 through `start_new_thread()` as well as `threading.Thread`, and not\n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
890 yet finished.\n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
891 \n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
892 This function is meant for internal and specialized purposes only.\n\ |
|
bf93e4df7bfb
Merged revisions 75969 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56981
diff
changeset
|
893 In most applications `threading.enumerate()` should be used instead."); |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
894 |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
895 static PyObject * |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
896 thread_stack_size(PyObject *self, PyObject *args) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
897 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
898 size_t old_size; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
899 Py_ssize_t new_size = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
900 int rc; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
901 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
902 if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size)) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
903 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
904 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
905 if (new_size < 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
906 PyErr_SetString(PyExc_ValueError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
907 "size must be 0 or a positive value"); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
908 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
909 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
910 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
911 old_size = PyThread_get_stacksize(); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
912 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
913 rc = PyThread_set_stacksize((size_t) new_size); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
914 if (rc == -1) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
915 PyErr_Format(PyExc_ValueError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
916 "size not valid: %zd bytes", |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
917 new_size); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
918 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
919 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
920 if (rc == -2) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
921 PyErr_SetString(ThreadError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
922 "setting stack size not supported"); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
923 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
924 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
925 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43855
diff
changeset
|
926 return PyLong_FromSsize_t((Py_ssize_t) old_size); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
927 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
928 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
929 PyDoc_STRVAR(stack_size_doc, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
930 "stack_size([size]) -> size\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
931 \n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
932 Return the thread stack size used when creating new threads. The\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
933 optional size argument specifies the stack size (in bytes) to be used\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
934 for subsequently created threads, and must be 0 (use platform or\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
935 configured default) or a positive integer value of at least 32,768 (32k).\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
936 If changing the thread stack size is unsupported, a ThreadError\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
937 exception is raised. If the specified size is invalid, a ValueError\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
938 exception is raised, and the stack size is unmodified. 32k bytes\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
939 currently the minimum supported stack size value to guarantee\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
940 sufficient stack space for the interpreter itself.\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
941 \n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
942 Note that some platforms may have particular restrictions on values for\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
943 the stack size, such as requiring a minimum stack size larger than 32kB or\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
944 requiring allocation in multiples of the system memory page size\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
945 - platform documentation should be referred to for more information\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
946 (4kB pages are common; using multiples of 4096 for the stack size is\n\ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
947 the suggested approach in the absence of more specific information)."); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
948 |
| 4751 | 949 static PyMethodDef thread_methods[] = { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
950 {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
951 METH_VARARGS, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
952 start_new_doc}, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
953 {"start_new", (PyCFunction)thread_PyThread_start_new_thread, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
954 METH_VARARGS, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
955 start_new_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
956 {"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
957 METH_NOARGS, allocate_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
958 {"allocate", (PyCFunction)thread_PyThread_allocate_lock, |
|
22584
bcd1fdf13acf
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22562
diff
changeset
|
959 METH_NOARGS, allocate_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
960 {"exit_thread", (PyCFunction)thread_PyThread_exit_thread, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
961 METH_NOARGS, exit_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
962 {"exit", (PyCFunction)thread_PyThread_exit_thread, |
|
22584
bcd1fdf13acf
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22562
diff
changeset
|
963 METH_NOARGS, exit_doc}, |
| 29498 | 964 {"interrupt_main", (PyCFunction)thread_PyThread_interrupt_main, |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
965 METH_NOARGS, interrupt_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
966 {"get_ident", (PyCFunction)thread_get_ident, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
967 METH_NOARGS, get_ident_doc}, |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
968 {"_count", (PyCFunction)thread__count, |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
969 METH_NOARGS, _count_doc}, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
970 {"stack_size", (PyCFunction)thread_stack_size, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
971 METH_VARARGS, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
972 stack_size_doc}, |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
973 #ifndef NO_EXIT_PROG |
| 22709 | 974 {"exit_prog", (PyCFunction)thread_PyThread_exit_prog, |
| 975 METH_VARARGS}, | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
976 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 {NULL, NULL} /* sentinel */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
978 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
981 /* Initialization function */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
982 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
983 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
|
984 "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
|
985 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
|
986 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
987 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
|
988 "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
|
989 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
|
990 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
991 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
|
992 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
|
993 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
|
994 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
995 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
|
996 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
|
997 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
|
998 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
999 static struct PyModuleDef threadmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1000 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1001 "_thread", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1002 thread_doc, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1003 -1, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1004 thread_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1005 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1006 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1007 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1008 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1009 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1010 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1011 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
1012 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1013 PyInit__thread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1014 { |
| 4751 | 1015 PyObject *m, *d; |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
1016 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
1017 /* Initialize types: */ |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
1018 if (PyType_Ready(&localtype) < 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1019 return NULL; |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
1020 if (PyType_Ready(&Locktype) < 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1021 return NULL; |
|
57172
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1022 if (PyType_Ready(&RLocktype) < 0) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1023 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1024 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1025 /* Create the module and add the functions */ |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1026 m = PyModule_Create(&threadmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35117
diff
changeset
|
1027 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1028 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1029 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1030 /* Add a symbolic constant */ |
| 4751 | 1031 d = PyModule_GetDict(m); |
|
47266
7fe3a8648ce2
Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents:
44351
diff
changeset
|
1032 ThreadError = PyErr_NewException("_thread.error", NULL, NULL); |
| 4751 | 1033 PyDict_SetItemString(d, "error", ThreadError); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
1034 Locktype.tp_doc = lock_doc; |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
1035 Py_INCREF(&Locktype); |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
1036 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1037 |
|
57172
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1038 Py_INCREF(&RLocktype); |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1039 if (PyModule_AddObject(m, "RLock", (PyObject *)&RLocktype) < 0) |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1040 return NULL; |
|
6d91aaadddd0
Issue #3001: Add a C implementation of recursive locks which is used by
Antoine Pitrou <solipsis@pitrou.net>
parents:
56992
diff
changeset
|
1041 |
| 35085 | 1042 Py_INCREF(&localtype); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
1043 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1044 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
1045 |
|
56981
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
1046 nb_threads = 0; |
|
6cf84e5a6dd7
Merged revisions 75958 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56440
diff
changeset
|
1047 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1048 /* Initialize the C thread library */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1049 PyThread_init_thread(); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47285
diff
changeset
|
1050 return m; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1051 } |
