Skip to content

Commit 65d5b57

Browse files
committed
Thanks to Chris Herborth, the thread primitives now have proper Py*
names in the source code (they already had those for the linker, through some smart macros; but the source still had the old, un-Py names).
1 parent 14f53a7 commit 65d5b57

20 files changed

+507
-548
lines changed

Include/pythread.h

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _THREAD_H_included
22
#define _THREAD_H_included
33

4-
#define NO_EXIT_PROG /* don't define exit_prog() */
4+
#define NO_EXIT_PROG /* don't define PyThread_exit_prog() */
55
/* (the result is no use of signals on SGI) */
66

77
#ifndef Py_PROTO
@@ -12,76 +12,42 @@
1212
#endif
1313
#endif
1414

15-
typedef void *type_lock;
16-
typedef void *type_sema;
15+
typedef void *PyThread_type_lock;
16+
typedef void *PyThread_type_sema;
1717

1818
#ifdef __cplusplus
1919
extern "C" {
2020
#endif
2121

22-
/* Macros defining new names for all these symbols */
23-
/* BeOS note: We have exit_thread(), and no legacy code to
24-
* support, so we won't allow exit_thread and _exit_thread
25-
* in here. Actually, I think these #defines should vanish;
26-
* aren't they cheesy in the face of the Great Renaming? [cjh]
27-
*/
28-
#define init_thread PyThread_init_thread
29-
#define start_new_thread PyThread_start_new_thread
30-
#ifndef __BEOS__
31-
#define exit_thread PyThread_exit_thread
32-
#define _exit_thread PyThread__exit_thread
33-
#endif
34-
#define get_thread_ident PyThread_get_thread_ident
35-
#define allocate_lock PyThread_allocate_lock
36-
#define free_lock PyThread_free_lock
37-
#define acquire_lock PyThread_acquire_lock
38-
#define release_lock PyThread_release_lock
39-
#define allocate_sema PyThread_allocate_sema
40-
#define free_sema PyThread_free_sema
41-
#define down_sema PyThread_down_sema
42-
#define up_sema PyThread_up_sema
43-
#define exit_prog PyThread_exit_prog
44-
#define _exit_prog PyThread__exit_prog
45-
#define create_key PyThread_create_key
46-
#define delete_key PyThread_delete_key
47-
#define get_key_value PyThread_get_key_value
48-
#define set_key_value PyThread_set_key_value
49-
50-
51-
DL_IMPORT(void) init_thread Py_PROTO((void));
52-
DL_IMPORT(int) start_new_thread Py_PROTO((void (*)(void *), void *));
53-
#ifndef __BEOS__
54-
DL_IMPORT(void) exit_thread Py_PROTO((void));
55-
DL_IMPORT(void) _exit_thread Py_PROTO((void));
56-
#else
22+
DL_IMPORT(void) PyThread_init_thread Py_PROTO((void));
23+
DL_IMPORT(int) PyThread_start_new_thread Py_PROTO((void (*)(void *), void *));
5724
DL_IMPORT(void) PyThread_exit_thread Py_PROTO((void));
58-
DL_IMPORT(void) PyThread__exit_thread Py_PROTO((void));
59-
#endif
60-
DL_IMPORT(long) get_thread_ident Py_PROTO((void));
25+
DL_IMPORT(void) PyThread__PyThread_exit_thread Py_PROTO((void));
26+
DL_IMPORT(long) PyThread_get_thread_ident Py_PROTO((void));
6127

62-
DL_IMPORT(type_lock) allocate_lock Py_PROTO((void));
63-
DL_IMPORT(void) free_lock Py_PROTO((type_lock));
64-
DL_IMPORT(int) acquire_lock Py_PROTO((type_lock, int));
28+
DL_IMPORT(PyThread_type_lock) PyThread_allocate_lock Py_PROTO((void));
29+
DL_IMPORT(void) PyThread_free_lock Py_PROTO((PyThread_type_lock));
30+
DL_IMPORT(int) PyThread_acquire_lock Py_PROTO((PyThread_type_lock, int));
6531
#define WAIT_LOCK 1
6632
#define NOWAIT_LOCK 0
67-
DL_IMPORT(void) release_lock Py_PROTO((type_lock));
33+
DL_IMPORT(void) PyThread_release_lock Py_PROTO((PyThread_type_lock));
6834

69-
DL_IMPORT(type_sema) allocate_sema Py_PROTO((int));
70-
DL_IMPORT(void) free_sema Py_PROTO((type_sema));
71-
DL_IMPORT(int) down_sema Py_PROTO((type_sema, int));
35+
DL_IMPORT(PyThread_type_sema) PyThread_allocate_sema Py_PROTO((int));
36+
DL_IMPORT(void) PyThread_free_sema Py_PROTO((PyThread_type_sema));
37+
DL_IMPORT(int) PyThread_down_sema Py_PROTO((PyThread_type_sema, int));
7238
#define WAIT_SEMA 1
7339
#define NOWAIT_SEMA 0
74-
DL_IMPORT(void) up_sema Py_PROTO((type_sema));
40+
DL_IMPORT(void) PyThread_up_sema Py_PROTO((PyThread_type_sema));
7541

7642
#ifndef NO_EXIT_PROG
77-
DL_IMPORT(void) exit_prog Py_PROTO((int));
78-
DL_IMPORT(void) _exit_prog Py_PROTO((int));
43+
DL_IMPORT(void) PyThread_exit_prog Py_PROTO((int));
44+
DL_IMPORT(void) PyThread__PyThread_exit_prog Py_PROTO((int));
7945
#endif
8046

81-
DL_IMPORT(int) create_key Py_PROTO((void));
82-
DL_IMPORT(void) delete_key Py_PROTO((int));
83-
DL_IMPORT(int) set_key_value Py_PROTO((int, void *));
84-
DL_IMPORT(void *) get_key_value Py_PROTO((int));
47+
DL_IMPORT(int) PyThread_create_key Py_PROTO((void));
48+
DL_IMPORT(void) PyThread_delete_key Py_PROTO((int));
49+
DL_IMPORT(int) PyThread_set_key_value Py_PROTO((int, void *));
50+
DL_IMPORT(void *) PyThread_get_key_value Py_PROTO((int));
8551

8652
#ifdef __cplusplus
8753
}

