Skip to content
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

gh-117511: Make PyMutex public in the non-limited API #117731

Merged
merged 14 commits into from
Jun 20, 2024
Prev Previous commit
Next Next commit
Replace struct _PyMutex with PyMutex
  • Loading branch information
colesbury committed Apr 10, 2024
commit 1cef880f6229672ec7302b194eeb6e3822f0bea0
2 changes: 1 addition & 1 deletion Include/cpython/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// PyMutex_Lock(&m);
// ...
// PyMutex_Unlock(&m);
typedef struct _PyMutex {
typedef struct PyMutex {
uint8_t v;
} PyMutex;

Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/weakrefobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct _PyWeakReference {
* Normally this can be derived from wr_object, but in some cases we need
* to lock after wr_object has been set to Py_None.
*/
struct _PyMutex *weakrefs_lock;
PyMutex *weakrefs_lock;
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct _warnings_runtime_state {
PyObject *filters; /* List */
PyObject *once_registry; /* Dict */
PyObject *default_action; /* String */
struct _PyMutex mutex;
PyMutex mutex;
long filters_version;
};

Expand Down
2 changes: 1 addition & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct _object {
// computed "gc_refs" refcount.
uintptr_t ob_tid;
uint16_t _padding;
struct _PyMutex ob_mutex; // per-object lock
PyMutex ob_mutex; // per-object lock
uint8_t ob_gc_bits; // gc-related state
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
Expand Down
2 changes: 1 addition & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ new_reference(PyObject *op)
#else
op->ob_tid = _Py_ThreadId();
op->_padding = 0;
op->ob_mutex = (struct _PyMutex){ 0 };
op->ob_mutex = (PyMutex){ 0 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no public PyMutex_STATIC_INIT, can you maybe add a private one in pycore_lock.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consider that in a separate PR:

  • It's not directly related to making the API public
  • It would make sense to consider that for multiple types (e.g., PyEvent, _PyOnceFlag), not just PyMutex

op->ob_gc_bits = 0;
op->ob_ref_local = 1;
op->ob_ref_shared = 0;
Expand Down
Loading