Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Fix PTHREAD_FOO_INITIALIZER for C++ by not using volatile in...
details: https://anonhg.NetBSD.org/src/rev/8f3d1052c180
branches: trunk
changeset: 340208:8f3d1052c180
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Aug 27 12:30:50 2015 +0000
description:
Fix PTHREAD_FOO_INITIALIZER for C++ by not using volatile in the relevant
pthread types in C++ builds, attempt 2.
The problem with attempt 1 was making assumptions of what the MD
__cpu_simple_lock_t (declared volatile) looks like. To get a same type
except non-volatile, we change the MD type to __cpu_simple_lock_nv_t
and typedef __cpu_simple_lock_t as a volatile __cpu_simple_lock_nv_t.
IMO, __cpu_simple_lock_t should not be volatile at all, but changing it
now is too risky.
Fixes at least Rumprun w/ gcc 5.1/5.2. Furthermore, the mpd application
(and possibly others) will no longer require NetBSD-specific patches.
Tested: build.sh for i386, Rumprun for x86_64 w/ gcc 5.2.
Based on the patch from Christos in lib/49989.
diffstat:
lib/libpthread/pthread_types.h | 31 +++++++++++++++++++++----------
sys/arch/aarch64/include/types.h | 4 ++--
sys/arch/amd64/include/types.h | 4 ++--
sys/arch/arm/include/types.h | 6 +++---
sys/arch/hppa/include/types.h | 6 +++---
sys/arch/i386/include/types.h | 4 ++--
sys/arch/ia64/include/types.h | 4 ++--
sys/arch/m68k/include/types.h | 4 ++--
sys/arch/mips/include/types.h | 4 ++--
sys/arch/or1k/include/types.h | 4 ++--
sys/arch/powerpc/include/types.h | 4 ++--
sys/arch/riscv/include/types.h | 4 ++--
sys/arch/sh3/include/types.h | 4 ++--
sys/arch/sparc/include/types.h | 4 ++--
sys/arch/usermode/include/types.h | 4 ++--
sys/arch/vax/include/types.h | 4 ++--
sys/sys/types.h | 4 +++-
17 files changed, 56 insertions(+), 43 deletions(-)
diffs (truncated from 378 to 300 lines):
diff -r 66e18ebbd3c6 -r 8f3d1052c180 lib/libpthread/pthread_types.h
--- a/lib/libpthread/pthread_types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/lib/libpthread/pthread_types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_types.h,v 1.16 2015/06/26 11:25:22 pooka Exp $ */
+/* $NetBSD: pthread_types.h,v 1.17 2015/08/27 12:30:50 pooka Exp $ */
/*-
* Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -35,8 +35,19 @@
/*
* We use the "pthread_spin_t" name internally; "pthread_spinlock_t" is the
* POSIX spinlock object.
+ *
+ * C++ expects to be using PTHREAD_FOO_INITIALIZER as a member initializer.
+ * This does not work for volatile types. Since C++ does not touch the guts
+ * of those types, we do not include volatile in the C++ definitions.
*/
-typedef __cpu_simple_lock_t pthread_spin_t;
+typedef __cpu_simple_lock_t pthread_spin_t;
+#ifdef __cplusplus
+typedef __cpu_simple_lock_nv_t __pthread_spin_t;
+#define __pthread_volatile
+#else
+typedef pthread_spin_t __pthread_spin_t;
+#define __pthread_volatile volatile
+#endif
/*
* Copied from PTQ_HEAD in pthread_queue.h
@@ -100,16 +111,16 @@
#endif
struct __pthread_mutex_st {
unsigned int ptm_magic;
- pthread_spin_t ptm_errorcheck;
+ __pthread_spin_t ptm_errorcheck;
#ifdef __CPU_SIMPLE_LOCK_PAD
uint8_t ptm_pad1[3];
#endif
- pthread_spin_t ptm_interlock; /* unused - backwards compat */
+ __pthread_spin_t ptm_interlock; /* unused - backwards compat */
#ifdef __CPU_SIMPLE_LOCK_PAD
uint8_t ptm_pad2[3];
#endif
- volatile pthread_t ptm_owner;
- pthread_t * volatile ptm_waiters;
+ __pthread_volatile pthread_t ptm_owner;
+ pthread_t * __pthread_volatile ptm_waiters;
unsigned int ptm_recursed;
void *ptm_spare2; /* unused - backwards compat */
};
@@ -145,7 +156,7 @@
unsigned int ptc_magic;
/* Protects the queue of waiters */
- pthread_spin_t ptc_lock;
+ __pthread_spin_t ptc_lock;
pthread_queue_t ptc_waiters;
pthread_mutex_t *ptc_mutex; /* Current mutex */
@@ -179,7 +190,7 @@
struct __pthread_spinlock_st {
unsigned int pts_magic;
- pthread_spin_t pts_spin;
+ __pthread_spin_t pts_spin;
int pts_flags;
};
@@ -197,12 +208,12 @@
unsigned int ptr_magic;
/* Protects data below */
- pthread_spin_t ptr_interlock;
+ __pthread_spin_t ptr_interlock;
pthread_queue_t ptr_rblocked;
pthread_queue_t ptr_wblocked;
unsigned int ptr_nreaders;
- volatile pthread_t ptr_owner;
+ __pthread_volatile pthread_t ptr_owner;
void *ptr_private;
};
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/aarch64/include/types.h
--- a/sys/arch/aarch64/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/aarch64/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
+/* $NetBSD: types.h,v 1.2 2015/08/27 12:30:50 pooka Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
/*
* This should have always been an 8-bit type.
*/
-typedef volatile unsigned char __cpu_simple_lock_t;
+typedef unsigned char __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/amd64/include/types.h
--- a/sys/arch/amd64/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/amd64/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.47 2015/08/21 14:22:14 pooka Exp $ */
+/* $NetBSD: types.h,v 1.48 2015/08/27 12:30:50 pooka Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -67,7 +67,7 @@
#define PRIxREGISTER "lx"
#define PRIxREGISTER32 "x"
-typedef volatile unsigned char __cpu_simple_lock_t;
+typedef unsigned char __cpu_simple_lock_nv_t;
/* __cpu_simple_lock_t used to be a full word. */
#define __CPU_SIMPLE_LOCK_PAD
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/arm/include/types.h
--- a/sys/arch/arm/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/arm/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.29 2014/09/13 17:41:03 matt Exp $ */
+/* $NetBSD: types.h,v 1.30 2015/08/27 12:30:50 pooka Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@@ -71,9 +71,9 @@
* to user-space, we don't want ABI breakage there.
*/
#if defined(_KERNEL)
-typedef volatile unsigned char __cpu_simple_lock_t;
+typedef unsigned char __cpu_simple_lock_nv_t;
#else
-typedef volatile int __cpu_simple_lock_t;
+typedef int __cpu_simple_lock_nv_t;
#endif /* _KERNEL */
#define __SIMPLELOCK_LOCKED 1
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/hppa/include/types.h
--- a/sys/arch/hppa/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/hppa/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.23 2014/02/24 07:23:43 skrll Exp $ */
+/* $NetBSD: types.h,v 1.24 2015/08/27 12:30:51 pooka Exp $ */
/* $OpenBSD: types.h,v 1.6 2001/08/11 01:58:34 art Exp $ */
@@ -68,9 +68,9 @@
/*
* Semaphores must be aligned on 16-byte boundaries on the PA-RISC.
*/
-typedef volatile struct {
+typedef struct {
volatile unsigned long csl_lock[4];
-} __cpu_simple_lock_t;
+} __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED { { 0, 0, 0, 0} }
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/i386/include/types.h
--- a/sys/arch/i386/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/i386/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.82 2015/08/21 14:22:14 pooka Exp $ */
+/* $NetBSD: types.h,v 1.83 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -90,7 +90,7 @@
typedef int register_t;
#define PRIxREGISTER "x"
-typedef volatile unsigned char __cpu_simple_lock_t;
+typedef unsigned char __cpu_simple_lock_nv_t;
/* __cpu_simple_lock_t used to be a full word. */
#define __CPU_SIMPLE_LOCK_PAD
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/ia64/include/types.h
--- a/sys/arch/ia64/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/ia64/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.7 2012/12/26 19:43:10 martin Exp $ */
+/* $NetBSD: types.h,v 1.8 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -63,7 +63,7 @@
typedef long int register_t;
#define PRIxREGISTER "lx"
-typedef __volatile int __cpu_simple_lock_t;
+typedef int __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/m68k/include/types.h
--- a/sys/arch/m68k/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/m68k/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.30 2011/11/22 15:25:28 joerg Exp $ */
+/* $NetBSD: types.h,v 1.31 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -63,7 +63,7 @@
typedef int register_t;
#define PRIxREGISTER "x"
-typedef volatile unsigned char __cpu_simple_lock_t;
+typedef unsigned char __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 0x80 /* result of `tas' insn */
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/mips/include/types.h
--- a/sys/arch/mips/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/mips/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.58 2015/06/11 14:32:16 matt Exp $ */
+/* $NetBSD: types.h,v 1.59 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -133,7 +133,7 @@
#define PCU_UNIT_COUNT 2
#endif
-typedef volatile unsigned int __cpu_simple_lock_t;
+typedef unsigned int __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/or1k/include/types.h
--- a/sys/arch/or1k/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/or1k/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.1 2014/09/03 19:34:26 matt Exp $ */
+/* $NetBSD: types.h,v 1.2 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
} label_t;
#endif
-typedef volatile unsigned int __cpu_simple_lock_t;
+typedef unsigned int __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/powerpc/include/types.h
--- a/sys/arch/powerpc/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/powerpc/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.50 2014/12/14 23:49:17 chs Exp $ */
+/* $NetBSD: types.h,v 1.51 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (C) 1995 Wolfgang Solfrank.
@@ -68,7 +68,7 @@
typedef __uint32_t tlb_asid_t; /* for booke */
#endif
-typedef volatile int __cpu_simple_lock_t;
+typedef int __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/riscv/include/types.h
--- a/sys/arch/riscv/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/riscv/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.2 2015/03/28 16:13:56 matt Exp $ */
+/* $NetBSD: types.h,v 1.3 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
} label_t;
#endif
-typedef volatile unsigned int __cpu_simple_lock_t;
+typedef unsigned int __cpu_simple_lock_nv_t;
#define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0
diff -r 66e18ebbd3c6 -r 8f3d1052c180 sys/arch/sh3/include/types.h
--- a/sys/arch/sh3/include/types.h Thu Aug 27 10:22:12 2015 +0000
+++ b/sys/arch/sh3/include/types.h Thu Aug 27 12:30:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.34 2011/07/17 23:48:35 dyoung Exp $ */
+/* $NetBSD: types.h,v 1.35 2015/08/27 12:30:51 pooka Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -64,7 +64,7 @@
typedef int register_t;
#define PRIxREGISTER "x"
Home |
Main Index |
Thread Index |
Old Index