Skip to content

[2.7] bpo-33257: Fix race conditions for non-threaded Tcl (GH-6444) #6972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cosmetic changes for readability
  • Loading branch information
native-api committed May 18, 2018
commit a15b10c289f9bbef4d90c7d24e6abdd49907ca6d
13 changes: 8 additions & 5 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ Copyright (C) 1994 Steen Lumholt.

Sometimes, it is necessary to have both the Python lock and the Tcl lock.
(For example, when transferring data between the Tcl interpreter and/or
objects and Python objects.) To avoid deadlocks, when acquiring, we always
acquire the Tcl lock first, then the Python lock. The additional macros for
objects and Python objects.) To avoid deadlocks, when acquiring, we always
acquire the Tcl lock first, then the Python lock. The additional macros for
finer lock control are: ENTER_OVERLAP acquires the Python lock (and restores
the thread state) when already holding the Tcl lock; LEAVE_OVERLAP releases
the Python lock and keeps the Tcl lock; and LEAVE_OVERLAP_TCL releases the
Expand Down Expand Up @@ -204,6 +204,7 @@ static PyThread_type_lock tcl_lock = 0;
static unsigned long tcl_lock_thread_ident = 0;
static unsigned int tcl_lock_reentry_count = 0;


#ifdef TCL_THREADS
static Tcl_ThreadDataKey state_key;
typedef PyThreadState *ThreadSpecificData;
Expand All @@ -212,9 +213,10 @@ typedef PyThreadState *ThreadSpecificData;
static PyThreadState *tcl_tstate = NULL;
#endif


#define ACQUIRE_TCL_LOCK \
if (tcl_lock) {\
if (tcl_lock_thread_ident == PyThread_get_thread_ident()) {\
if (tcl_lock_thread_ident == PyThread_get_thread_ident()) { \
tcl_lock_reentry_count++; \
if(!tcl_lock_reentry_count) \
Py_FatalError("Tcl lock reentry count overflow"); \
Expand All @@ -234,12 +236,13 @@ if (tcl_lock){\
}\
}


#define ENTER_TCL \
{ PyThreadState *tstate = PyThreadState_Get();\
{ PyThreadState *tstate = PyThreadState_Get(); \
ENTER_TCL_CUSTOM_TSTATE(tstate)

#define ENTER_TCL_CUSTOM_TSTATE(tstate) \
Py_BEGIN_ALLOW_THREADS\
Py_BEGIN_ALLOW_THREADS \
ACQUIRE_TCL_LOCK; tcl_tstate = tstate;

#define LEAVE_TCL \
Expand Down