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]

Fix PTHREAD_MUTEX_INITIALIZER for C++


Compilation with g++ on 64-bit systems using the following test
program fails with with current glibc CVS:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define _GNU_SOURCE 1

#include <pthread.h>


static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t mutexA = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static pthread_mutex_t mutexB = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
static pthread_mutex_t mutexC = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;


int
main (void)
{
  return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pthread.c:6: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:6: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:7: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:7: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:8: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:8: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:9: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â
pthread.c:9: error: invalid conversion from âvoid*â to â__pthread_mutex_u*â

The appended patch fixes this.  Ok to commit?

Andreas

2006-01-03  Andreas Jaeger  <aj@suse.de>

	* sysdeps/pthread/pthread.h (PTHREAD_MUTEX_INITIALIZER): Use C++
	compatible initializer.
	(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP): Likewise.
	(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP): Likewise.
	(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP): Likewise.

============================================================
Index: nptl/sysdeps/pthread/pthread.h
--- nptl/sysdeps/pthread/pthread.h	27 Dec 2005 00:59:21 -0000	1.37
+++ nptl/sysdeps/pthread/pthread.h	3 Jan 2006 16:00:01 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -74,14 +74,14 @@ enum
 /* Mutex initializers.  */
 #if __WORDSIZE == 64
 # define PTHREAD_MUTEX_INITIALIZER \
-  { { 0, 0, 0, 0, 0, 0, (void *) 0, (void *) 0 } }
+  { { 0, 0, 0, 0, 0, 0, (union __pthread_mutex_u *) 0, (union __pthread_mutex_u *) 0 } }
 # ifdef __USE_GNU
 #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, (void *) 0, (void *) 0 } }
+  { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, (union __pthread_mutex_u *) 0, (union __pthread_mutex_u *) 0 } }
 #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, (void *) 0, (void *) 0 } }
+  { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, (union __pthread_mutex_u *) 0, (union __pthread_mutex_u *) 0 } }
 #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
-  { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, (void *) 0, (void *) 0 } }
+  { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, (union __pthread_mutex_u *) 0, (union __pthread_mutex_u *) 0 } }
 # endif
 #else
 # define PTHREAD_MUTEX_INITIALIZER \

-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SUSE Linux Products GmbH, Maxfeldstr. 5, 90409 NÃrnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Attachment: pgp00000.pgp
Description: PGP signature


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