Modules/_tkinter.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,29 @@ PERFORMANCE OF THIS SOFTWARE.
171171
172172
*/
173173

174-
static type_lock tcl_lock = 0;
174+
static PyThread_type_lock tcl_lock = 0;
175175
static PyThreadState *tcl_tstate = NULL;
176176

177177
#define ENTER_TCL \
178178
{ PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \
179-
acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
179+
PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
180180

181181
#define LEAVE_TCL \
182-
tcl_tstate = NULL; release_lock(tcl_lock); Py_END_ALLOW_THREADS}
182+
tcl_tstate = NULL; PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
183183

184184
#define ENTER_OVERLAP \
185185
Py_END_ALLOW_THREADS
186186

187187
#define LEAVE_OVERLAP_TCL \
188-
tcl_tstate = NULL; release_lock(tcl_lock); }
188+
tcl_tstate = NULL; PyThread_release_lock(tcl_lock); }
189189

190190
#define ENTER_PYTHON \
191191
{ PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \
192-
release_lock(tcl_lock); PyEval_RestoreThread((tstate)); }
192+
PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); }
193193

194194
#define LEAVE_PYTHON \
195195
{ PyThreadState *tstate = PyEval_SaveThread(); \
196-
acquire_lock(tcl_lock, 1); tcl_tstate = tstate; }
196+
PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; }
197197

198198
#else
199199

@@ -1679,11 +1679,11 @@ Tkapp_MainLoop(self, args)
16791679

16801680
#ifdef WITH_THREAD
16811681
Py_BEGIN_ALLOW_THREADS
1682-
acquire_lock(tcl_lock, 1);
1682+
PyThread_acquire_lock(tcl_lock, 1);
16831683
tcl_tstate = tstate;
16841684
result = Tcl_DoOneEvent(TCL_DONT_WAIT);
16851685
tcl_tstate = NULL;
1686-
release_lock(tcl_lock);
1686+
PyThread_release_lock(tcl_lock);
16871687
if (result == 0)
16881688
Sleep(20);
16891689
Py_END_ALLOW_THREADS
@@ -1921,13 +1921,13 @@ EventHook()
19211921
#endif
19221922
#if defined(WITH_THREAD) || defined(MS_WINDOWS)
19231923
Py_BEGIN_ALLOW_THREADS
1924-
acquire_lock(tcl_lock, 1);
1924+
PyThread_acquire_lock(tcl_lock, 1);
19251925
tcl_tstate = event_tstate;
19261926

19271927
result = Tcl_DoOneEvent(TCL_DONT_WAIT);
19281928

19291929
tcl_tstate = NULL;
1930-
release_lock(tcl_lock);
1930+
PyThread_release_lock(tcl_lock);
19311931
if (result == 0)
19321932
Sleep(20);
19331933
Py_END_ALLOW_THREADS
@@ -2014,7 +2014,7 @@ init_tkinter()
20142014
Tkapp_Type.ob_type = &PyType_Type;
20152015

20162016
#ifdef WITH_THREAD
2017-
tcl_lock = allocate_lock();
2017+
tcl_lock = PyThread_allocate_lock();
20182018
#endif
20192019

