Skip to content

Commit

Permalink
bpo-33608: Revert "Factor out a private, per-interpreter _Py_AddPendi…
Browse files Browse the repository at this point in the history
…ngCall()." (pythongh-12806)

This reverts commit f13c5c8 (pythongh-12360).
  • Loading branch information
ericsnowcurrently authored Apr 12, 2019
1 parent f938d8b commit b75b1a3
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 151 deletions.
2 changes: 1 addition & 1 deletion Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *);
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *);
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
#endif

/* Masks and values used by FORMAT_VALUE opcode. */
Expand Down
18 changes: 5 additions & 13 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ extern "C" {
#include "pycore_atomic.h"
#include "pythread.h"

struct _is; // See PyInterpreterState in cpython/pystate.h.

PyAPI_FUNC(int) _Py_AddPendingCall(struct _is*, unsigned long, int (*)(void *), void *);
PyAPI_FUNC(int) _Py_MakePendingCalls(struct _is*);
PyAPI_FUNC(void) _Py_FinishPendingCalls(struct _is*);
PyAPI_FUNC(void) _Py_FinishPendingCalls(void);

struct _pending_calls {
int finishing;
Expand All @@ -28,21 +24,13 @@ struct _pending_calls {
int async_exc;
#define NPENDINGCALLS 32
struct {
unsigned long thread_id;
int (*func)(void *);
void *arg;
} calls[NPENDINGCALLS];
int first;
int last;
};

struct _ceval_interpreter_state {
/* This single variable consolidates all requests to break out of
the fast path in the eval loop. */
_Py_atomic_int eval_breaker;
struct _pending_calls pending;
};

#include "pycore_gil.h"

struct _ceval_runtime_state {
Expand All @@ -53,8 +41,12 @@ struct _ceval_runtime_state {
c_tracefunc. This speeds up the if statement in
PyEval_EvalFrameEx() after fast_next_opcode. */
int tracing_possible;
/* This single variable consolidates all requests to break out of
the fast path in the eval loop. */
_Py_atomic_int eval_breaker;
/* Request for dropping the GIL */
_Py_atomic_int gil_drop_request;
struct _pending_calls pending;
/* Request for checking signals. */
_Py_atomic_int signals_pending;
struct _gil_runtime_state gil;
Expand Down
3 changes: 0 additions & 3 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern "C" {
#include "pystate.h"
#include "pythread.h"

#include "pycore_atomic.h"
#include "pycore_ceval.h"
#include "pycore_pathconfig.h"
#include "pycore_pymem.h"
Expand Down Expand Up @@ -84,8 +83,6 @@ struct _is {
PyObject *pyexitmodule;

uint64_t tstate_next_unique_id;

struct _ceval_interpreter_state ceval;
};

PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T);
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def pendingcalls_wait(self, l, n, context = None):
def test_pendingcalls_threaded(self):

#do every callback on a separate thread
n = 32 #total callbacks (see NPENDINGCALLS in pycore_ceval.h)
n = 32 #total callbacks
threads = []
class foo(object):pass
context = foo()
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,6 @@ pending_threadfunc(PyObject *self, PyObject *arg)
Py_INCREF(callable);

Py_BEGIN_ALLOW_THREADS
/* XXX Use the internal _Py_AddPendingCall(). */
r = Py_AddPendingCall(&_pending_callback, callable);
Py_END_ALLOW_THREADS

Expand Down
13 changes: 4 additions & 9 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <process.h>
#endif
#endif
#include "internal/pycore_pystate.h"

#ifdef HAVE_SIGNAL_H
#include <signal.h>
Expand Down Expand Up @@ -296,10 +295,8 @@ trip_signal(int sig_num)
{
/* Py_AddPendingCall() isn't signal-safe, but we
still use it for this exceptional case. */
_Py_AddPendingCall(_PyRuntime.interpreters.main,
main_thread,
report_wakeup_send_error,
(void *)(intptr_t) last_error);
Py_AddPendingCall(report_wakeup_send_error,
(void *)(intptr_t) last_error);
}
}
}
Expand All @@ -316,10 +313,8 @@ trip_signal(int sig_num)
{
/* Py_AddPendingCall() isn't signal-safe, but we
still use it for this exceptional case. */
_Py_AddPendingCall(_PyRuntime.interpreters.main,
main_thread,
report_wakeup_write_error,
(void *)(intptr_t)errno);
Py_AddPendingCall(report_wakeup_write_error,
(void *)(intptr_t)errno);
}
}
}
Expand Down
Loading

0 comments on commit b75b1a3

Please sign in to comment.