Bug 82617

Summary: Build failure when using older pthreads implementations
Product: p11-glue Reporter: Baruch Siach <baruch>
Component: p11-kitAssignee: Stef Walter <stefw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: stefw
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Fix build against older pthreads implementations
Fix build against older pthreads implementations (revised)

Description Baruch Siach 2014-08-14 13:13:54 UTC
Created attachment 104620 [details]
Fix build against older pthreads implementations

Older pthreads implementations like glibc NPTL prior to version 2.12, and
uClibc linuxthreads (both), need _XOPEN_SOURCE to expose
pthread_mutexattr_settype() and THREAD_MUTEX_DEFAULT.
    
This results in the following build error:
    
  CC       compat.lo
compat.c: In function 'p11_mutex_init':
compat.c:164:2: warning: implicit declaration of function 'pthread_mutexattr_settype' [-Wimplicit-function-declaration]
compat.c:164:2: warning: nested extern declaration of 'pthread_mutexattr_settype' [-Wnested-externs]
compat.c:164:36: error: 'PTHREAD_MUTEX_DEFAULT' undeclared (first use in this function)

The attached patch should fix this.
Comment 1 Stef Walter 2014-08-14 13:16:24 UTC
I'm a bit worried about defining this in a header. Would it work to define it very early in the compat.c file?
Comment 2 Baruch Siach 2014-08-14 13:22:14 UTC
(In reply to comment #1)
> I'm a bit worried about defining this in a header. Would it work to define
> it very early in the compat.c file?

This can only work if you define _XOPEN_SOURCE before '#include "compat.h"'. Is that what you mean?
Comment 3 Stef Walter 2014-08-14 13:27:01 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > I'm a bit worried about defining this in a header. Would it work to define
> > it very early in the compat.c file?
> 
> This can only work if you define _XOPEN_SOURCE before '#include "compat.h"'.
> Is that what you mean?

Yes.
Comment 4 Baruch Siach 2014-08-14 14:05:31 UTC
Created attachment 104621 [details] [review]
Fix build against older pthreads implementations (revised)

Here is a revised patch, build tested.
Comment 5 Stef Walter 2014-08-15 06:07:20 UTC
Thanks. Merged the patch into master.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.