summaryrefslogtreecommitdiff
path: root/Modules/_threadmodule.c
diff options
context:
space:
mode:
authorMartin v. L?wis <martin@v.loewis.de>2012-06-03 12:00:48 +0200
committerMartin v. L?wis <martin@v.loewis.de>2012-06-03 12:00:48 +0200
commit183bc7b78cb50c73b3142710b3b8fbafde4a3833 (patch)
tree8a29bbfd852dccb5f14340c8d1c6309cf8fdfb72 /Modules/_threadmodule.c
parent15670dc71126aabce6daca6c8d32f55ea146cc11 (diff)
parent9fe4e3d311149c5f07073f7c55509fcfd7dde47e (diff)
downloadcpython-183bc7b78cb50c73b3142710b3b8fbafde4a3833.tar.gz
Merge 3.2: issue #14937.
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 5f76a7b6c2..8f66cb37e0 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -53,6 +53,7 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
_PyTime_timeval curtime;
_PyTime_timeval endtime;
+
if (microseconds > 0) {
_PyTime_gettimeofday(&endtime);
endtime.tv_sec += microseconds / (1000 * 1000);
@@ -75,7 +76,7 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
/* If we're using a timeout, recompute the timeout after processing
* signals, since those can take time. */
- if (microseconds >= 0) {
+ if (microseconds > 0) {
_PyTime_gettimeofday(&curtime);
microseconds = ((endtime.tv_sec - curtime.tv_sec) * 1000000 +
(endtime.tv_usec - curtime.tv_usec));
@@ -413,6 +414,12 @@ rlock_release_save(rlockobject *self)
long owner;
unsigned long count;
+ if (self->rlock_count == 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot release un-acquired lock");
+ return NULL;
+ }
+
owner = self->rlock_owner;
count = self->rlock_count;
self->rlock_count = 0;
@@ -1225,11 +1232,9 @@ the suggested approach in the absence of more specific information).");
static PyMethodDef thread_methods[] = {
{"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread,
- METH_VARARGS,
- start_new_doc},
+ METH_VARARGS, start_new_doc},
{"start_new", (PyCFunction)thread_PyThread_start_new_thread,
- METH_VARARGS,
- start_new_doc},
+ METH_VARARGS, start_new_doc},
{"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock,
METH_NOARGS, allocate_doc},
{"allocate", (PyCFunction)thread_PyThread_allocate_lock,
@@ -1245,8 +1250,7 @@ static PyMethodDef thread_methods[] = {
{"_count", (PyCFunction)thread__count,
METH_NOARGS, _count_doc},
{"stack_size", (PyCFunction)thread_stack_size,
- METH_VARARGS,
- stack_size_doc},
+ METH_VARARGS, stack_size_doc},
{NULL, NULL} /* sentinel */
};
@@ -1310,7 +1314,9 @@ PyInit__thread(void)
/* Add a symbolic constant */
d = PyModule_GetDict(m);
- ThreadError = PyErr_NewException("_thread.error", NULL, NULL);
+ ThreadError = PyExc_RuntimeError;
+ Py_INCREF(ThreadError);
+
PyDict_SetItemString(d, "error", ThreadError);
Locktype.tp_doc = lock_doc;
Py_INCREF(&Locktype);