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

Skip to content

[WIP] bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). #9334

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
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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 Sep 15, 2018
commit 93f27066be7a3b1a82994739084f0a62d78e0cde
29 changes: 3 additions & 26 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,38 +1266,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 @@ -1319,7 +1296,7 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
}

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

PyObject *
Expand Down
0