Content-Length: 458541 | pFad | http://github.com/python/cpython/pull/110246/commits/4d103dd4e5bbad54d3a34b349070248da1b39438

87 gh-76785: Add SendChannel.send_buffer() by ericsnowcurrently · Pull Request #110246 · python/cpython · GitHub
Skip to content

gh-76785: Add SendChannel.send_buffer() #110246

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 20 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 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
Optionally free the pending call's data.
  • Loading branch information
ericsnowcurrently committed Oct 2, 2023
commit 4d103dd4e5bbad54d3a34b349070248da1b39438
6 changes: 5 additions & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
extern void _PyEval_FiniState(struct _ceval_state *ceval);
extern void _PyEval_SignalReceived(PyInterpreterState *interp);

// bitwise flags:
#define _Py_PENDING_MAINTHREADONLY 1
#define _Py_PENDING_RAWFREE 2

// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(int) _PyEval_AddPendingCall(
PyInterpreterState *interp,
_Py_pending_call_func func,
void *arg,
int mainthreadonly);
int flags);

extern void _PyEval_SignalAsyncExc(PyInterpreterState *interp);
#ifdef HAVE_FORK
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_ceval_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct _pending_calls {
struct _pending_call {
_Py_pending_call_func func;
void *arg;
int flags;
} calls[NPENDINGCALLS];
int first;
int last;
Expand Down
4 changes: 2 additions & 2 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ trip_signal(int sig_num)
_PyEval_AddPendingCall(interp,
report_wakeup_send_error,
(void *)(intptr_t) last_error,
1);
_Py_PENDING_MAINTHREADONLY);
}
}
}
Expand All @@ -335,7 +335,7 @@ trip_signal(int sig_num)
_PyEval_AddPendingCall(interp,
report_wakeup_write_error,
(void *)(intptr_t)errno,
1);
_Py_PENDING_MAINTHREADONLY);
}
}
}
Expand Down
31 changes: 19 additions & 12 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ _PyEval_SignalReceived(PyInterpreterState *interp)
/* Push one item onto the queue while holding the lock. */
static int
_push_pending_call(struct _pending_calls *pending,
_Py_pending_call_func func, void *arg)
_Py_pending_call_func func, void *arg, int flags)
{
int i = pending->last;
int j = (i + 1) % NPENDINGCALLS;
Expand All @@ -772,13 +772,14 @@ _push_pending_call(struct _pending_calls *pending,
}
pending->calls[i].func = func;
pending->calls[i].arg = arg;
pending->calls[i].flags = flags;
pending->last = j;
return 0;
}

static int
_next_pending_call(struct _pending_calls *pending,
int (**func)(void *), void **arg)
int (**func)(void *), void **arg, int *flags)
{
int i = pending->first;
if (i == pending->last) {
Expand All @@ -788,15 +789,16 @@ _next_pending_call(struct _pending_calls *pending,
}
*func = pending->calls[i].func;
*arg = pending->calls[i].arg;
*flags = pending->calls[i].flags;
return i;
}

/* Pop one item off the queue while holding the lock. */
static void
_pop_pending_call(struct _pending_calls *pending,
int (**func)(void *), void **arg)
int (**func)(void *), void **arg, int *flags)
{
int i = _next_pending_call(pending, func, arg);
int i = _next_pending_call(pending, func, arg, flags);
if (i >= 0) {
pending->calls[i] = (struct _pending_call){0};
pending->first = (i + 1) % NPENDINGCALLS;
Expand All @@ -810,12 +812,12 @@ _pop_pending_call(struct _pending_calls *pending,

int
_PyEval_AddPendingCall(PyInterpreterState *interp,
_Py_pending_call_func func, void *arg,
int mainthreadonly)
_Py_pending_call_func func, void *arg, int flags)
{
assert(!mainthreadonly || _Py_IsMainInterpreter(interp));
assert(!(flags & _Py_PENDING_MAINTHREADONLY)
|| _Py_IsMainInterpreter(interp));
struct _pending_calls *pending = &interp->ceval.pending;
if (mainthreadonly) {
if (flags & _Py_PENDING_MAINTHREADONLY) {
/* The main thread only exists in the main interpreter. */
assert(_Py_IsMainInterpreter(interp));
pending = &_PyRuntime.ceval.pending_mainthread;
Expand All @@ -825,7 +827,7 @@ _PyEval_AddPendingCall(PyInterpreterState *interp,
assert(pending->lock != NULL);

PyThread_acquire_lock(pending->lock, WAIT_LOCK);
int result = _push_pending_call(pending, func, arg);
int result = _push_pending_call(pending, func, arg, flags);
PyThread_release_lock(pending->lock);

/* signal main loop */
Expand All @@ -839,7 +841,7 @@ Py_AddPendingCall(_Py_pending_call_func func, void *arg)
/* Legacy users of this API will continue to target the main thread
(of the main interpreter). */
PyInterpreterState *interp = _PyInterpreterState_Main();
return _PyEval_AddPendingCall(interp, func, arg, 1);
return _PyEval_AddPendingCall(interp, func, arg, _Py_PENDING_MAINTHREADONLY);
}

static int
Expand Down Expand Up @@ -880,17 +882,22 @@ _make_pending_calls(struct _pending_calls *pending)
for (int i=0; i<NPENDINGCALLS; i++) {
_Py_pending_call_func func = NULL;
void *arg = NULL;
int flags = 0;

/* pop one item off the queue while holding the lock */
PyThread_acquire_lock(pending->lock, WAIT_LOCK);
_pop_pending_call(pending, &func, &arg);
_pop_pending_call(pending, &func, &arg, &flags);
PyThread_release_lock(pending->lock);

/* having released the lock, perform the callback */
if (func == NULL) {
break;
}
if (func(arg) != 0) {
int res = func(arg);
if ((flags & _Py_PENDING_RAWFREE) && arg != NULL) {
PyMem_RawFree(arg);
}
if (res != 0) {
return -1;
}
}
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/110246/commits/4d103dd4e5bbad54d3a34b349070248da1b39438

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy