diff options
| author | jruoho <jruoho@NetBSD.org> | 2010-07-09 08:22:04 +0000 |
|---|---|---|
| committer | jruoho <jruoho@NetBSD.org> | 2010-07-09 08:22:04 +0000 |
| commit | 6aa4892177ef68ab15087600a06f86c7cb9ec24e (patch) | |
| tree | b8774fca076c295348105b90e01965879d384ddb | |
| parent | 7296ba383a0848ff0f4e6f5b4bed749e1241b4e8 (diff) | |
Rationalize by moving
pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
| -rw-r--r-- | lib/libpthread/Makefile | 8 | ||||
| -rw-r--r-- | lib/libpthread/pthread_getspecific.3 | 55 | ||||
| -rw-r--r-- | lib/libpthread/pthread_key_create.3 | 101 | ||||
| -rw-r--r-- | lib/libpthread/pthread_key_delete.3 | 133 | ||||
| -rw-r--r-- | lib/libpthread/pthread_setspecific.3 | 125 |
5 files changed, 111 insertions, 311 deletions
diff --git a/lib/libpthread/Makefile b/lib/libpthread/Makefile index c0db1100781..c5930f4201f 100644 --- a/lib/libpthread/Makefile +++ b/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.68 2010/07/09 07:31:01 jruoho Exp $ +# $NetBSD: Makefile,v 1.69 2010/07/09 08:22:04 jruoho Exp $ # WARNS= 4 @@ -105,11 +105,11 @@ MAN+= affinity.3 pthread.3 \ pthread_exit.3 \ pthread_getname_np.3 \ pthread_getspecific.3 pthread_join.3 \ - pthread_key_create.3 pthread_key_delete.3 pthread_kill.3 \ + pthread_key_create.3 pthread_kill.3 \ pthread_mutex.3 pthread_mutexattr.3 \ pthread_once.3 pthread_rwlock.3 pthread_rwlockattr.3 \ pthread_schedparam.3 pthread_self.3 \ - pthread_setspecific.3 pthread_sigmask.3 pthread_spin.3 \ + pthread_sigmask.3 pthread_spin.3 \ pthread_suspend_np.3 pthread_testcancel.3 MLINKS+= affinity.3 pthread_setaffinity_np.3 @@ -155,6 +155,8 @@ MLINKS+= pthread_condattr.3 pthread_condattr_init.3 MLINKS+= pthread_condattr.3 pthread_condattr_destroy.3 MLINKS+= pthread_getname_np.3 pthread_setname_np.3 +MLINKS+= pthread_getspecific.3 pthread_setspecific.3 +MLINKS+= pthread_key_create.3 pthread_key_delete.3 MLINKS+= pthread_mutex.3 pthread_mutex_init.3 MLINKS+= pthread_mutex.3 pthread_mutex_destroy.3 diff --git a/lib/libpthread/pthread_getspecific.3 b/lib/libpthread/pthread_getspecific.3 index d54042013e8..dee33414fb8 100644 --- a/lib/libpthread/pthread_getspecific.3 +++ b/lib/libpthread/pthread_getspecific.3 @@ -1,6 +1,6 @@ -.\" $NetBSD: pthread_getspecific.3,v 1.3 2008/05/02 18:11:04 martin Exp $ +.\" $NetBSD: pthread_getspecific.3,v 1.4 2010/07/09 08:22:04 jruoho Exp $ .\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. .\" All rights reserved. .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -55,39 +55,50 @@ .\" .\" $FreeBSD: src/lib/libpthread/man/pthread_getspecific.3,v 1.11 2002/09/16 19:29:28 mini Exp $ .\" -.Dd January 30, 2003 +.Dd July 9, 2010 .Dt PTHREAD_GETSPECIFIC 3 .Os .Sh NAME .Nm pthread_getspecific -.Nd get a thread-specific data value +.Nd thread-specific data value .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS .In pthread.h .Ft void * .Fn pthread_getspecific "pthread_key_t key" +.Ft int +.Fn pthread_setspecific "pthread_key_t key" "const void *value" .Sh DESCRIPTION The .Fn pthread_getspecific function returns the value currently bound to the specified .Fa key on behalf of the calling thread. +Conversely, the +.Fn pthread_setspecific +function associates a thread-specific value with a +.Fa key +obtained via a previous call to +.Xr pthread_key_create 3 . +Different threads have different values bound to each key. +These values are typically pointers to blocks of dynamically +allocated memory that have been reserved for use by the calling thread. .Pp -The effect of calling -.Fn pthread_getspecific -with a +Undefined behavior may follow if either function is called with a .Fa key value not obtained from -.Fn pthread_key_create -or after +.Xr pthread_key_create 3 , +or if the call is made after .Fa key has been deleted with -.Fn pthread_key_delete -is undefined. -.Pp -.Fn pthread_getspecific -may be called from a thread-specific data destructor function. +.Xr pthread_key_delete 3 . +It is possible to call either function from +a thread-specific data destructor function. +Note however that this is not well defined for the +.Fn pthread_setspecific +function; +lost storage or infinite loops may occur. .Sh RETURN VALUES The .Fn pthread_getspecific @@ -96,13 +107,15 @@ function will return the thread-specific data value associated with the given If no thread-specific data value is associated with .Fa key , then the value NULL is returned. +If successful, the +.Fn pthread_setspecific +function will return zero. +Otherwise an error number will be returned to +indicate the error. .Sh ERRORS -None. +No errors are defined for either function. .Sh SEE ALSO -.Xr pthread_key_create 3 , -.Xr pthread_key_delete 3 , -.Xr pthread_setspecific 3 +.Xr pthread_key_create 3 .Sh STANDARDS -.Fn pthread_getspecific -conforms to -.St -p1003.1-96 . +These functions conform to +.St -p1003.1-2001 . diff --git a/lib/libpthread/pthread_key_create.3 b/lib/libpthread/pthread_key_create.3 index 894307c2cef..6dc0f9d0782 100644 --- a/lib/libpthread/pthread_key_create.3 +++ b/lib/libpthread/pthread_key_create.3 @@ -1,6 +1,6 @@ -.\" $NetBSD: pthread_key_create.3,v 1.4 2008/05/02 18:11:04 martin Exp $ +.\" $NetBSD: pthread_key_create.3,v 1.5 2010/07/09 08:22:04 jruoho Exp $ .\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. .\" All rights reserved. .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -55,46 +55,46 @@ .\" .\" $FreeBSD: src/lib/libpthread/man/pthread_key_create.3,v 1.12 2002/09/16 19:29:28 mini Exp $ .\" -.Dd January 30, 2003 +.Dd July 9, 2010 .Dt PTHREAD_KEY_CREATE 3 .Os .Sh NAME .Nm pthread_key_create -.Nd thread-specific data key creation +.Nd thread-specific data .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS .In pthread.h .Ft int .Fn pthread_key_create "pthread_key_t *key" "void (*destructor)(void *)" +.Ft int +.Fn pthread_key_delete "pthread_key_t key" .Sh DESCRIPTION The .Fn pthread_key_create function creates a thread-specific data key visible to all threads in the process. -Key values provided by -.Fn pthread_key_create -are opaque objects used to locate thread-specific data. -Although the same -key value may be used by different threads, the values bound to the key -by +Key values are opaque objects used to locate thread-specific data. +The same key value may be used by different threads, +but the values bound to the key by .Fn pthread_setspecific -are maintained on a per-thread basis and persist for the life of the calling -thread. +are maintained on a per-thread basis and +persist for the life of the calling thread. .Pp -Upon key creation, the value NULL is associated with the new key in all -active threads. -Upon thread creation, the value NULL is associated with all +Upon key creation, the value +.Dv NULL +is associated with the new key in all active threads. +Upon thread creation, the value +.Dv NULL +is associated with all defined keys in the new thread. .Pp An optional destructor function may be associated with each key value. -At -thread exit, if a key value has a non-NULL destructor pointer, and the +At thread exit, if a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated with the key, the function pointed to is called with the current associated value as its sole argument. -The -order of destructor calls is unspecified if more than one destructor exists -for a thread when it exits. +The order of destructor calls is unspecified if more +than one destructor exists for a thread when it exits. .Pp If, after all the destructors have been called for all non-NULL values with associated destructors, there are still some non-NULL values with @@ -104,17 +104,47 @@ If, after at least iterations of destructor calls for outstanding non-NULL values, there are still some non-NULL values with associated destructors, the implementation stops calling destructors. +.Pp +The +.Fn pthread_key_delete +function deletes a thread-specific data key previously returned by +.Fn pthread_key_create . +The thread-specific data values associated with +.Fa key +need not be NULL at the time of the call. +It is the responsibility of the application to free any +application storage or perform any cleanup actions for data structures +related to the deleted key or associated thread-specific data in any threads; +this cleanup can be done either before or after +.Fn pthread_key_delete +is called. +Any attempt to use +.Fa key +following the call to +.Fn pthread_key_delete +results in undefined behavior. +.Pp +The +.Fn pthread_key_delete +function itself is callable from within destructor functions, +but destructor functions are not invoked by the function. +Any destructor function that may have been associated with +.Fa key +will no longer be called upon thread exit. .Sh RETURN VALUES If successful, the .Fn pthread_key_create function will store the newly created key value at the location specified by .Fa key and returns zero. -Otherwise an error number will be returned to indicate -the error. +Also +.Fn pthread_key_delete +will return zero upon success. +Upon failure both functions return an error number to indicate the cause. .Sh ERRORS +The .Fn pthread_key_create -shall fail if: +may fail if: .Bl -tag -width Er .It Bq Er EAGAIN The system lacked the necessary resources to create another thread-specific @@ -124,11 +154,24 @@ would be exceeded. .It Bq Er ENOMEM Insufficient memory exists to create the key. .El +.Pp +The +.Fn pthread_key_delete +function may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa key +value is invalid. +.El .Sh SEE ALSO -.Xr pthread_getspecific 3 , -.Xr pthread_key_delete 3 , -.Xr pthread_setspecific 3 +.Xr pthread_getspecific 3 .Sh STANDARDS -.Fn pthread_key_create -conforms to -.St -p1003.1-96 . +These functions conform to +.St -p1003.1-2001 . +.Sh BUGS +The current specifications are flawed and +do not permit a clean implementation without potential problems. +The current implementation in +.Nx +addresses these problems by not supporting key reuse. diff --git a/lib/libpthread/pthread_key_delete.3 b/lib/libpthread/pthread_key_delete.3 deleted file mode 100644 index 70ec8ad2842..00000000000 --- a/lib/libpthread/pthread_key_delete.3 +++ /dev/null @@ -1,133 +0,0 @@ -.\" $NetBSD: pthread_key_delete.3,v 1.6 2008/05/02 18:11:04 martin Exp $ -.\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by John Birrell. -.\" 4. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD: src/lib/libpthread/man/pthread_key_delete.3,v 1.12 2002/09/16 19:29:28 mini Exp $ -.\" -.Dd January 30, 2003 -.Dt PTHREAD_KEY_DELETE 3 -.Os -.Sh NAME -.Nm pthread_key_delete -.Nd delete a thread-specific data key -.Sh LIBRARY -.Lb libpthread -.Sh SYNOPSIS -.In pthread.h -.Ft int -.Fn pthread_key_delete "pthread_key_t key" -.Sh DESCRIPTION -The -.Fn pthread_key_delete -function deletes a thread-specific data key previously returned by -.Fn pthread_key_create . -The thread-specific data values associated with -.Fa key -need not be NULL at the time that -.Fn pthread_key_delete -is called. -It is the responsibility of the application to free any -application storage or perform any cleanup actions for data structures -related to the deleted key or associated thread-specific data in any threads; -this cleanup can be done either before or after -.Fn pthread_key_delete -is called. -Any attempt to use -.Fa key -following the call to -.Fn pthread_key_delete -results in undefined behavior. -.Pp -The -.Fn pthread_key_delete -function is callable from within destructor functions. -Destructor functions -are not invoked by -.Fn pthread_key_delete . -Any destructor function that may have been associated with -.Fa key -will no longer be called upon thread exit. -.Sh RETURN VALUES -If successful, the -.Fn pthread_key_delete -function will return zero. -Otherwise an error number will be returned to -indicate the error. -.Sh ERRORS -.Fn pthread_key_delete -may fail if: -.Bl -tag -width Er -.It Bq Er EINVAL -The -.Fa key -value is invalid. -.El -.Sh SEE ALSO -.Xr pthread_getspecific 3 , -.Xr pthread_key_create 3 , -.Xr pthread_setspecific 3 -.Sh STANDARDS -.Fn pthread_key_delete -conforms to -.St -p1003.1-96 . -.Sh BUGS -The current specifications of -.Fn pthread_key_create -and -.Fn pthread_key_delete -are flawed and do not permit a clean implementation without -potential problems. -The current implementation of these functions -.Nx -in addresses these problems by not supporting key reuse. diff --git a/lib/libpthread/pthread_setspecific.3 b/lib/libpthread/pthread_setspecific.3 deleted file mode 100644 index b980f475d54..00000000000 --- a/lib/libpthread/pthread_setspecific.3 +++ /dev/null @@ -1,125 +0,0 @@ -.\" $NetBSD: pthread_setspecific.3,v 1.3 2008/05/02 18:11:04 martin Exp $ -.\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by John Birrell. -.\" 4. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD: src/lib/libpthread/man/pthread_setspecific.3,v 1.12 2002/09/16 19:29:29 mini Exp $ -.\" -.Dd January 30, 2003 -.Dt PTHREAD_SETSPECIFIC 3 -.Os -.Sh NAME -.Nm pthread_setspecific -.Nd set a thread-specific data value -.Sh LIBRARY -.Lb libpthread -.Sh SYNOPSIS -.In pthread.h -.Ft int -.Fn pthread_setspecific "pthread_key_t key" "const void *value" -.Sh DESCRIPTION -The -.Fn pthread_setspecific -function associates a thread-specific value with a -.Fa key -obtained via a previous call to -.Fn pthread_key_create . -Different threads have different values bound to each key. -These values are -typically pointers to blocks of dynamically allocated memory that have been -reserved for use by the calling thread. -.Pp -The effect of calling -.Fn pthread_setspecific -with a key value not obtained from -.Fn pthread_key_create -or after -.Fa key -has been deleted with -.Fn pthread_key_delete -is undefined. -.Pp -.Fn pthread_setspecific -may be called from a thread-specific data destructor function, however this -may result in lost storage or infinite loops. -.Sh RETURN VALUES -If successful, the -.Fn pthread_setspecific -function will return zero. -Otherwise an error number will be returned to -indicate the error. -.Sh ERRORS -.Fn pthread_setspecific -shall fail if: -.Bl -tag -width Er -.It Bq Er ENOMEM -Insufficient memory exists to associate the value with the -.Fa key . -.El -.Pp -.Fn pthread_setspecific -may fail if: -.Bl -tag -width Er -.It Bq Er EINVAL -The -.Fa key -value is invalid. -.El -.Sh SEE ALSO -.Xr pthread_getspecific 3 , -.Xr pthread_key_create 3 , -.Xr pthread_key_delete 3 -.Sh STANDARDS -.Fn pthread_setspecific -conforms to -.St -p1003.1-96 . |