20202020
m = Py_InitModule("_tkinter", moduleMethods);

Modules/bsddbmodule.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct {
5757
DB *di_bsddb;
5858
int di_size; /* -1 means recompute */
5959
#ifdef WITH_THREAD
60-
type_lock di_lock;
60+
PyThread_type_lock di_lock;
6161
#endif
6262
} bsddbobject;
6363

@@ -113,7 +113,7 @@ newdbhashobject(file, flags, mode,
113113

114114
dp->di_size = -1;
115115
#ifdef WITH_THREAD
116-
dp->di_lock = allocate_lock();
116+
dp->di_lock = PyThread_allocate_lock();
117117
if (dp->di_lock == NULL) {
118118
PyErr_SetString(BsddbError, "can't allocate lock");
119119
Py_DECREF(dp);
@@ -169,7 +169,7 @@ newdbbtobject(file, flags, mode,
169169

170170
dp->di_size = -1;
171171
#ifdef WITH_THREAD
172-
dp->di_lock = allocate_lock();
172+
dp->di_lock = PyThread_allocate_lock();
173173
if (dp->di_lock == NULL) {
174174
PyErr_SetString(BsddbError, "can't allocate lock");
175175
Py_DECREF(dp);
@@ -225,7 +225,7 @@ newdbrnobject(file, flags, mode,
225225

226226
dp->di_size = -1;
227227
#ifdef WITH_THREAD
228-
dp->di_lock = allocate_lock();
228+
dp->di_lock = PyThread_allocate_lock();
229229
if (dp->di_lock == NULL) {
230230
PyErr_SetString(BsddbError, "can't allocate lock");
231231
Py_DECREF(dp);
@@ -242,9 +242,9 @@ bsddb_dealloc(dp)
242242
{
243243
#ifdef WITH_THREAD
244244
if (dp->di_lock) {
245-
acquire_lock(dp->di_lock, 0);
246-
release_lock(dp->di_lock);
247-
free_lock(dp->di_lock);
245+
PyThread_acquire_lock(dp->di_lock, 0);
246+
PyThread_release_lock(dp->di_lock);
247+
PyThread_free_lock(dp->di_lock);
248248
dp->di_lock = NULL;
249249
}
250250
#endif
@@ -262,8 +262,8 @@ bsddb_dealloc(dp)
262262
}
263263

264264
#ifdef WITH_THREAD
265-
#define BSDDB_BGN_SAVE(_dp) Py_BEGIN_ALLOW_THREADS acquire_lock(_dp->di_lock,1);
266-
#define BSDDB_END_SAVE(_dp) release_lock(_dp->di_lock); Py_END_ALLOW_THREADS
265+
#define BSDDB_BGN_SAVE(_dp) Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(_dp->di_lock,1);
266+
#define BSDDB_END_SAVE(_dp) PyThread_release_lock(_dp->di_lock); Py_END_ALLOW_THREADS
267267
#else
268268
#define BSDDB_BGN_SAVE(_dp) Py_BEGIN_ALLOW_THREADS
269269
#define BSDDB_END_SAVE(_dp) Py_END_ALLOW_THREADS

Modules/signalmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ signal_signal(self, args)
221221
if (!PyArg_Parse(args, "(iO)", &sig_num, &obj))
222222
return NULL;
223223
#ifdef WITH_THREAD
224-
if (get_thread_ident() != main_thread) {
224+
if (PyThread_get_thread_ident() != main_thread) {
225225
PyErr_SetString(PyExc_ValueError,
226226
"signal only works in main thread");
227227
return NULL;
@@ -346,7 +346,7 @@ initsignal()
346346
int i;
347347

348348
#ifdef WITH_THREAD
349-
main_thread = get_thread_ident();
349+
main_thread = PyThread_get_thread_ident();
350350
main_pid = getpid();
351351
#endif
352352

@@ -619,7 +619,7 @@ PyErr_CheckSignals()
619619
if (!is_tripped)
620620
return 0;
621621
#ifdef WITH_THREAD
622-
if (get_thread_ident() != main_thread)
622+
if (PyThread_get_thread_ident() != main_thread)
623623
return 0;
624624
#endif
625625
if (!(f = PyEval_GetFrame()))
@@ -676,7 +676,7 @@ PyOS_InterruptOccurred()
676676
{
677677
if (Handlers[SIGINT].tripped) {
678678
#ifdef WITH_THREAD
679-
if (get_thread_ident() != main_thread)
679+
if (PyThread_get_thread_ident() != main_thread)
680680
return 0;
681681
#endif
682682
Handlers[SIGINT].tripped = 0;
@@ -689,7 +689,7 @@ void
689689
PyOS_AfterFork()
690690
{
691691
#ifdef WITH_THREAD
692-
main_thread = get_thread_ident();
692+
main_thread = PyThread_get_thread_ident();
693693
main_pid = getpid();
694694
#endif
695695
}

Modules/socketmodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ BUILD_FUNC_DEF_4(PySocketSock_New,int,fd, int,family, int,type, int,proto)
313313
/* Lock to allow python interpreter to continue, but only allow one
314314
thread to be in gethostbyname */
315315
#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
316-
type_lock gethostbyname_lock;
316+
PyThread_type_lock gethostbyname_lock;
317317
#endif
318318

319319

@@ -358,11 +358,11 @@ BUILD_FUNC_DEF_2(setipaddr, char*,name, struct sockaddr_in *,addr_ret)
358358
hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
359359
#else /* not HAVE_GETHOSTBYNAME_R */
360360
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
361-
acquire_lock(gethostbyname_lock,1);
361+
PyThread_acquire_lock(gethostbyname_lock,1);
362362
#endif
363363
hp = gethostbyname(name);
364364
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
365-
release_lock(gethostbyname_lock);
365+
PyThread_release_lock(gethostbyname_lock);
366366
#endif
367367
#endif /* HAVE_GETHOSTBYNAME_R */
368368
Py_END_ALLOW_THREADS
@@ -1417,11 +1417,11 @@ BUILD_FUNC_DEF_2(PySocket_gethostbyname_ex,PyObject *,self, PyObject *,args)
14171417
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
14181418
#else /* not HAVE_GETHOSTBYNAME_R */
14191419
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
1420-
acquire_lock(gethostbyname_lock,1);
1420+
PyThread_acquire_lock(gethostbyname_lock,1);
14211421
#endif
14221422
h = gethostbyname(name);
14231423
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
1424-
release_lock(gethostbyname_lock);
1424+
PyThread_release_lock(gethostbyname_lock);
14251425
#endif
14261426
#endif /* HAVE_GETHOSTBYNAME_R */
14271427
Py_END_ALLOW_THREADS
@@ -1463,13 +1463,13 @@ BUILD_FUNC_DEF_2(PySocket_gethostbyaddr,PyObject *,self, PyObject *, args)
14631463
&hp_allocated, buf, buf_len, &errnop);
14641464
#else /* not HAVE_GETHOSTBYNAME_R */
14651465
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
1466-
acquire_lock(gethostbyname_lock,1);
1466+
PyThread_acquire_lock(gethostbyname_lock,1);
14671467
#endif
14681468
h = gethostbyaddr((char *)&addr.sin_addr,
14691469
sizeof(addr.sin_addr),
14701470
AF_INET);
14711471
#if defined(WITH_THREAD) && !defined(MS_WINDOWS)
1472-
release_lock(gethostbyname_lock);
1472+
PyThread_release_lock(gethostbyname_lock);
14731473
#endif
14741474
#endif /* HAVE_GETHOSTBYNAME_R */
14751475
Py_END_ALLOW_THREADS
@@ -2188,6 +2188,6 @@ initsocket()
21882188

21892189
/* Initialize gethostbyname lock */
21902190
#if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS)
2191-
gethostbyname_lock = allocate_lock();
2191+
gethostbyname_lock = PyThread_allocate_lock();
21922192
#endif
21932193
}

Modules/stdwinmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ PERFORMANCE OF THIS SOFTWARE.
8787

8888
#include "pythread.h"
8989

90-
static type_lock StdwinLock; /* Lock held when interpreter not locked */
90+
static PyThread_type_lock StdwinLock; /* Lock held when interpreter not locked */
9191

92-
#define BGN_STDWIN Py_BEGIN_ALLOW_THREADS acquire_lock(StdwinLock, 1);
93-
#define RET_STDWIN release_lock(StdwinLock); Py_BLOCK_THREADS
94-
#define END_STDWIN release_lock(StdwinLock); Py_END_ALLOW_THREADS
92+
#define BGN_STDWIN Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(StdwinLock, 1);
93+
#define RET_STDWIN PyThread_release_lock(StdwinLock); Py_BLOCK_THREADS
94+
#define END_STDWIN PyThread_release_lock(StdwinLock); Py_END_ALLOW_THREADS
9595

9696
#else
9797

@@ -2659,6 +2659,6 @@ initstdwin()
26592659
PyDict_SetItemString(d, "error", StdwinError) != 0)
26602660
return;
26612661
#ifdef WITH_THREAD
2662-
StdwinLock = allocate_lock();
2662+
StdwinLock = PyThread_allocate_lock();
26632663
#endif
26642664
}

0 commit comments

Comments
 (0)