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 16/10/2017 16:00, H.J. Lu wrote:
> On Mon, Oct 16, 2017 at 10:39 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 9:05 AM, Andreas Schwab <schwab@suse.de> wrote:
>>>> On Okt 16 2017, "H.J. Lu" <hjl.tools@gmail.com> wrote:
>>>>
>>>>> Here __x86_64__ == __PTHREAD_MUTEX_HAVE_PREV,  which ties
>>>>> __PTHREAD_MUTEX_HAVE_PREV with __nusers and __PTHREAD_SPINS.
>>>>
>>>> That's what I would call related by chance.  The position of __nusers
>>>> differs only because __kind must not be moved, and that difference
>>>> existed already before the introduction of __prev and __next.
>>>>
>>>
>>> By chance or not, they can't be changed on x86.
>>
>> This file is used by all architectures.
>>
>> Andreas.
>>
> 
> The current code has
> 
> /* Common definition of pthread_mutex_t. */
> 
> #if __WORDSIZE == 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
> 
> /* Lock elision support.  */
> #if __PTHREAD_MUTEX_LOCK_ELISION
> # if __WORDSIZE == 64
> #  define __PTHREAD_SPINS_DATA \
>   short __spins; \
>   short __elision
> #  define __PTHREAD_SPINS             0, 0
> # else
> #  define __PTHREAD_SPINS_DATA \
>   struct \
>   { \
>     short __espins; \
>     short __eelision; \
>   } __elision_data
> #  define __PTHREAD_SPINS         { 0, 0 }
> #  define __spins __elision_data.__espins
> #  define __elision __elision_data.__eelision
> # endif
> #else
> # define __PTHREAD_SPINS_DATA int __spins
> /* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER.  */
> # define __PTHREAD_SPINS 0
> #endif
> 
> struct __pthread_mutex_s
> {
>   int __lock __LOCK_ALIGNMENT;
>   unsigned int __count;
>   int __owner;
> #if __WORDSIZE == 64
>   unsigned int __nusers;
> #endif
>   /* KIND must stay at this position in the structure to maintain
>      binary compatibility with static initializers.  */
>   int __kind;
>   __PTHREAD_COMPAT_PADDING_MID
> #if __WORDSIZE == 64
>   __PTHREAD_SPINS_DATA;
>   __pthread_list_t __list;
> # define __PTHREAD_MUTEX_HAVE_PREV      1
> #else
>   unsigned int __nusers;
>   __extension__ union
>   {
>     __PTHREAD_SPINS_DATA;
>     __pthread_slist_t __list;
>   };
> #endif
>   __PTHREAD_COMPAT_PADDING_END
> };
> 
> __PTHREAD_MUTEX_HAVE_PREV is the same as __WORDSIZE == 64,
> which ties it together with __nusers  and __PTHREAD_SPINS_DATA.  We
> can't change it for existing targets.
I agree, in the end __PTHREAD_MUTEX_HAVE_PREV will define which internal
layout __pthread_mutex_s will use to place __nusers and __list.  We can
add an extra architecture define to set the __nusers/__list layout along
with __PTHREAD_MUTEX_HAVE_PREV, however this will only add complexity.

I plan to send an update version of this patch and I think it worth add
a comment about __PTHREAD_MUTEX_HAVE_PREV and the internal layout coupling.  


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