summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dirent.h3
-rw-r--r--lib/libc/gen/closedir.c12
-rw-r--r--lib/libc/gen/opendir.c3
-rw-r--r--lib/libc/gen/readdir.c32
-rw-r--r--lib/libc/gen/seekdir.c6
-rw-r--r--lib/libc/gen/telldir.c13
-rw-r--r--lib/libc/include/thread_private.h56
-rw-r--r--lib/libc/shlib_version4
-rw-r--r--lib/libc/sys/ftruncate.c21
-rw-r--r--lib/libc/sys/lseek.c21
-rw-r--r--lib/libc/thread/Makefile.inc4
-rw-r--r--lib/libc/thread/thread_fd.c22
-rw-r--r--lib/libc/thread/unithread_mutex.c49
-rw-r--r--lib/libpthread/shlib_version2
-rw-r--r--lib/libpthread/thread/Makefile.inc4
-rw-r--r--lib/libpthread/thread/thread_mutex.c49
-rw-r--r--lib/libpthread/uthread/Makefile.inc4
-rw-r--r--lib/libpthread/uthread/pthread_private.h13
-rw-r--r--lib/libpthread/uthread/uthread_ftruncate.c57
-rw-r--r--lib/libpthread/uthread/uthread_init.c11
-rw-r--r--lib/libpthread/uthread/uthread_lseek.c56
-rw-r--r--lib/libpthread/uthread/uthread_mutex.c6
-rw-r--r--lib/librthread/rthread_libc.c29
-rw-r--r--lib/librthread/rthread_sync.c8
24 files changed, 373 insertions, 112 deletions
diff --git a/include/dirent.h b/include/dirent.h
index 7565be1ca7d..20765d01c44 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dirent.h,v 1.17 2007/02/08 16:34:38 millert Exp $ */
+/* $OpenBSD: dirent.h,v 1.18 2007/06/05 18:11:48 kurt Exp $ */
/* $NetBSD: dirent.h,v 1.9 1995/03/26 20:13:37 jtc Exp $ */
/*-
@@ -71,6 +71,7 @@ typedef struct _dirdesc {
long dd_rewind; /* magic cookie for rewinding */
int dd_flags; /* flags for readdir */
struct _telldir *dd_td; /* telldir position recording */
+ void *dd_lock; /* mutex to protect struct */
} DIR;
#define dirfd(dirp) ((dirp)->dd_fd)
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index 7315bcc1e41..48d2775d7ea 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: closedir.c,v 1.7 2006/04/01 18:06:59 otto Exp $ */
+/* $OpenBSD: closedir.c,v 1.8 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1983, 1993
* Regents of the University of California. All rights reserved.
@@ -42,17 +42,15 @@ int
closedir(DIR *dirp)
{
int fd;
- int ret;
- if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
- return (ret);
+ _MUTEX_LOCK(&dirp->dd_lock);
fd = dirp->dd_fd;
dirp->dd_fd = -1;
dirp->dd_loc = 0;
free(dirp->dd_td->td_locs);
free(dirp->dd_buf);
+ _MUTEX_UNLOCK(&dirp->dd_lock);
+ _MUTEX_DESTROY(&dirp->dd_lock);
free(dirp);
- ret = close(fd);
- _FD_UNLOCK(fd, FD_READ);
- return (ret);
+ return (close(fd));
}
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 065c1aa9411..4028ba9c1eb 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: opendir.c,v 1.18 2007/02/09 14:58:09 millert Exp $ */
+/* $OpenBSD: opendir.c,v 1.19 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -97,6 +97,7 @@ __opendir2(const char *name, int flags)
dirp->dd_loc = 0;
dirp->dd_fd = fd;
dirp->dd_flags = flags;
+ dirp->dd_lock = NULL;
/*
* Set up seek point for rewinddir.
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index b028c822396..5f4c447e576 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readdir.c,v 1.11 2007/02/08 16:34:39 millert Exp $ */
+/* $OpenBSD: readdir.c,v 1.12 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -38,7 +38,7 @@
* get next entry in a directory.
*/
struct dirent *
-readdir(DIR *dirp)
+_readdir_unlocked(DIR *dirp)
{
struct dirent *dp;
@@ -65,28 +65,34 @@ readdir(DIR *dirp)
}
}
+struct dirent *
+readdir(DIR *dirp)
+{
+ struct dirent *dp;
+
+ _MUTEX_LOCK(&dirp->dd_lock);
+ dp = _readdir_unlocked(dirp);
+ _MUTEX_UNLOCK(&dirp->dd_lock);
+
+ return (dp);
+}
+
int
readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
{
struct dirent *dp;
- int ret;
- if (dirp->dd_fd < 0) {
- return EBADF;
- }
- if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
- return ret;
- errno = 0;
- dp = readdir(dirp);
+ _MUTEX_LOCK(&dirp->dd_lock);
+ dp = _readdir_unlocked(dirp);
if (dp == NULL && errno != 0) {
- _FD_UNLOCK(dirp->dd_fd, FD_READ);
+ _MUTEX_UNLOCK(&dirp->dd_lock);
return errno;
}
if (dp != NULL)
memcpy(entry, dp, sizeof (struct dirent) - MAXNAMLEN + dp->d_namlen);
- _FD_UNLOCK(dirp->dd_fd, FD_READ);
+ _MUTEX_UNLOCK(&dirp->dd_lock);
if (dp != NULL)
- *result = entry;
+ *result = entry;
else
*result = NULL;
return 0;
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index e472f62b789..2affbdd1ef1 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: seekdir.c,v 1.8 2006/04/01 18:06:59 otto Exp $ */
+/* $OpenBSD: seekdir.c,v 1.9 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <dirent.h>
+#include "thread_private.h"
#include "telldir.h"
/*
@@ -39,6 +40,7 @@
void
seekdir(DIR *dirp, long loc)
{
-
+ _MUTEX_LOCK(&dirp->dd_lock);
__seekdir(dirp, loc);
+ _MUTEX_UNLOCK(&dirp->dd_lock);
}
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index 708b923f3a0..1314397ce93 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: telldir.c,v 1.9 2006/04/10 12:04:20 otto Exp $ */
+/* $OpenBSD: telldir.c,v 1.10 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <unistd.h>
+#include "thread_private.h"
#include "telldir.h"
/*
@@ -42,9 +43,11 @@
long
telldir(DIR *dirp)
{
- long i = dirp->dd_td->td_last;
+ long i;
struct ddloc *lp;
+ _MUTEX_LOCK(&dirp->dd_lock);
+ i = dirp->dd_td->td_last;
lp = &dirp->dd_td->td_locs[i];
/* return previous telldir, if there */
@@ -52,6 +55,7 @@ telldir(DIR *dirp)
if (lp->loc_seek == dirp->dd_seek &&
lp->loc_loc == dirp->dd_loc) {
dirp->dd_td->td_last = i;
+ _MUTEX_UNLOCK(&dirp->dd_lock);
return (i);
}
}
@@ -60,8 +64,10 @@ telldir(DIR *dirp)
size_t newsz = dirp->dd_td->td_sz * 2 + 1;
struct ddloc *p;
p = realloc(dirp->dd_td->td_locs, newsz * sizeof(*p));
- if (p == NULL)
+ if (p == NULL) {
+ _MUTEX_UNLOCK(&dirp->dd_lock);
return (-1);
+ }
dirp->dd_td->td_sz = newsz;
dirp->dd_td->td_locs = p;
lp = &dirp->dd_td->td_locs[i];
@@ -70,6 +76,7 @@ telldir(DIR *dirp)
lp->loc_seek = dirp->dd_seek;
lp->loc_loc = dirp->dd_loc;
dirp->dd_td->td_last = i;
+ _MUTEX_UNLOCK(&dirp->dd_lock);
return (i);
}
diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h
index c5acc4b5e43..a365c25e66a 100644
--- a/lib/libc/include/thread_private.h
+++ b/lib/libc/include/thread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: thread_private.h,v 1.19 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: thread_private.h,v 1.20 2007/06/05 18:11:48 kurt Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
@@ -54,10 +54,24 @@ extern int __isthreaded;
* 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.
+ *
+ * _thread_mutex_lock:
+ * lock the given mutex. If the given mutex is NULL,
+ * rely on rthreads/pthreads implementation to initialize
+ * the mutex before locking.
+ *
+ * _thread_mutex_unlock:
+ * unlock the given mutex.
+ *
+ * _thread_mutex_destroy:
+ * destroy the given mutex.
*/
void _thread_tag_lock(void **);
void _thread_tag_unlock(void **);
void *_thread_tag_storage(void **, void *, size_t, void *);
+void _thread_mutex_lock(void **);
+void _thread_mutex_unlock(void **);
+void _thread_mutex_destroy(void **);
/*
* Macros used in libc to access thread mutex, keys, and per thread storage.
@@ -77,32 +91,32 @@ void *_thread_tag_storage(void **, void *, size_t, void *);
#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.
+ * Macros used in libc to access non-static mutexes.
*/
-#define FD_READ 0x1
-#define FD_WRITE 0x2
-#define FD_RDWR (FD_READ | FD_WRITE)
-#define FD_RDWR_CLOSE (FD_RDWR | 0x4)
-
-struct timespec;
-int _thread_fd_lock(int, int, struct timespec *);
-void _thread_fd_unlock(int, int);
+#define _MUTEX_LOCK(mutex) \
+ do { \
+ if (__isthreaded) \
+ _thread_mutex_lock(mutex); \
+ } while (0)
+#define _MUTEX_UNLOCK(mutex) \
+ do { \
+ if (__isthreaded) \
+ _thread_mutex_unlock(mutex); \
+ } while (0)
+#define _MUTEX_DESTROY(mutex) \
+ do { \
+ if (__isthreaded) \
+ _thread_mutex_destroy(mutex); \
+ } while (0)
/*
- * Macros are used in libc code for historical (debug) reasons.
- * Define them here.
+ * Resolver code is special cased in that it uses global keys.
*/
-#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
-#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
-
+extern void *__THREAD_NAME(_res);
+extern void *__THREAD_NAME(_res_ext);
+extern void *__THREAD_NAME(serv_mutex);
/*
* malloc lock/unlock prototypes and definitions
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index acb4851773e..2041edd3fce 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
-major=40
-minor=3
+major=41
+minor=0
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then libpthread must also be updated.
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c
index c1722580859..d0f5e9837c4 100644
--- a/lib/libc/sys/ftruncate.c
+++ b/lib/libc/sys/ftruncate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftruncate.c,v 1.14 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: ftruncate.c,v 1.15 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,27 +28,24 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include "thread_private.h"
register_t __syscall(quad_t, ...);
+/* ftruncate is weak to support libpthread locking */
+
+WEAK_PROTOTYPE(ftruncate);
+
+WEAK_ALIAS(ftruncate);
+
/*
* This function provides 64-bit offset padding that
* is not supplied by GCC 1.X but is supplied by GCC 2.X.
*/
int
-ftruncate(int fd, off_t length)
+WEAK_NAME(ftruncate)(int fd, off_t length)
{
- int retval;
-
- if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) {
- retval = -1;
- } else {
- retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length);
- _FD_UNLOCK(fd, FD_RDWR);
- }
- return retval;
+ return (__syscall((quad_t)SYS_ftruncate, fd, 0, length));
}
diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c
index f9e9ef98aa3..1abb688a348 100644
--- a/lib/libc/sys/lseek.c
+++ b/lib/libc/sys/lseek.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lseek.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: lseek.c,v 1.14 2007/06/05 18:11:48 kurt Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,27 +28,24 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include "thread_private.h"
off_t __syscall(quad_t, ...);
+/* lseek is weak to support libpthread locking */
+
+WEAK_PROTOTYPE(lseek);
+
+WEAK_ALIAS(lseek);
+
/*
* This function provides 64-bit offset padding that
* is not supplied by GCC 1.X but is supplied by GCC 2.X.
*/
off_t
-lseek(int fd, off_t offset, int whence)
+WEAK_NAME(lseek)(int fd, off_t offset, int whence)
{
- off_t retval;
-
- if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) {
- retval = -1;
- } else {
- retval = __syscall((quad_t)SYS_lseek, fd, 0, offset, whence);
- _FD_UNLOCK(fd, FD_RDWR);
- }
- return retval;
+ return (__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
}
diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc
index 9d323879900..6d4c1cacdf6 100644
--- a/lib/libc/thread/Makefile.inc
+++ b/lib/libc/thread/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2007/06/05 18:11:48 kurt Exp $
.PATH: ${LIBCSRCDIR}/thread
-SRCS+= thread_fd.c unithread_malloc_lock.c unithread_tag.c
+SRCS+= unithread_malloc_lock.c unithread_mutex.c unithread_tag.c
diff --git a/lib/libc/thread/thread_fd.c b/lib/libc/thread/thread_fd.c
index 9f10fedf837..e69de29bb2d 100644
--- a/lib/libc/thread/thread_fd.c
+++ b/lib/libc/thread/thread_fd.c
@@ -1,22 +0,0 @@
-/* $OpenBSD: thread_fd.c,v 1.8 2004/06/07 21:11:23 marc Exp $ */
-
-#include <sys/time.h>
-#include "thread_private.h"
-
-WEAK_PROTOTYPE(_thread_fd_lock);
-WEAK_PROTOTYPE(_thread_fd_unlock);
-
-WEAK_ALIAS(_thread_fd_lock);
-WEAK_ALIAS(_thread_fd_unlock);
-
-int
-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)
-{
-}
-
diff --git a/lib/libc/thread/unithread_mutex.c b/lib/libc/thread/unithread_mutex.c
new file mode 100644
index 00000000000..44009de7c01
--- /dev/null
+++ b/lib/libc/thread/unithread_mutex.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: unithread_mutex.c,v 1.1 2007/06/05 18:11:48 kurt Exp $ */
+
+/*
+ * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include "thread_private.h"
+
+WEAK_PROTOTYPE(_thread_mutex_lock);
+WEAK_PROTOTYPE(_thread_mutex_unlock);
+WEAK_PROTOTYPE(_thread_mutex_destroy);
+
+WEAK_ALIAS(_thread_mutex_lock);
+WEAK_ALIAS(_thread_mutex_unlock);
+WEAK_ALIAS(_thread_mutex_destroy);
+
+/* ARGSUSED */
+void
+WEAK_NAME(_thread_mutex_lock)(void **mutex)
+{
+ return;
+}
+
+/* ARGSUSED */
+void
+WEAK_NAME(_thread_mutex_unlock)(void **mutex)
+{
+ return;
+}
+
+/* ARGSUSED */
+void
+WEAK_NAME(_thread_mutex_destroy)(void **mutex)
+{
+ return;
+}
diff --git a/lib/libpthread/shlib_version b/lib/libpthread/shlib_version
index 5b844bbf422..d0f0988b418 100644
--- a/lib/libpthread/shlib_version
+++ b/lib/libpthread/shlib_version
@@ -1,2 +1,2 @@
-major=7
+major=8
minor=0
diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc
index 2545995b494..a7f50b57a01 100644
--- a/lib/libpthread/thread/Makefile.inc
+++ b/lib/libpthread/thread/Makefile.inc
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2007/06/05 18:11:48 kurt Exp $
.PATH: ${SRCDIR}/thread
-SRCS+= thread_tag.c thread_malloc_lock.c
+SRCS+= thread_tag.c thread_malloc_lock.c thread_mutex.c
diff --git a/lib/libpthread/thread/thread_mutex.c b/lib/libpthread/thread/thread_mutex.c
new file mode 100644
index 00000000000..979a2e2e3fc
--- /dev/null
+++ b/lib/libpthread/thread/thread_mutex.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: thread_mutex.c,v 1.1 2007/06/05 18:11:48 kurt Exp $ */
+
+/*
+ * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include "thread_private.h"
+#include "pthread.h"
+#include "pthread_private.h"
+
+void
+_thread_mutex_lock(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_lock(pmutex) != 0)
+ PANIC("mutex lock failure");
+}
+
+void
+_thread_mutex_unlock(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_unlock(pmutex) != 0)
+ PANIC("mutex unlock failure");
+}
+
+void
+_thread_mutex_destroy(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_destroy(pmutex) != 0)
+ PANIC("mutex destroy failure");
+}
diff --git a/lib/libpthread/uthread/Makefile.inc b/lib/libpthread/uthread/Makefile.inc
index 6ef4e88c344..3e814dd0500 100644
--- a/lib/libpthread/uthread/Makefile.inc
+++ b/lib/libpthread/uthread/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.19 2005/10/30 03:37:34 brad Exp $
+# $OpenBSD: Makefile.inc,v 1.20 2007/06/05 18:11:48 kurt Exp $
# $FreeBSD: Makefile.inc,v 1.19 1999/08/28 00:03:19 peter Exp $
# uthread sources
@@ -59,6 +59,7 @@ SRCS+= \
uthread_fstat.c \
uthread_fstatfs.c \
uthread_fsync.c \
+ uthread_ftruncate.c \
uthread_gc.c \
uthread_getdirentries.c \
uthread_getpeername.c \
@@ -75,6 +76,7 @@ SRCS+= \
uthread_kqueue.c \
uthread_kill.c \
uthread_listen.c \
+ uthread_lseek.c \
uthread_main_np.c \
uthread_mattr_init.c \
uthread_mattr_kind_np.c \
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index 5ccdde97165..d26fc50bf53 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.66 2007/05/21 16:50:36 kurt Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.67 2007/06/05 18:11:49 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -491,8 +491,15 @@ enum pthread_state {
/*
- * File descriptor locking definitions are defined in "thread_private.h"
+ * File descriptor locking definitions.
*/
+#define FD_READ 0x1
+#define FD_WRITE 0x2
+#define FD_RDWR (FD_READ | FD_WRITE)
+#define FD_RDWR_CLOSE (FD_RDWR | 0x4)
+
+#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
+#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
/*
* File status flags struture - shared for dup'ed fd's
@@ -1148,6 +1155,8 @@ void _thread_cleanupspecific(void);
void _thread_clear_pending(int, pthread_t);
void _thread_dump_data(const void *, int);
void _thread_dump_info(void);
+int _thread_fd_lock(int, int, struct timespec *);
+void _thread_fd_unlock(int, int);
void _thread_init(void);
void _thread_kern_lock(int);
void _thread_kern_sched(struct sigcontext *);
diff --git a/lib/libpthread/uthread/uthread_ftruncate.c b/lib/libpthread/uthread/uthread_ftruncate.c
new file mode 100644
index 00000000000..c29e2f090dc
--- /dev/null
+++ b/lib/libpthread/uthread/uthread_ftruncate.c
@@ -0,0 +1,57 @@
+/* $OpenBSD: uthread_ftruncate.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
+ */
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+register_t __syscall(quad_t, ...);
+
+/*
+ * This function provides 64-bit offset padding that
+ * is not supplied by GCC 1.X but is supplied by GCC 2.X.
+ */
+int
+ftruncate(int fd, off_t length)
+{
+ int retval;
+
+ if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) {
+ retval = -1;
+ } else {
+ retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length);
+ _FD_UNLOCK(fd, FD_RDWR);
+ }
+ return retval;
+}
+#endif
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 55fed967e2d..93f7ec27ad6 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.38 2007/05/21 16:50:36 kurt Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.39 2007/06/05 18:11:49 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -130,8 +130,6 @@ static void *references[] = {
&write,
&writev,
/* libc thread-safe helper functions */
- &_thread_fd_lock,
- &_thread_fd_unlock,
&_thread_malloc_init,
&_thread_malloc_lock,
&_thread_malloc_unlock,
@@ -140,9 +138,14 @@ static void *references[] = {
&_thread_tag_lock,
&_thread_tag_unlock,
&_thread_tag_storage,
+ &_thread_mutex_lock,
+ &_thread_mutex_unlock,
+ &_thread_mutex_destroy,
&flockfile,
+ &ftruncate,
&ftrylockfile,
- &funlockfile
+ &funlockfile,
+ &lseek
};
/*
diff --git a/lib/libpthread/uthread/uthread_lseek.c b/lib/libpthread/uthread/uthread_lseek.c
new file mode 100644
index 00000000000..152d707938b
--- /dev/null
+++ b/lib/libpthread/uthread/uthread_lseek.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: uthread_lseek.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
+ */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+off_t __syscall(quad_t, ...);
+
+/*
+ * This function provides 64-bit offset padding that
+ * is not supplied by GCC 1.X but is supplied by GCC 2.X.
+ */
+off_t
+lseek(int fd, off_t offset, int whence)
+{
+ off_t retval;
+
+ if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) {
+ retval = -1;
+ } else {
+ retval = __syscall((quad_t)SYS_lseek, fd, 0, offset, whence);
+ _FD_UNLOCK(fd, FD_RDWR);
+ }
+ return retval;
+}
+#endif
diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c
index a237d193070..f45a0f64616 100644
--- a/lib/libpthread/uthread/uthread_mutex.c
+++ b/lib/libpthread/uthread/uthread_mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_mutex.c,v 1.20 2007/05/01 18:16:38 kurt Exp $ */
+/* $OpenBSD: uthread_mutex.c,v 1.21 2007/06/05 18:11:49 kurt Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -667,7 +667,9 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
/*
* If the mutex is statically initialized, perform the dynamic
- * initialization:
+ * initialization. Note: _thread_mutex_lock() in libc requires
+ * pthread_mutex_lock() to perform the mutex init when *mutex
+ * is NULL.
*/
else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0))
ret = mutex_lock_common(mutex);
diff --git a/lib/librthread/rthread_libc.c b/lib/librthread/rthread_libc.c
index 30a820e1280..bf3c057d874 100644
--- a/lib/librthread/rthread_libc.c
+++ b/lib/librthread/rthread_libc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_libc.c,v 1.3 2006/10/27 02:41:24 tedu Exp $ */
+/* $OpenBSD: rthread_libc.c,v 1.4 2007/06/05 18:11:49 kurt Exp $ */
/* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
@@ -126,6 +126,33 @@ _thread_tag_storage(void **tag, void *storage, size_t sz, void *err)
return ret;
}
+void
+_thread_mutex_lock(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_lock(pmutex) != 0)
+ _rthread_debug(1, "mutex lock failure");
+}
+
+void
+_thread_mutex_unlock(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_unlock(pmutex) != 0)
+ _rthread_debug(1, "mutex unlock failure");
+}
+
+void
+_thread_mutex_destroy(void **mutex)
+{
+ pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex;
+
+ if (pthread_mutex_destroy(pmutex) != 0)
+ _rthread_debug(1, "mutex destroy failure");
+}
+
/*
* the malloc lock
*/
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index 28706b6181d..29c561b7dee 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.17 2007/05/25 22:38:39 kurt Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.18 2007/06/05 18:11:49 kurt Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -257,6 +257,12 @@ _rthread_mutex_lock(pthread_mutex_t *mutexp, int trywait)
pthread_t thread = pthread_self();
int ret = 0;
+ /*
+ * If the mutex is statically initialized, perform the dynamic
+ * initialization. Note: _thread_mutex_lock() in libc requires
+ * _rthread_mutex_lock() to perform the mutex init when *mutexp
+ * is NULL.
+ */
if (*mutexp == NULL) {
_spinlock(&static_init_lock);
if (*mutexp == NULL)