summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--include/pthread/pthread.h3
-rw-r--r--sysdeps/generic/bits/mutex-attr.h5
-rw-r--r--sysdeps/generic/bits/mutex.h6
-rw-r--r--sysdeps/generic/pt-mutex-destroy.c7
-rw-r--r--sysdeps/generic/pt-mutex-init.c11
-rw-r--r--sysdeps/generic/pt-mutexattr.c10
7 files changed, 50 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index aa535eb..890193c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-06-01 Neal H. Walfield <neal@gnu.org>
+
+ * include/pthread/pthread.h (PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP):
+ New definition.
+ * sysdeps/generic/bits/mutex.h
+ (__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): New definition.
+ * sysdeps/generic/bits/mutex-attr.h (__pthread_recursive_mutexattr):
+ New definition.
+ * sysdeps/generic/pt-mutexattr.c (__pthread_recursive_mutexattr):
+ New declaration.
+ * sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): If ATTR
+ is &__PTHREAD_RECURSIVE_MUTEXATTR, don't allocate a copy, just
+ save in MUTEX->ATTR.
+ * sysdeps/generic/pt-mutex-destroy.c (_pthread_mutex_destroy): If
+ MUTEX->ATTR is &__PTHREAD_RECURSIVE_MUTEXATTR, don't free it.
+
2008-05-29 Thomas Schwinge <tschwinge@gnu.org>
* headers.m4: Link files into `sysroot/include/' instead of `include/'.
diff --git a/include/pthread/pthread.h b/include/pthread/pthread.h
index 0437550..7f69573 100644
--- a/include/pthread/pthread.h
+++ b/include/pthread/pthread.h
@@ -314,6 +314,9 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
typedef struct __pthread_mutex pthread_mutex_t;
#define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER
+/* Static initializer for recursive mutexes. */
+#define PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP \
+ __PTHREAD_MUTEX_RECURSIVE_INITIALIZER
/* Create a mutex with attributes given by ATTR and store it in
*__MUTEX. */
diff --git a/sysdeps/generic/bits/mutex-attr.h b/sysdeps/generic/bits/mutex-attr.h
index 883b074..420d5d1 100644
--- a/sysdeps/generic/bits/mutex-attr.h
+++ b/sysdeps/generic/bits/mutex-attr.h
@@ -1,5 +1,5 @@
/* Mutex attribute type. Generic version.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2008 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
@@ -30,4 +30,7 @@ struct __pthread_mutexattr
enum __pthread_mutex_type mutex_type;
};
+/* Attributes for a recursive mutex. */
+extern const struct __pthread_mutexattr __pthread_recursive_mutexattr;
+
#endif /* bits/mutex-attr.h */
diff --git a/sysdeps/generic/bits/mutex.h b/sysdeps/generic/bits/mutex.h
index 1aaf80e..e0ae3db 100644
--- a/sysdeps/generic/bits/mutex.h
+++ b/sysdeps/generic/bits/mutex.h
@@ -1,5 +1,5 @@
/* Mutex type. Generic version.
- Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 2008 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
@@ -54,6 +54,10 @@ struct __pthread_mutex
# define __PTHREAD_MUTEX_INITIALIZER \
{ __SPIN_LOCK_INITIALIZER, __SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0, 0 }
+# define __PTHREAD_MUTEX_RECURSIVE_INITIALIZER \
+ { __SPIN_LOCK_INITIALIZER, __SPIN_LOCK_INITIALIZER, 0, 0, \
+ (struct __pthread_mutexattr *) &__pthread_recursive_mutexattr, 0, 0, 0 }
+
# endif
#endif /* Not __pthread_mutex_defined. */
diff --git a/sysdeps/generic/pt-mutex-destroy.c b/sysdeps/generic/pt-mutex-destroy.c
index 72faefe..0c9d514 100644
--- a/sysdeps/generic/pt-mutex-destroy.c
+++ b/sysdeps/generic/pt-mutex-destroy.c
@@ -1,5 +1,5 @@
/* Destroy a mutex. Generic version.
- Copyright (C) 2000,02 Free Software Foundation, Inc.
+ Copyright (C) 2000,02, 2008 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
@@ -26,7 +26,10 @@
int
_pthread_mutex_destroy (pthread_mutex_t *mutex)
{
- if (mutex->attr)
+ if (mutex->attr == &__pthread_recursive_mutexattr)
+ /* Static attributes. */
+ ;
+ else
free (mutex->attr);
return 0;
diff --git a/sysdeps/generic/pt-mutex-init.c b/sysdeps/generic/pt-mutex-init.c
index da1781b..83f5b18 100644
--- a/sysdeps/generic/pt-mutex-init.c
+++ b/sysdeps/generic/pt-mutex-init.c
@@ -1,5 +1,5 @@
/* Initialize a mutex. Generic version.
- Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 2008 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
@@ -32,10 +32,15 @@ _pthread_mutex_init (pthread_mutex_t *mutex,
if (! attr
|| memcmp (attr, &__pthread_default_mutexattr, sizeof (*attr) == 0))
- /* Use the default attributes. */
+ /* The default attributes. */
return 0;
- /* Non-default attributes. */
+ if (attr == &__pthread_recursive_mutexattr)
+ /* Non-default but known attributes. */
+ {
+ mutex->attr = attr;
+ return 0;
+ }
mutex->attr = malloc (sizeof *attr);
if (! mutex->attr)
diff --git a/sysdeps/generic/pt-mutexattr.c b/sysdeps/generic/pt-mutexattr.c
index 647db24..d80a7d7 100644
--- a/sysdeps/generic/pt-mutexattr.c
+++ b/sysdeps/generic/pt-mutexattr.c
@@ -1,5 +1,5 @@
/* Default mutex attributes. Generic version.
- Copyright (C) 2000,02 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2008 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
@@ -27,3 +27,11 @@ const struct __pthread_mutexattr __pthread_default_mutexattr =
pshared: PTHREAD_PROCESS_PRIVATE,
mutex_type: PTHREAD_MUTEX_DEFAULT
};
+
+const struct __pthread_mutexattr __pthread_recursive_mutexattr =
+{
+ prioceiling: 0,
+ protocol: PTHREAD_PRIO_NONE,
+ pshared: PTHREAD_PROCESS_PRIVATE,
+ mutex_type: PTHREAD_MUTEX_RECURSIVE
+};