This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix libgomp semaphores
On 11/29/2011 08:09 AM, Richard Henderson wrote:
>> +static inline bool
>> +likely_compare_exchange (int *ptr, int *expected, int val, bool weak,
>> + enum memmodel succ, enum memmodel fail)
>> {
>> + return __builtin_expect (__atomic_compare_exchange_n (ptr, expected, val,
>> + weak, succ, fail), 1);
>> }
>
> Please move this to libgomp.h just below the memmodel definition, as
> a macro so that it's not tied to int. It seems likely that we'll
> want this elsewhere in libgomp as we convert things.
... although it does occur to me that it would be more useful to adjust gcc/predict.c so that we get this by default. Then we don't have to contort loops like
> + while (1)
> + if (likely_compare_exchange (sem, &count, ((count + SEM_INC) & ~SEM_WAIT),
> + false, MEMMODEL_RELEASE, MEMMODEL_RELAXED))
> + break;
this. This is surely more natural as
while (!__atomic_compare_exchange_n (sem, &count, ...))
continue;
r~