aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_multiprocessing
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_multiprocessing')
-rw-r--r--Modules/_multiprocessing/multiprocessing.c25
-rw-r--r--Modules/_multiprocessing/multiprocessing.h6
-rw-r--r--Modules/_multiprocessing/semaphore.c20
3 files changed, 20 insertions, 31 deletions
diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c
index eb05c62b0d0..a77c3b341c4 100644
--- a/Modules/_multiprocessing/multiprocessing.c
+++ b/Modules/_multiprocessing/multiprocessing.c
@@ -10,25 +10,23 @@
#include "multiprocessing.h"
-PyObject *ProcessError, *BufferTooShort;
-
/*
* Function which raises exceptions based on error codes
*/
PyObject *
-mp_SetError(PyObject *Type, int num)
+_PyMp_SetError(PyObject *Type, int num)
{
switch (num) {
#ifdef MS_WINDOWS
case MP_STANDARD_ERROR:
if (Type == NULL)
- Type = PyExc_WindowsError;
+ Type = PyExc_OSError;
PyErr_SetExcFromWindowsErr(Type, 0);
break;
case MP_SOCKET_ERROR:
if (Type == NULL)
- Type = PyExc_WindowsError;
+ Type = PyExc_OSError;
PyErr_SetExcFromWindowsErr(Type, WSAGetLastError());
break;
#else /* !MS_WINDOWS */
@@ -159,19 +157,12 @@ PyInit__multiprocessing(void)
if (!module)
return NULL;
- /* Get copy of BufferTooShort */
- temp = PyImport_ImportModule("multiprocessing");
- if (!temp)
- return NULL;
- BufferTooShort = PyObject_GetAttrString(temp, "BufferTooShort");
- Py_XDECREF(temp);
-
#if defined(MS_WINDOWS) || \
(defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
- /* Add SemLock type to module */
- if (PyType_Ready(&SemLockType) < 0)
+ /* Add _PyMp_SemLock type to module */
+ if (PyType_Ready(&_PyMp_SemLockType) < 0)
return NULL;
- Py_INCREF(&SemLockType);
+ Py_INCREF(&_PyMp_SemLockType);
{
PyObject *py_sem_value_max;
/* Some systems define SEM_VALUE_MAX as an unsigned value that
@@ -182,10 +173,10 @@ PyInit__multiprocessing(void)
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
if (py_sem_value_max == NULL)
return NULL;
- PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX",
+ PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
py_sem_value_max);
}
- PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType);
+ PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);
#endif
/* Add configuration macros */
diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h
index e3de9baf1b3..0759a80e44b 100644
--- a/Modules/_multiprocessing/multiprocessing.h
+++ b/Modules/_multiprocessing/multiprocessing.h
@@ -91,15 +91,13 @@
#define MP_SOCKET_ERROR (-1002)
#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
-PyObject *mp_SetError(PyObject *Type, int num);
+PyObject *_PyMp_SetError(PyObject *Type, int num);
/*
* Externs - not all will really exist on all platforms
*/
-extern PyObject *BufferTooShort;
-extern PyTypeObject SemLockType;
-extern PyTypeObject PipeConnectionType;
+extern PyTypeObject _PyMp_SemLockType;
/*
* Miscellaneous
diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c
index 2c2b020e3bd..dcf3b42bc10 100644
--- a/Modules/_multiprocessing/semaphore.c
+++ b/Modules/_multiprocessing/semaphore.c
@@ -43,7 +43,7 @@ _GetSemaphoreValue(HANDLE handle, long *value)
{
long previous;
- switch (WaitForSingleObject(handle, 0)) {
+ switch (WaitForSingleObjectEx(handle, 0, FALSE)) {
case WAIT_OBJECT_0:
if (!ReleaseSemaphore(handle, 1, &previous))
return MP_STANDARD_ERROR;
@@ -99,7 +99,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
}
/* check whether we can acquire without releasing the GIL and blocking */
- if (WaitForSingleObject(self->handle, 0) == WAIT_OBJECT_0) {
+ if (WaitForSingleObjectEx(self->handle, 0, FALSE) == WAIT_OBJECT_0) {
self->last_tid = GetCurrentThreadId();
++self->count;
Py_RETURN_TRUE;
@@ -118,7 +118,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
Py_BEGIN_ALLOW_THREADS
if (sigint_event != NULL)
ResetEvent(sigint_event);
- res = WaitForMultipleObjects(nhandles, handles, FALSE, full_msecs);
+ res = WaitForMultipleObjectsEx(nhandles, handles, FALSE, full_msecs, FALSE);
Py_END_ALLOW_THREADS
/* handle result */
@@ -200,7 +200,7 @@ semlock_release(SemLockObject *self, PyObject *args)
#ifndef HAVE_SEM_TIMEDWAIT
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
-int
+static int
sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
{
int res;
@@ -451,7 +451,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
failure:
if (handle != SEM_FAILED)
SEM_CLOSE(handle);
- mp_SetError(NULL, MP_STANDARD_ERROR);
+ _PyMp_SetError(NULL, MP_STANDARD_ERROR);
return NULL;
}
@@ -498,7 +498,7 @@ semlock_getvalue(SemLockObject *self)
#else
int sval;
if (SEM_GETVALUE(self->handle, &sval) < 0)
- return mp_SetError(NULL, MP_STANDARD_ERROR);
+ return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
/* some posix implementations use negative numbers to indicate
the number of waiting threads */
if (sval < 0)
@@ -514,16 +514,16 @@ semlock_iszero(SemLockObject *self)
if (sem_trywait(self->handle) < 0) {
if (errno == EAGAIN)
Py_RETURN_TRUE;
- return mp_SetError(NULL, MP_STANDARD_ERROR);
+ return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
} else {
if (sem_post(self->handle) < 0)
- return mp_SetError(NULL, MP_STANDARD_ERROR);
+ return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
Py_RETURN_FALSE;
}
#else
int sval;
if (SEM_GETVALUE(self->handle, &sval) < 0)
- return mp_SetError(NULL, MP_STANDARD_ERROR);
+ return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
return PyBool_FromLong((long)sval == 0);
#endif
}
@@ -581,7 +581,7 @@ static PyMemberDef semlock_members[] = {
* Semaphore type
*/
-PyTypeObject SemLockType = {
+PyTypeObject _PyMp_SemLockType = {
PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "_multiprocessing.SemLock",
/* tp_basicsize */ sizeof(SemLockObject),