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] Define __PTHREAD_MUTEX_HAVE_PREV only if undefined [BZ #22298]


On Mon, Oct 16, 2017 at 8:25 AM, Andreas Schwab <schwab@suse.de> wrote:
> On Okt 16 2017, "H.J. Lu" <hjl.tools@gmail.com> wrote:
>
>> On Mon, Oct 16, 2017 at 7:31 AM, Andreas Schwab <schwab@suse.de> wrote:
>>> On Okt 16 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>>>
>>>> diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
>>>> index 68b82b6..5dfe01e 100644
>>>> --- a/sysdeps/nptl/bits/thread-shared-types.h
>>>> +++ b/sysdeps/nptl/bits/thread-shared-types.h
>>>> @@ -58,8 +58,7 @@
>>>>  #include <bits/pthreadtypes-arch.h>
>>>>
>>>>  /* Common definition of pthread_mutex_t. */
>>>> -
>>>> -#if __WORDSIZE == 64
>>>> +#if __PTHREAD_MUTEX_HAVE_PREV
>>>>  typedef struct __pthread_internal_list
>>>>  {
>>>>    struct __pthread_internal_list *__prev;
>>>> @@ -74,7 +73,7 @@ typedef struct __pthread_internal_slist
>>>>
>>>>  /* Lock elision support.  */
>>>>  #if __PTHREAD_MUTEX_LOCK_ELISION
>>>> -# if __WORDSIZE == 64
>>>> +# if __PTHREAD_MUTEX_HAVE_PREV
>>>>  #  define __PTHREAD_SPINS_DATA       \
>>>>    short __spins;             \
>>>>    short __elision
>>>> @@ -101,17 +100,16 @@ struct __pthread_mutex_s
>>>>    int __lock __LOCK_ALIGNMENT;
>>>>    unsigned int __count;
>>>>    int __owner;
>>>> -#if __WORDSIZE == 64
>>>> +#if __PTHREAD_MUTEX_HAVE_PREV
>>>>    unsigned int __nusers;
>>>>  #endif
>>>
>>> The name doesn't really fit here.  There is nothing matching prev in
>>> __nusers or __PTHREAD_SPINS_DATA.
>>>
>>
>> True.  But they are tied together.
>
> Are they?  They look rather unrelated, or only related by chance.
>
> Andreas.
>

Glibc 2.25 has

#ifdef __x86_64__
typedef struct __pthread_internal_list
{
  struct __pthread_internal_list *__prev;
  struct __pthread_internal_list *__next;
} __pthread_list_t;
#else
typedef struct __pthread_internal_slist
{
  struct __pthread_internal_slist *__next;
} __pthread_slist_t;
#endif


/* Data structures for mutex handling.  The structure of the attribute
   type is not exposed on purpose.  */
typedef union
{
  struct __pthread_mutex_s
  {
    int __lock;
    unsigned int __count;
    int __owner;
#ifdef __x86_64__
    unsigned int __nusers;
#endif
    /* KIND must stay at this position in the structure to maintain
       binary compatibility with static initializers.  */
    int __kind;
#ifdef __x86_64__
    short __spins;
    short __elision;
    __pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV      1
/* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER.  */
# define __PTHREAD_SPINS             0, 0
#else
    unsigned int __nusers;
    __extension__ union
    {
      struct
      {
        short __espins;
        short __elision;
# define __spins __elision_data.__espins
# define __elision __elision_data.__elision
# define __PTHREAD_SPINS         { 0, 0 }
      } __elision_data;
      __pthread_slist_t __list;
    };
#endif
  } __data;
  char __size[__SIZEOF_PTHREAD_MUTEX_T];
  long int __align;
} pthread_mutex_t;

Here __x86_64__ == __PTHREAD_MUTEX_HAVE_PREV,  which ties
__PTHREAD_MUTEX_HAVE_PREV with __nusers and __PTHREAD_SPINS.

-- 
H.J.


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