Commit 375e3022 authored by Fred Drake's avatar Fred Drake

Update to use the new \csimplemacro macro

parent 79bf99c5
...@@ -391,12 +391,13 @@ Py_BEGIN_ALLOW_THREADS ...@@ -391,12 +391,13 @@ Py_BEGIN_ALLOW_THREADS
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
\end{verbatim} \end{verbatim}
The \code{Py_BEGIN_ALLOW_THREADS}\ttindex{Py_BEGIN_ALLOW_THREADS} macro The
opens a new block and declares a hidden local variable; the \csimplemacro{Py_BEGIN_ALLOW_THREADS}\ttindex{Py_BEGIN_ALLOW_THREADS}
\code{Py_END_ALLOW_THREADS}\ttindex{Py_END_ALLOW_THREADS} macro closes macro opens a new block and declares a hidden local variable; the
the block. Another advantage of using these two macros is that when \csimplemacro{Py_END_ALLOW_THREADS}\ttindex{Py_END_ALLOW_THREADS}
Python is compiled without thread support, they are defined empty, macro closes the block. Another advantage of using these two macros
thus saving the thread state and lock manipulations. is that when Python is compiled without thread support, they are
defined empty, thus saving the thread state and lock manipulations.
When thread support is enabled, the block above expands to the When thread support is enabled, the block above expands to the
following code: following code:
...@@ -574,30 +575,31 @@ look for example usage in the Python source distribution. ...@@ -574,30 +575,31 @@ look for example usage in the Python source distribution.
This macro expands to This macro expands to
\samp{\{ PyThreadState *_save; _save = PyEval_SaveThread();}. \samp{\{ PyThreadState *_save; _save = PyEval_SaveThread();}.
Note that it contains an opening brace; it must be matched with a Note that it contains an opening brace; it must be matched with a
following \code{Py_END_ALLOW_THREADS} macro. See above for further following \csimplemacro{Py_END_ALLOW_THREADS} macro. See above for
discussion of this macro. It is a no-op when thread support is further discussion of this macro. It is a no-op when thread support
disabled at compile time. is disabled at compile time.
\end{csimplemacrodesc} \end{csimplemacrodesc}
\begin{csimplemacrodesc}{Py_END_ALLOW_THREADS} \begin{csimplemacrodesc}{Py_END_ALLOW_THREADS}
This macro expands to \samp{PyEval_RestoreThread(_save); \}}. This macro expands to \samp{PyEval_RestoreThread(_save); \}}.
Note that it contains a closing brace; it must be matched with an Note that it contains a closing brace; it must be matched with an
earlier \code{Py_BEGIN_ALLOW_THREADS} macro. See above for further earlier \csimplemacro{Py_BEGIN_ALLOW_THREADS} macro. See above for
discussion of this macro. It is a no-op when thread support is further discussion of this macro. It is a no-op when thread support
disabled at compile time. is disabled at compile time.
\end{csimplemacrodesc} \end{csimplemacrodesc}
\begin{csimplemacrodesc}{Py_BLOCK_THREADS} \begin{csimplemacrodesc}{Py_BLOCK_THREADS}
This macro expands to \samp{PyEval_RestoreThread(_save);}: it is This macro expands to \samp{PyEval_RestoreThread(_save);}: it is
equivalent to \code{Py_END_ALLOW_THREADS} without the closing brace. equivalent to \csimplemacro{Py_END_ALLOW_THREADS} without the
It is a no-op when thread support is disabled at compile time. closing brace. It is a no-op when thread support is disabled at
compile time.
\end{csimplemacrodesc} \end{csimplemacrodesc}
\begin{csimplemacrodesc}{Py_UNBLOCK_THREADS} \begin{csimplemacrodesc}{Py_UNBLOCK_THREADS}
This macro expands to \samp{_save = PyEval_SaveThread();}: it is This macro expands to \samp{_save = PyEval_SaveThread();}: it is
equivalent to \code{Py_BEGIN_ALLOW_THREADS} without the opening equivalent to \csimplemacro{Py_BEGIN_ALLOW_THREADS} without the
brace and variable declaration. It is a no-op when thread support opening brace and variable declaration. It is a no-op when thread
is disabled at compile time. support is disabled at compile time.
\end{csimplemacrodesc} \end{csimplemacrodesc}
All of the following functions are only available when thread support All of the following functions are only available when thread support
......
...@@ -1068,11 +1068,11 @@ involving threads. Normally, multiple threads in the Python ...@@ -1068,11 +1068,11 @@ involving threads. Normally, multiple threads in the Python
interpreter can't get in each other's way, because there is a global interpreter can't get in each other's way, because there is a global
lock protecting Python's entire object space. However, it is possible lock protecting Python's entire object space. However, it is possible
to temporarily release this lock using the macro to temporarily release this lock using the macro
\code{Py_BEGIN_ALLOW_THREADS}, and to re-acquire it using \csimplemacro{Py_BEGIN_ALLOW_THREADS}, and to re-acquire it using
\code{Py_END_ALLOW_THREADS}. This is common around blocking I/O \csimplemacro{Py_END_ALLOW_THREADS}. This is common around blocking
calls, to let other threads use the processor while waiting for the I/O to I/O calls, to let other threads use the processor while waiting for
complete. Obviously, the following function has the same problem as the I/O to complete. Obviously, the following function has the same
the previous one: problem as the previous one:
\begin{verbatim} \begin{verbatim}
bug(PyObject *list) { bug(PyObject *list) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment