Skip to content

Use a common interface for FT-only mutexes #137514

@ZeroIntensity

Description

@ZeroIntensity

Throughout the codebase, there are two common patterns for using a mutex only on the free-threaded build:

#ifdef Py_GIL_DISABLED
PyMutex_Lock(/* ... */);
#endif

/* ... */

#ifdef Py_GIL_DISABLED
PyMutex_Unlock(/* ... */);
#endif
#ifdef Py_GIL_DISABLED
#define LOCK() PyMutex_Lock(/* ... */)
#define UNLOCK() PyMutex_Unlock(/* ... */)
#else
#define LOCK()
#define UNLOCK()
#endif

static void
something()
{
    LOCK();
    /* ... */
    UNLOCK();
}

I think we can eliminate some redundancy by adding a common wrapper similar to the latter, but takes a mutex argument rather than being hardcoded into the macro.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions