Re: [HACKERS] Fix performance of generic atomics - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Fix performance of generic atomics
Date
Msg-id 15742.1495723153@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] Fix performance of generic atomics  (Sokolov Yura <funny.falcon@postgrespro.ru>)
Responses Re: [HACKERS] Fix performance of generic atomics  (Sokolov Yura <funny.falcon@postgrespro.ru>)
List pgsql-hackers
Sokolov Yura <funny.falcon@postgrespro.ru> writes:
@@ -382,12 +358,8 @@ static inline uint64pg_atomic_fetch_and_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 and_){
uint64old;
 
-    while (true)
-    {
-        old = pg_atomic_read_u64_impl(ptr);
-        if (pg_atomic_compare_exchange_u64_impl(ptr, &old, old & and_))
-            break;
-    }
+    old = pg_atomic_read_u64_impl(ptr);
+    while (!pg_atomic_compare_exchange_u64_impl(ptr, &old, old & and_));    return old;}#endif

FWIW, I do not think that writing the loops like that is good style.
It looks like a typo and will confuse readers.  You could perhaps
write the same code with better formatting, eg
while (!pg_atomic_compare_exchange_u64_impl(ptr, &old, old & and_))    /* skip */ ;

but why not leave the formulation with while(true) and a break alone?

(I take no position on whether moving the read of "old" outside the
loop is a valid optimization.)
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: retry shm attach for windows (WAS: Re: [HACKERS] OK, so culicidae is *still* broken)
Next
From: Aleksander Alekseev
Date:
Subject: Re: [HACKERS] Fix performance of generic atomics