This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Optimize generic spinlock code and use C11 like atomic macros.


On 04/10/2017 03:36 PM, Andreas Schwab wrote:
On Apr 10 2017, Stefan Liebler <stli@linux.vnet.ibm.com> wrote:

On 04/10/2017 10:17 AM, Andreas Schwab wrote:
On Apr 07 2017, Stefan Liebler <stli@linux.vnet.ibm.com> wrote:

/* ATOMIC_EXCHANGE_USES_CAS is equal to 1 if atomic_exchange operations

Why 1 exactly, and not just non-zero?

Andreas.


This points out that there is only a true/false choice and
all architectures have to define it.

That doesn't answer my question.  Why do you need the dance of checking
for 1 explicitly?

Andreas.

At the moment there is only a choice between 0 and 1.
The check ensures that ATOMIC_EXCHANGE_USES_CAS is defined and it has a specific value.
If someone defines it to another value, he will get an error here.
Then the check and the comment is hopefully updated, too.

__HAVE_64B_ATOMICS has to be 0 or 1, but it is not checked explicitly.
Here are some users of it:
./nptl/sem_waitcommon.c:81:#if !__HAVE_64B_ATOMICS
./nptl/sem_waitcommon.c:91:#if __HAVE_64B_ATOMICS
./nptl/pthread_cond_common.c:26:#if __HAVE_64B_ATOMICS == 1
./nptl/pthread_cond_common.c:59:#else
./nptl/pthread_cond_common.c:245:#endif  /* !__HAVE_64B_ATOMICS  */
...
If someone defines __HAVE_64B_ATOMICS to 2, build/test will fail with some unspecified error.
If someone defines ATOMIC_EXCHANGE_USES_CAS to 2, build fails with
"ATOMIC_EXCHANGE_USES_CAS has to be defined to 0 or 1".

But you are right, zero or non-zero is fine, too.
My latest patch is only using:
#if ! ATOMIC_EXCHANGE_USES_CAS
#else
#endif

But perhaps #if ATOMIC_EXCHANGE_USES_CAS == 1 will be introduced by a future patch.

Bye
Stefan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]