Looking at patterns like this

        if (XLogCtl->LogwrtRqst.Write < EndPos)
                XLogCtl->LogwrtRqst.Write = EndPos;

It seems possible to implement with

    do {
        XLogRecPtr      currwrite;

        currwrite = pg_atomic_read_u64(LogwrtRqst.Write);
        if (currwrite > EndPos)
            break;  // already done by somebody else
        if (pg_atomic_compare_exchange_u64(LogwrtRqst.Write,
                                           currwrite, EndPos))
            break;  // successfully updated
    } while (true);

This assumes that LogwrtRqst.Write never goes backwards, so it doesn't
seem good material for a general routine.

This *seems* correct to me, though this is muddy territory to me.  Also,
are there better ways to go about this?

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Reply via email to