8000 bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). by ericsnowcurrently · Pull Request #12360 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). #12360

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

Merged
Merged
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
Use _Py_AddPendingCall() for releasing shared data.
  • Loading branch information
ericsnowcurrently committed Apr 5, 2019
commit 40ab9ab02d6f98322f514aecbe57820a53d57d36
30 changes: 3 additions & 27 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,38 +1353,15 @@ _PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
return 0;
}

static void
static int
_release_xidata(void *arg)
{
_PyCrossInterpreterData *data = (_PyCrossInterpreterData *)arg;
if (data->free != NULL) {
data->free(data->data);
}
Py_XDECREF(data->obj);
}

static void
_call_in_interpreter(PyInterpreterState *interp,
void (*func)(void *), void *arg)
{
/* We would use Py_AddPendingCall() if it weren't specific to the
* main interpreter (see bpo-33608). In the meantime we take a
* naive approach.
*/
PyThreadState *save_tstate = NULL;
if (interp != _PyInterpreterState_Get()) {
// XXX Using the "head" thread isn't strictly correct.
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
}

func(arg);

// Switch back.
if (save_tstate != NULL) {
PyThreadState_Swap(save_tstate);
}
return 0;
}

void
Expand All @@ -1406,8 +1383,7 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
}

// "Release" the data and/or the object.
// XXX Use _Py_AddPendingCall().
_call_in_interpreter(interp, _release_xidata, data);
_Py_AddPendingCall(interp, 0, _release_xidata, data);
}

PyObject *
Expand Down
0