An interpreted, interactive, object-oriented programming language
CentOS Sources
2017-08-01 71084d584ff953f5463757ec6536406320560b4d
commit | author | age
71084d 1 diff --git a/Include/pythread.h b/Include/pythread.h
CS 2 index dfd6157..f3e6259 100644
3 --- a/Include/pythread.h
4 +++ b/Include/pythread.h
5 @@ -30,6 +30,8 @@ PyAPI_FUNC(void) PyThread_delete_key(int);
6  PyAPI_FUNC(int) PyThread_set_key_value(int, void *);
7  PyAPI_FUNC(void *) PyThread_get_key_value(int);
8  PyAPI_FUNC(void) PyThread_delete_key_value(int key);
9 +PyAPI_FUNC(int) _PyThread_AcquireKeyLock(void);
10 +PyAPI_FUNC(void) _PyThread_ReleaseKeyLock(void);
11  
12  /* Cleanup after a fork */
13  PyAPI_FUNC(void) PyThread_ReInitTLS(void);
14 diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
15 index 022d7aa..8f6cbb2 100644
16 --- a/Modules/posixmodule.c
17 +++ b/Modules/posixmodule.c
18 @@ -65,6 +65,10 @@ corresponding Unix manual entries for more information on calls.");
19  #include "osdefs.h"
20  #endif
21
22 +#ifdef WITH_THREAD
23 +#include "pythread.h"
24 +#endif
25 +
26  #ifdef HAVE_SYS_TYPES_H
27  #include <sys/types.h>
28  #endif /* HAVE_SYS_TYPES_H */
29 @@ -3796,7 +3800,18 @@ posix_fork1(PyObject *self, PyObject *noargs)
30      pid_t pid;
31      int result = 0;
32      _PyImport_AcquireLock();
33 +#ifdef WITH_THREAD
34 +    if (_PyThread_AcquireKeyLock() == 0) {
35 +        _PyImport_ReleaseLock();
36 +        PyErr_SetString(PyExc_RuntimeError,
37 +                        "could not acquire thread key lock");
38 +        return NULL;
39 +    }
40 +#endif
41      pid = fork1();
42 +#ifdef WITH_THREAD
43 +    _PyThread_ReleaseKeyLock();
44 +#endif
45      if (pid == 0) {
46          /* child: this clobbers and resets the import lock. */
47          PyOS_AfterFork();
48 @@ -3829,7 +3844,18 @@ posix_fork(PyObject *self, PyObject *noargs)
49      pid_t pid;
50      int result = 0;
51      _PyImport_AcquireLock();
52 +#ifdef WITH_THREAD
53 +    if (_PyThread_AcquireKeyLock() == 0) {
54 +        _PyImport_ReleaseLock();
55 +        PyErr_SetString(PyExc_RuntimeError,
56 +                        "could not acquire thread key lock");
57 +        return NULL;
58 +    }
59 +#endif
60      pid = fork();
61 +#ifdef WITH_THREAD
62 +    _PyThread_ReleaseKeyLock();
63 +#endif
64      if (pid == 0) {
65          /* child: this clobbers and resets the import lock. */
66          PyOS_AfterFork();
67 @@ -3955,7 +3981,18 @@ posix_forkpty(PyObject *self, PyObject *noargs)
68      pid_t pid;
69  
70      _PyImport_AcquireLock();
71 +#ifdef WITH_THREAD
72 +    if (_PyThread_AcquireKeyLock() == 0) {
73 +        _PyImport_ReleaseLock();
74 +        PyErr_SetString(PyExc_RuntimeError,
75 +                        "could not acquire thread key lock");
76 +        return NULL;
77 +    }
78 +#endif
79      pid = forkpty(&master_fd, NULL, NULL, NULL);
80 +#ifdef WITH_THREAD
81 +    _PyThread_ReleaseKeyLock();
82 +#endif
83      if (pid == 0) {
84          /* child: this clobbers and resets the import lock. */
85          PyOS_AfterFork();
86 diff --git a/Python/thread.c b/Python/thread.c
87 index dd333e8..957739e 100644
88 --- a/Python/thread.c
89 +++ b/Python/thread.c
90 @@ -387,6 +387,24 @@ PyThread_delete_key_value(int key)
91      PyThread_release_lock(keymutex);
92  }
93  
94 +int
95 +_PyThread_AcquireKeyLock(void)
96 +{
97 +    if (keymutex == NULL) {
98 +        keymutex = PyThread_allocate_lock();
99 +    }
100 +    if (keymutex == NULL) {
101 +        return 0;
102 +    }
103 +    return PyThread_acquire_lock(keymutex, 1);
104 +}
105 +
106 +void
107 +_PyThread_ReleaseKeyLock(void)
108 +{
109 +    PyThread_release_lock(keymutex);
110 +}
111 +
112  /* Forget everything not associated with the current thread id.
113   * This function is called from PyOS_AfterFork().  It is necessary
114   * because other thread ids which were in use at the time of the fork