summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2004-06-07 21:11:24 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2004-06-07 21:11:24 +0000
commit768c8cdce4390df345d6498b2a3307d67a5749e7 (patch)
tree00a877e5acbe675ccad443ca71c778ca03852221 /lib
parentece2fea13db64b72fa79e093ca7679e7a491fdd3 (diff)
major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer needs pthread.h to compile. OK millert@, brad@, tedu@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/getgrent.c3
-rw-r--r--lib/libc/include/thread_private.h160
-rw-r--r--lib/libc/net/getaddrinfo.c4
-rw-r--r--lib/libc/net/getnameinfo.c4
-rw-r--r--lib/libc/net/res_init.c12
-rw-r--r--lib/libc/shlib_version2
-rw-r--r--lib/libc/stdio/flockfile.c15
-rw-r--r--lib/libc/sys/ftruncate.c4
-rw-r--r--lib/libc/sys/lseek.c4
-rw-r--r--lib/libc/thread/Makefile.inc4
-rw-r--r--lib/libc/thread/thread_fd.c9
-rw-r--r--lib/libc/thread/unithread_malloc_lock.c5
-rw-r--r--lib/libc/thread/unithread_storage.c40
-rw-r--r--lib/libc/thread/unithread_tag.c32
-rw-r--r--lib/libpthread/shlib_version2
-rw-r--r--lib/libpthread/thread/Makefile.inc4
-rw-r--r--lib/libpthread/thread/thread_storage.c82
-rw-r--r--lib/libpthread/thread/thread_tag.c120
-rw-r--r--lib/libpthread/uthread/pthread_private.h4
-rw-r--r--lib/libpthread/uthread/uthread_fd.c43
-rw-r--r--lib/libpthread/uthread/uthread_file.c13
-rw-r--r--lib/libpthread/uthread/uthread_init.c9
22 files changed, 275 insertions, 300 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 1d157d679e2..558aea40ff4 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -29,7 +29,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getgrent.c,v 1.20 2004/05/18 02:05:52 jfb Exp $";
+static char rcsid[] = "$OpenBSD: getgrent.c,v 1.21 2004/06/07 21:11:23 marc Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -59,7 +59,6 @@ static struct group_storage {
/* File pointers are locked with the 'gr' mutex */
_THREAD_PRIVATE_KEY(gr);
-_THREAD_PRIVATE_MUTEX(gr);
static FILE *_gr_fp;
static struct group _gr_group;
static int _gr_stayopen;
diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h
index 4212e7dcb2e..edac6b008d0 100644
--- a/lib/libc/include/thread_private.h
+++ b/lib/libc/include/thread_private.h
@@ -1,13 +1,19 @@
-/* $OpenBSD: thread_private.h,v 1.15 2003/01/28 04:58:00 marc Exp $ */
+/* $OpenBSD: thread_private.h,v 1.16 2004/06/07 21:11:23 marc Exp $ */
+
+/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
#ifndef _THREAD_PRIVATE_H_
#define _THREAD_PRIVATE_H_
-#include <pthread.h>
+/*
+ * This file defines the thread library interface to libc. Thread
+ * libraries must implement the functions described here for proper
+ * inter-operation with libc. libc contains weak versions of the
+ * described functions for operation in a non-threaded environment.
+ */
/*
- * This variable is initially 0 when there is exactly one thread.
- * It should never decrease.
+ * This variable is 0 until a second thread is created.
*/
extern int __isthreaded;
@@ -19,116 +25,102 @@ extern int __isthreaded;
* WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n,
* WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n).
*/
-#define WEAK_NAME(name) __CONCAT(_weak_,name)
-#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name))
+#define WEAK_NAME(name) __CONCAT(_weak_,name)
+#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name))
#ifdef __GNUC__
-#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name)
+#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name)
#else
-#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */
+#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */
#endif
/*
- * These macros help in making persistent storage thread-specific.
- * Libc makes extensive use of private static data structures
- * that hold state across function invocation, and these macros
- * are no-ops when running single-threaded.
- *
- * Linking against the user-thread library causes these macros to
- * allocate storage on a per-thread basis.
+ * helper macro to make unique names in the thread namespace
*/
-
-#define __THREAD_MUTEX_NAME(name) __CONCAT(_libc_storage_mutex_,name)
-#define __THREAD_KEY_NAME(name) __CONCAT(_libc_storage_key_,name)
-
-struct _thread_private_key_struct {
- pthread_once_t once;
- void (*cleanfn)(void *);
- pthread_key_t key;
-};
-
-void _libc_private_storage_lock(pthread_mutex_t *);
-void _libc_private_storage_unlock(pthread_mutex_t *);
-void * _libc_private_storage(volatile struct _thread_private_key_struct *,
- void *, size_t, void *);
-
-/* Declare a module mutex. */
-#define _THREAD_PRIVATE_MUTEX(name) \
- static pthread_mutex_t __THREAD_MUTEX_NAME(name) = \
- PTHREAD_MUTEX_INITIALIZER
-
-/* Lock a module mutex against use by any other threads. */
-#define _THREAD_PRIVATE_MUTEX_LOCK(name) \
- _libc_private_storage_lock(&__THREAD_MUTEX_NAME(name))
-
-/* Unlock a module mutex. */
-#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
- _libc_private_storage_unlock(&__THREAD_MUTEX_NAME(name))
-
-/* Declare a thread-private storage key. */
-#define _THREAD_PRIVATE_KEY(name) \
- static volatile struct _thread_private_key_struct \
- __THREAD_KEY_NAME(name) = { \
- PTHREAD_ONCE_INIT, \
- 0 \
- }
+#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name)
/*
- * In threaded mode, return a pointer to thread-private memory of
- * the same size as, and (initially) with the same contents as 'storage'. If
- * an error occurs, the 'error' parameter is returned.
- * In single-threaded mode, no storage is allocated. Instead, a pointer
- * to storage is always returned.
- * The 'cleanfn' function of the key structure is called to free the storage.
- * If 'cleanfn' is NULL, then free() is used. This hook can be useful for
- * getting rid of memory leaks.
+ * helper functions that exist as (weak) null functions in libc and
+ * (strong) functions in the thread library. These functions:
+ *
+ * _thread_tag_lock:
+ * lock the mutex associated with the given tag. If the given
+ * tag is NULL a tag is first allocated.
+ *
+ * _thread_tag_unlock:
+ * unlock the mutex associated with the given tag. If the given
+ * tag is NULL a tag is first allocated.
+ *
+ * _thread_tag_storage:
+ * return a pointer to per thread instance of data associated
+ * with the given tag. If the given tag is NULL a tag is first
+ * allocated.
*/
-#define _THREAD_PRIVATE(keyname, storage, error) \
- _libc_private_storage(&__THREAD_KEY_NAME(keyname), \
- &(storage), sizeof (storage), error)
+void _thread_tag_lock(void **);
+void _thread_tag_unlock(void **);
+void *_thread_tag_storage(void **, void *, size_t, void *);
/*
- * Keys used to access the per thread instances of resolver global data.
- * These are not static as they are referenced in several places.
+ * Macros used in libc to access thread mutex, keys, and per thread storage.
+ * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for
+ * historical reasons. They do the same thing, define a static variable
+ * keyed by 'name' that identifies a mutex and a key to identify per thread
+ * data.
*/
-extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res);
-#ifdef INET6
-extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext);
-#endif
+#define _THREAD_PRIVATE_KEY(name) \
+ static void *__THREAD_NAME(name)
+#define _THREAD_PRIVATE_MUTEX(name) \
+ static void *__THREAD_NAME(name)
+#define _THREAD_PRIVATE_MUTEX_LOCK(name) \
+ _thread_tag_lock(&(__THREAD_NAME(name)))
+#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
+ _thread_tag_unlock(&(__THREAD_NAME(name)))
+#define _THREAD_PRIVATE(keyname, storage, error) \
+ _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \
+ sizeof (storage), error)
+/*
+ * Resolver code is special cased in that it uses global keys.
+ */
+extern void *__THREAD_NAME(_res);
+extern void *__THREAD_NAME(_res_ext);
+extern void *__THREAD_NAME(serv_mutex);
/*
* File descriptor locking definitions.
*/
-#define FD_READ 0x1
-#define FD_WRITE 0x2
-#define FD_RDWR (FD_READ | FD_WRITE)
+#define FD_READ 0x1
+#define FD_WRITE 0x2
+#define FD_RDWR (FD_READ | FD_WRITE)
+
+int _thread_fd_lock(int, int, struct timespec *);
+void _thread_fd_unlock(int, int);
-#define _FD_LOCK(_fd,_type,_ts) \
- _thread_fd_lock(_fd, _type, _ts, __FILE__, __LINE__)
-#define _FD_UNLOCK(_fd,_type) \
- _thread_fd_unlock(_fd, _type, __FILE__, __LINE__)
+/*
+ * Macros are used in libc code for historical (debug) reasons.
+ * Define them here.
+ */
+#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
+#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
-int _thread_fd_lock(int, int, struct timespec *, const char *, int);
-void _thread_fd_unlock(int, int, const char *, int);
/*
- * malloc lock/unlock definitions
+ * malloc lock/unlock prototypes and definitions
*/
-# define _MALLOC_LOCK() do { \
+void _thread_malloc_init(void);
+void _thread_malloc_lock(void);
+void _thread_malloc_unlock(void);
+
+#define _MALLOC_LOCK() do { \
if (__isthreaded) \
_thread_malloc_lock(); \
} while (0)
-# define _MALLOC_UNLOCK() do { \
+#define _MALLOC_UNLOCK() do { \
if (__isthreaded) \
_thread_malloc_unlock();\
} while (0)
-# define _MALLOC_LOCK_INIT()do { \
+#define _MALLOC_LOCK_INIT() do { \
if (__isthreaded) \
_thread_malloc_init();\
} while (0)
-void _thread_malloc_init(void);
-void _thread_malloc_lock(void);
-void _thread_malloc_unlock(void);
-
#endif /* _THREAD_PRIVATE_H_ */
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 8fb8975ad83..3db8cc82ee9 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getaddrinfo.c,v 1.49 2004/04/14 07:06:15 itojun Exp $ */
+/* $OpenBSD: getaddrinfo.c,v 1.50 2004/06/07 21:11:23 marc Exp $ */
/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
/*
@@ -873,7 +873,7 @@ get_port(ai, servname, matchonly)
int port;
int allownumeric;
/* mutex is defined in getnameinfo.c */
- extern pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex);
+ extern void *__THREAD_NAME(serv_mutex);
if (servname == NULL)
return 0;
diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c
index da5df507ab0..62760e178da 100644
--- a/lib/libc/net/getnameinfo.c
+++ b/lib/libc/net/getnameinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getnameinfo.c,v 1.27 2003/07/21 23:17:53 marc Exp $ */
+/* $OpenBSD: getnameinfo.c,v 1.28 2004/06/07 21:11:23 marc Exp $ */
/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
/*
@@ -91,7 +91,7 @@ static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int);
/*
* this mutex is also used by get_port in getaddrinfo.c
*/
-pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex) = PTHREAD_MUTEX_INITIALIZER;
+void *__THREAD_NAME(serv_mutex);
int
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c
index 9c739588836..79ccada6eeb 100644
--- a/lib/libc/net/res_init.c
+++ b/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $ */
+/* $OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $ */
/*
* ++Copyright++ 1985, 1989, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $";
+static char rcsid[] = "$OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -118,9 +118,7 @@ static u_int32_t net_mask(struct in_addr);
/*
* Resolver state default settings.
*/
-volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res) = {
- PTHREAD_ONCE_INIT, 0
-};
+void *__THREAD_NAME(_res);
struct __res_state _res
# if defined(__BIND_RES_TEXT)
@@ -128,9 +126,7 @@ struct __res_state _res
# endif
;
#ifdef INET6
-volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext) = {
- PTHREAD_ONCE_INIT, 0
-};
+void *__THREAD_NAME(_res_ext);
struct __res_state_ext _res_ext;
#endif /* INET6 */
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 59270a5cade..785601b1fd8 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,2 +1,2 @@
-major=31
+major=32
minor=0 # note: remember to update minor in ../libpthread/shlib_version
diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c
index e0963391596..35cadb38284 100644
--- a/lib/libc/stdio/flockfile.c
+++ b/lib/libc/stdio/flockfile.c
@@ -1,5 +1,6 @@
-/* $OpenBSD: flockfile.c,v 1.5 2001/09/04 22:17:45 fgsch Exp $ */
+/* $OpenBSD: flockfile.c,v 1.6 2004/06/07 21:11:23 marc Exp $ */
+#include <sys/time.h>
#include <stdio.h>
#include "thread_private.h"
@@ -12,17 +13,14 @@
#undef flockfile
#undef ftrylockfile
#undef funlockfile
-#undef _flockfile_debug
WEAK_PROTOTYPE(flockfile);
WEAK_PROTOTYPE(ftrylockfile);
WEAK_PROTOTYPE(funlockfile);
-WEAK_PROTOTYPE(_flockfile_debug);
WEAK_ALIAS(flockfile);
WEAK_ALIAS(ftrylockfile);
WEAK_ALIAS(funlockfile);
-WEAK_ALIAS(_flockfile_debug);
void
WEAK_NAME(flockfile)(fp)
@@ -44,12 +42,3 @@ WEAK_NAME(funlockfile)(fp)
FILE * fp;
{
}
-
-void
-WEAK_NAME(_flockfile_debug)(fp, fname, lineno)
- FILE * fp;
- char * fname;
- int lineno;
-{
-}
-
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c
index 8d95281064e..47670e5248d 100644
--- a/lib/libc/sys/ftruncate.c
+++ b/lib/libc/sys/ftruncate.c
@@ -28,11 +28,13 @@
*/
#if defined(SYSLIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: ftruncate.c,v 1.11 2003/06/11 21:03:10 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ftruncate.c,v 1.12 2004/06/07 21:11:23 marc Exp $";
#endif /* SYSLIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/syscall.h>
+#include <sys/time.h>
+#include <unistd.h>
#include "thread_private.h"
#ifdef lint
diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c
index d811ce9b8ae..b5c629e1b89 100644
--- a/lib/libc/sys/lseek.c
+++ b/lib/libc/sys/lseek.c
@@ -28,11 +28,13 @@
*/
#if defined(SYSLIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: lseek.c,v 1.10 2003/06/11 21:03:10 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: lseek.c,v 1.11 2004/06/07 21:11:23 marc Exp $";
#endif /* SYSLIBC_SCCS and not lint */
#include <sys/types.h>
+#include <sys/time.h>
#include <sys/syscall.h>
+#include <unistd.h>
#include "thread_private.h"
/*
diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc
index 356bf1a3cc9..9d323879900 100644
--- a/lib/libc/thread/Makefile.inc
+++ b/lib/libc/thread/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.5 2002/11/05 22:19:55 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $
.PATH: ${LIBCSRCDIR}/thread
-SRCS+= thread_fd.c unithread_storage.c unithread_malloc_lock.c
+SRCS+= thread_fd.c unithread_malloc_lock.c unithread_tag.c
diff --git a/lib/libc/thread/thread_fd.c b/lib/libc/thread/thread_fd.c
index f2a9ae2290b..9f10fedf837 100644
--- a/lib/libc/thread/thread_fd.c
+++ b/lib/libc/thread/thread_fd.c
@@ -1,7 +1,6 @@
-/* $OpenBSD: thread_fd.c,v 1.7 2002/11/05 22:19:55 marc Exp $ */
+/* $OpenBSD: thread_fd.c,v 1.8 2004/06/07 21:11:23 marc Exp $ */
#include <sys/time.h>
-#include <pthread.h>
#include "thread_private.h"
WEAK_PROTOTYPE(_thread_fd_lock);
@@ -11,15 +10,13 @@ WEAK_ALIAS(_thread_fd_lock);
WEAK_ALIAS(_thread_fd_unlock);
int
-WEAK_NAME(_thread_fd_lock)(int fd, int lock_type, struct timespec *timeout,
- const char *fname, int lineno)
+WEAK_NAME(_thread_fd_lock)(int fd, int lock_type, struct timespec *timeout)
{
return 0;
}
void
-WEAK_NAME(_thread_fd_unlock)(int fd, int lock_type, const char *fname,
- int lineno)
+WEAK_NAME(_thread_fd_unlock)(int fd, int lock_type)
{
}
diff --git a/lib/libc/thread/unithread_malloc_lock.c b/lib/libc/thread/unithread_malloc_lock.c
index 74855be7821..2c195a9a95c 100644
--- a/lib/libc/thread/unithread_malloc_lock.c
+++ b/lib/libc/thread/unithread_malloc_lock.c
@@ -1,7 +1,6 @@
-/* $OpenBSD: unithread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */
+/* $OpenBSD: unithread_malloc_lock.c,v 1.5 2004/06/07 21:11:23 marc Exp $ */
-#include <sys/cdefs.h>
-#include <pthread.h>
+#include <sys/time.h>
#include "thread_private.h"
WEAK_PROTOTYPE(_thread_malloc_lock);
diff --git a/lib/libc/thread/unithread_storage.c b/lib/libc/thread/unithread_storage.c
deleted file mode 100644
index 456082a8a2b..00000000000
--- a/lib/libc/thread/unithread_storage.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* $OpenBSD: unithread_storage.c,v 1.1 2000/01/06 15:07:06 d Exp $ */
-/*
- *
- */
-/* unthreaded storage allocation helper functions */
-
-#include <sys/cdefs.h>
-#include <pthread.h>
-#include "thread_private.h"
-
-WEAK_PROTOTYPE(_libc_private_storage_lock);
-WEAK_PROTOTYPE(_libc_private_storage_unlock);
-WEAK_PROTOTYPE(_libc_private_storage);
-
-WEAK_ALIAS(_libc_private_storage_lock);
-WEAK_ALIAS(_libc_private_storage_unlock);
-WEAK_ALIAS(_libc_private_storage);
-
-void
-WEAK_NAME(_libc_private_storage_lock)(mutex)
- pthread_mutex_t *mutex;
-{
-}
-
-void
-WEAK_NAME(_libc_private_storage_unlock)(mutex)
- pthread_mutex_t *mutex;
-{
-}
-
-void *
-WEAK_NAME(_libc_private_storage)(key, init, initsz, error)
- volatile struct _thread_private_key_struct * key;
- void *init;
- size_t initsz;
- void *error;
-{
-
- return init;
-}
diff --git a/lib/libc/thread/unithread_tag.c b/lib/libc/thread/unithread_tag.c
new file mode 100644
index 00000000000..c7ac928b994
--- /dev/null
+++ b/lib/libc/thread/unithread_tag.c
@@ -0,0 +1,32 @@
+/* $OpenBSD: unithread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */
+
+/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
+
+#include <sys/time.h>
+#include "thread_private.h"
+
+WEAK_PROTOTYPE(_thread_tag_lock);
+WEAK_PROTOTYPE(_thread_tag_unlock);
+WEAK_PROTOTYPE(_thread_tag_storage);
+
+WEAK_ALIAS(_thread_tag_lock);
+WEAK_ALIAS(_thread_tag_unlock);
+WEAK_ALIAS(_thread_tag_storage);
+
+void
+WEAK_NAME(_thread_tag_lock)(void **tag)
+{
+ return;
+}
+
+void
+WEAK_NAME(_thread_tag_unlock)(void **tag)
+{
+ return;
+}
+
+void *
+WEAK_NAME(_thread_tag_storage)(void **tag, void *init, size_t initsz, void *err)
+{
+ return init;
+}
diff --git a/lib/libpthread/shlib_version b/lib/libpthread/shlib_version
index 012c14171d3..d9961ea9fef 100644
--- a/lib/libpthread/shlib_version
+++ b/lib/libpthread/shlib_version
@@ -1,2 +1,2 @@
-major=3
+major=4
minor=0
diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc
index 074139f176b..2545995b494 100644
--- a/lib/libpthread/thread/Makefile.inc
+++ b/lib/libpthread/thread/Makefile.inc
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.5 2003/01/20 18:12:11 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $
.PATH: ${SRCDIR}/thread
-SRCS+= thread_storage.c thread_malloc_lock.c
+SRCS+= thread_tag.c thread_malloc_lock.c
diff --git a/lib/libpthread/thread/thread_storage.c b/lib/libpthread/thread/thread_storage.c
deleted file mode 100644
index 61609f9c277..00000000000
--- a/lib/libpthread/thread/thread_storage.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $OpenBSD: thread_storage.c,v 1.6 2002/11/05 22:19:55 marc Exp $ */
-/* Public Domain */
-
-/*
- * libpthread's stronger functions
- */
-
-#include <stdlib.h>
-#include <pthread.h>
-#include <string.h>
-#include "pthread_private.h"
-
-void
-_libc_private_storage_lock(mutex)
- pthread_mutex_t *mutex;
-{
- if (__isthreaded && pthread_mutex_lock(mutex) != 0)
- PANIC("_libc_private_storage_lock");
-}
-
-void
-_libc_private_storage_unlock(mutex)
- pthread_mutex_t *mutex;
-{
- if (__isthreaded && pthread_mutex_unlock(mutex) != 0)
- PANIC("_libc_private_storage_unlock");
-}
-
-void *
-_libc_private_storage(volkey, init, initsz, error)
- volatile struct _thread_private_key_struct * volkey;
- void * init;
- size_t initsz;
- void * error;
-{
- void *result;
- void (*cleanfn)(void *);
- struct _thread_private_key_struct * key;
-
- /* Use static storage while not threaded: */
- if (!__isthreaded)
- return init;
-
- key = (struct _thread_private_key_struct *)volkey; /* for gcc */
-
- /* Create the key once: */
- if (volkey->once.state == PTHREAD_NEEDS_INIT) {
- if (pthread_mutex_lock(&key->once.mutex) != 0)
- return error;
- if (volkey->once.state == PTHREAD_NEEDS_INIT) {
- if (key->cleanfn == NULL)
- cleanfn = free;
- else
- cleanfn = key->cleanfn;
- if (pthread_key_create(&key->key, cleanfn) != 0) {
- pthread_mutex_unlock(&key->once.mutex);
- return error;
- }
- key->once.state = PTHREAD_DONE_INIT;
- }
- pthread_mutex_unlock(&key->once.mutex);
- }
-
- /* XXX signals may cause re-entrancy here? */
-
- /* Acquire this key's thread-specific storage: */
- result = pthread_getspecific(key->key);
-
- /* Allocate and initialise storage if unallocated: */
- if (result == NULL) {
- result = malloc(initsz);
- if (result == NULL)
- return error;
- if (pthread_setspecific(key->key, result) != 0) {
- free(result);
- return error;
- }
- memcpy(result, init, initsz);
- }
-
- return result;
-}
diff --git a/lib/libpthread/thread/thread_tag.c b/lib/libpthread/thread/thread_tag.c
new file mode 100644
index 00000000000..43bd4c14b0e
--- /dev/null
+++ b/lib/libpthread/thread/thread_tag.c
@@ -0,0 +1,120 @@
+/* $OpenBSD: thread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */
+
+/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
+
+#include <sys/time.h>
+
+#include <stdlib.h>
+
+#include "thread_private.h"
+#include "pthread.h"
+#include "pthread_private.h"
+
+/*
+ * A thread tag is a pointer to a structure of this time. An opaque
+ * tag is used to decouple libc from the thread library.
+ */
+struct _thread_tag {
+ pthread_mutex_t m; /* the tag's mutex */
+ pthread_key_t k; /* a key for private data */
+};
+
+/*
+ * local mutex to protect against tag creation races.
+ */
+static pthread_mutex_t _thread_tag_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/*
+ * Initialize a thread tag structure once. This function is called
+ * if the tag is null. Allocation and initialization are controlled
+ * by a mutex. If the tag is not null when the mutex is obtained
+ * the caller lost a race -- some other thread initialized the tag.
+ * This function will never return NULL.
+ */
+static void
+_thread_tag_init(void **tag)
+{
+ struct _thread_tag *tt;
+ int result;
+
+ result = pthread_mutex_lock(&_thread_tag_mutex);
+ if (result == 0) {
+ if (*tag == NULL) {
+ tt = malloc(sizeof *tt);
+ if (tt != NULL) {
+ result = pthread_mutex_init(&tt->m, NULL);
+ result |= pthread_key_create(&tt->k, free);
+ *tag = tt;
+ }
+ }
+ result |= pthread_mutex_unlock(&_thread_tag_mutex);
+ }
+ if (result != 0)
+ PANIC(__func__);
+}
+
+/*
+ * lock the mutex associated with the given tag
+ */
+void
+_thread_tag_lock(void **tag)
+{
+ struct _thread_tag *tt;
+
+ if (__isthreaded) {
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+ if (pthread_mutex_lock(&tt->m) != 0)
+ PANIC(__func__);
+ }
+}
+
+/*
+ * unlock the mutex associated with the given tag
+ */
+void
+_thread_tag_unlock(void **tag)
+{
+ struct _thread_tag *tt;
+
+ if (__isthreaded) {
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+ if (pthread_mutex_unlock(&tt->m) != 0)
+ PANIC(__func__);
+ }
+}
+
+/*
+ * return the thread specific data for the given tag. If there
+ * is no date for this thread initialize it from 'storage'.
+ * On any error return 'err'.
+ */
+void *
+_thread_tag_storage(void **tag, void *storage, size_t sz, void *err)
+{
+ struct _thread_tag *tt;
+ void *ret;
+
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+
+ ret = pthread_getspecific(tt->k);
+ if (ret == NULL) {
+ ret = malloc(sz);
+ if (ret == NULL)
+ ret = err;
+ else {
+ if (pthread_setspecific(tt->k, ret) == 0)
+ memcpy(ret, storage, sz);
+ else {
+ free(ret);
+ ret = err;
+ }
+ }
+ }
+ return ret;
+}
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index afafee5e642..aef55382c95 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.52 2004/02/01 06:22:14 brad Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.53 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -1117,7 +1117,7 @@ int _thread_fd_table_init(int);
int _thread_fd_table_dup(int, int);
void _thread_fd_table_remove(int);
void _thread_fd_unlock_owned(pthread_t);
-void _thread_fd_unlock_thread(struct pthread *, int, int, const char *, int);
+void _thread_fd_unlock_thread(struct pthread *, int, int);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
void _thread_leave_cancellation_point(void);
diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c
index ac81f56e1f1..a32a09c07e9 100644
--- a/lib/libpthread/uthread/uthread_fd.c
+++ b/lib/libpthread/uthread/uthread_fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fd.c,v 1.21 2003/02/14 03:58:42 marc Exp $ */
+/* $OpenBSD: uthread_fd.c,v 1.22 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -275,8 +275,7 @@ _thread_fd_table_remove(int fd)
* Unlock the fd table entry for a given thread, fd, and lock type.
*/
void
-_thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
- const char *fname, int lineno)
+_thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type)
{
struct fd_table_entry *entry;
int ret;
@@ -300,10 +299,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
* other threads for clashing with the current
* thread's accesses:
*/
- if (fname)
- _spinlock_debug(&entry->lock, (char *)fname, lineno);
- else
- _SPINLOCK(&entry->lock);
+ _SPINLOCK(&entry->lock);
/* Check if the running thread owns the read lock: */
if (entry->r_owner == thread &&
@@ -393,14 +389,13 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
}
/*
- * Unlock an fd table entry for the given fd and lock type. Save
- * fname and lineno (debug variables).
+ * Unlock an fd table entry for the given fd and lock type.
*/
void
-_thread_fd_unlock(int fd, int lock_type, const char *fname, int lineno)
+_thread_fd_unlock(int fd, int lock_type)
{
struct pthread *curthread = _get_curthread();
- _thread_fd_unlock_thread(curthread, fd, lock_type, fname, lineno);
+ _thread_fd_unlock_thread(curthread, fd, lock_type);
}
/*
@@ -429,20 +424,16 @@ _thread_fd_unlock_owned(pthread_t pthread)
}
_SPINUNLOCK(&entry->lock);
if (do_unlock)
- _thread_fd_unlock_thread(pthread, fd, FD_RDWR,
- __FILE__, __LINE__);
+ _thread_fd_unlock_thread(pthread, fd, FD_RDWR);
}
}
}
/*
- * Lock an fd table entry for the given fd and lock type. Save
- * fname and lineno (debug variables). The debug variables may be
- * null when called by the non-debug version of the function.
+ * Lock an fd table entry for the given fd and lock type.
*/
int
-_thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
- const char *fname, int lineno)
+_thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
{
struct pthread *curthread = _get_curthread();
struct fd_table_entry *entry;
@@ -461,11 +452,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* other threads for clashing with the current
* thread's accesses:
*/
- if (fname)
- _spinlock_debug(&entry->lock, (char *)fname, lineno);
- else
- _SPINLOCK(&entry->lock);
-
+ _SPINLOCK(&entry->lock);
/* Handle read locks */
if (lock_type == FD_READ || lock_type == FD_RDWR) {
/*
@@ -493,9 +480,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* running thread:
*/
curthread->data.fd.fd = fd;
- curthread->data.fd.branch = lineno;
- curthread->data.fd.fname =
- (char *)fname;
/* Set the timeout: */
_thread_kern_set_timeout(timeout);
@@ -536,8 +520,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* this file descriptor:
*/
entry->r_lockcount = 0;
- entry->r_fname = fname;
- entry->r_lineno = lineno;
}
}
@@ -573,9 +555,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* running thread:
*/
curthread->data.fd.fd = fd;
- curthread->data.fd.branch = lineno;
- curthread->data.fd.fname =
- (char *)fname;
/* Set the timeout: */
_thread_kern_set_timeout(timeout);
@@ -615,8 +594,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* for this file descriptor:
*/
entry->w_lockcount = 0;
- entry->w_fname = fname;
- entry->w_lineno = lineno;
}
}
diff --git a/lib/libpthread/uthread/uthread_file.c b/lib/libpthread/uthread/uthread_file.c
index b50174c0d2b..71c0ffc35aa 100644
--- a/lib/libpthread/uthread/uthread_file.c
+++ b/lib/libpthread/uthread/uthread_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_file.c,v 1.10 2003/01/31 04:46:17 marc Exp $ */
+/* $OpenBSD: uthread_file.c,v 1.11 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -173,7 +173,7 @@ do_lock(int idx, FILE *fp)
}
void
-_flockfile_debug(FILE * fp, char *fname, int lineno)
+flockfile(FILE * fp)
{
int idx = file_idx(fp);
struct file_lock *p;
@@ -230,19 +230,12 @@ _flockfile_debug(FILE * fp, char *fname, int lineno)
_SPINUNLOCK(&hash_lock);
/* Wait on the FILE lock: */
- _thread_kern_sched_state(PS_FILE_WAIT, fname, lineno);
+ _thread_kern_sched_state(PS_FILE_WAIT, "", 0);
}
}
return;
}
-void
-flockfile(FILE * fp)
-{
- _flockfile_debug(fp, (char *) "?", 1);
- return;
-}
-
int
ftrylockfile(FILE * fp)
{
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 6a1833039e2..531753880e6 100644
--- a/lib/libpthread/uthread/uthread_init.c
+++ b/lib/libpthread/uthread/uthread_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_init.c,v 1.31 2004/01/15 22:22:12 marc Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.32 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -134,11 +134,10 @@ static void *references[] = {
&_thread_malloc_init,
&_thread_malloc_lock,
&_thread_malloc_unlock,
- &_libc_private_storage,
- &_libc_private_storage_lock,
- &_libc_private_storage_unlock,
+ &_thread_tag_lock,
+ &_thread_tag_unlock,
+ &_thread_tag_storage,
&flockfile,
- &_flockfile_debug,
&ftrylockfile,
&funlockfile
};