macdice · GitHub

Commits on Aug 21, 2026

  1. ecpg: Fix auto_mem cleanup on thread exit.

    The pthread key destructor registered to free memory allocated with
    ecpg_auto_alloc() on thread exit had two problems:
    1.  It didn't do anything, because the OS clears the thread-specific
    slot (ie the value that get_auto_allocs() will return) before calling
    the destructor.  We need to use the value that is passed to the
    destructor as an argument.
    2.  It was using ECPGfree_auto_mem(), but that would free the actual
    allocated values, and not just the list structure.  The values are
    supposed to be freed by user code (for example the free(r) call in
    src/interfaces/ecpg/test/thread/alloc.pgc).  We need to use
    ecpg_clear_auto_mem() instead, or valid .pgc code will double-free the
    most recently auto-allocated objects on thread exit.
    The destructor still doesn't run at all on Windows, but a proposed patch
    will address that problem.
    Discussion: https://postgr.es/m/CA%2BhUKGLv202ndx%3DkP1fZJapNcbfnpq-rezHNyt%2BcQ4pdxr1akg%40mail.gmail.com
    Backpatch-through: 14
    Reviewed-by: Thom Brown <thom@linux.com>

    authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  2. port: Provide pg_threads.h API.

    This is based on C11 <threads.h>, which is not available on all systems
    we support and a little light on features, but still provides a
    standards-based way to nail down a lot of gnarly details and avoid
    having to invent our own strange names for things.  Our API has pg_
    prefixes on all identifiers, since client code might be using
    <threads.h> directly.
    The thread_local macro is an exception and doesn't get a prefix, since
    there is no doubt about its definition.
    Two implementations are provided to redirect the API to underlying
    threading APIs:
     * <pthread.h>, a thin wrapper for POSIX and MinGW systems
     * <threads.h>, a thin wrapper for Visual Studio's C11 threads
    A native Windows version using traditional Windows APIs is also
    possible.
    Some local extensions are also provided in pg_threads_ext.h:
     * pg_rwlock_t
     * pg_thrd_barrier_t
     * pg_thrd_error_string()
     * pg_thrd_error_string_with_detail()
     * PG_CND_INIT
     * PG_MTX_PLAIN_INIT
    Later commits will make use of this API as a centralized replacement for
    several module-local thread API abstractions.
    Discussion: https://postgr.es/m/CA%2BhUKG%2BK%2BLmYtz54%2BSv1j5Zu1Qo6szzAMbMyuKSeQmb7De4Ewg%40mail.gmail.com
    Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
    Reviewed-by: Bryan Green <dbryan.green@gmail.com>

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  3. Configuration menu

    Browse the repository at this point in the history

  4. Configuration menu

    Browse the repository at this point in the history

  5. Configuration menu

    Browse the repository at this point in the history

  6. Configuration menu

    Browse the repository at this point in the history

  7. Configuration menu

    Browse the repository at this point in the history

  8. libpq: Use pg_threads.h.

    * adopt pg_threads.h for mutexes
    * remove a local pthreads abstraction
    Discussion:
    Reviewed-by:

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  9. pg_basebackup: Use pg_threads.h.

    Previously, Windows systems used a thread to stream WAL, and POSIX
    systems used a subprocess.  Now all systems use a thread.
    Discussion:
    Reviewed-by:

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  10. pg_signal_processor: Infrastructure for cleanup.

    Provide a way to register signal handlers than run serially in a special
    thread.  This is intended to allow frontend programs to use more
    complicated shutdown code when you hit ^C, without having to worry
    about async-signal-safety.
    XXX experimental
    Discussion:
    Reviewed-by:

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  11. fe_utils: Provide cancel_set for fast quit paths.

    Provide a simpler way for frontend programs managing many connections to
    arrange cleanup.  Now that we can run more complicated code on eg SIGINT
    via pg_signal_processor, this API provides an easy way to manage a set
    of connections that need to be canceled.  We couldn't have done this
    before, because it requires locks.  A follow-up patch will use this for
    pg_dump/pg_restore.
    XXX Experimental!
    Discussion:
    Reviewed-by:

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  12. XXX pg_dump: Refactor to use threads on all platforms.

    XXX See Bryan Green's patches.  This was just an experiment that grew
    out of switching to pg_thread.h and then accidentally continuing to
    hack.  Clearly we also need to get rid of the pipes that were only
    needed because of the make -j architecture, which his patches address.
    Discussion:
    Reviewed-by:

    macdice authored and Commitfest Bot committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  13. Configuration menu

    Browse the repository at this point in the history

Read the original on github.com ↗