Skip to content

Commit 3b35dfd

Browse files
committed
Reduce verbosity of comments.
1 parent 84d1261 commit 3b35dfd

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

Python/context.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,6 @@ contextvar_set(PyContextVar *var, PyObject *val);
6666
static int
6767
contextvar_del(PyContextVar *var);
6868

69-
70-
/* The HAMT held by a context is immutable, but the pointer to it is not:
71-
contextvar_set() and contextvar_del() install a new HAMT and drop the
72-
reference to the previous one. Only the thread that entered a context can
73-
do that (a context cannot be entered by two threads at once), but any
74-
thread can read a context object at any time -- ctx.copy(), len(ctx),
75-
ctx.items(), etc. Such a reader has to acquire its own reference to the
76-
HAMT under the context's lock; reading ctx_vars unlocked lets the writer
77-
deallocate the HAMT while the reader is walking it.
78-
79-
With that discipline -- ctx_vars written only by the owning thread, and
80-
read by other threads only under the context's lock -- there is no
81-
unsynchronized concurrent access, so plain (non-atomic) loads and stores
82-
are used. */
83-
8469
static inline PyHamtObject *
8570
context_get_vars(PyContext *ctx)
8671
{
@@ -93,20 +78,18 @@ context_get_vars(PyContext *ctx)
9378
return vars;
9479
}
9580

96-
/* Same, but for the context that is current on this thread. No other thread
97-
can have it as its current context, so this thread is the only one that can
98-
replace its HAMT: neither the lock nor a new reference is needed here.
99-
Returns a borrowed reference. */
10081
static inline PyHamtObject *
10182
context_get_current_vars(PyContext *ctx)
10283
{
84+
// ctx_vars written only by the owning thread, and read by other threads
85+
// only under the context's lock, a plain (non-atomic) load is okay
10386
PyHamtObject *vars = ctx->ctx_vars;
10487
assert(vars != NULL);
10588
return vars;
10689
}
10790

108-
/* Install a new HAMT in a context. Steals a reference to new_vars. Must
109-
only be called by the thread that has `ctx` as its current context. */
91+
// Note: steals a reference to new_vars and must only be called by the thread
92+
// that has `ctx` as its current context.
11093
static inline void
11194
context_set_vars(PyContext *ctx, PyHamtObject *new_vars)
11295
{
@@ -666,7 +649,6 @@ context_tp_subscript(PyObject *op, PyObject *key)
666649
PyContext *self = _PyContext_CAST(op);
667650
PyHamtObject *vars = context_get_vars(self);
668651
int found = _PyHamt_Find(vars, key, &val);
669-
/* `val` is borrowed from `vars`, take a reference before dropping it. */
670652
Py_XINCREF(val);
671653
Py_DECREF(vars);
672654
if (found < 0) {
@@ -719,7 +701,6 @@ _contextvars_Context_get_impl(PyContext *self, PyObject *key,
719701
PyObject *val = NULL;
720702
PyHamtObject *vars = context_get_vars(self);
721703
int found = _PyHamt_Find(vars, key, &val);
722-
/* `val` is borrowed from `vars`, take a reference before dropping it. */
723704
Py_XINCREF(val);
724705
Py_DECREF(vars);
725706
if (found < 0) {

0 commit comments

Comments
 (0)