summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread_libc.c
diff options
context:
space:
mode:
authorkurt <kurt@openbsd.org>2007-06-05 18:11:48 +0000
committerkurt <kurt@openbsd.org>2007-06-05 18:11:48 +0000
commit45e14c381361430fbd1edeac8cedeeb0decb1480 (patch)
treea5ed83726574726f3efb97709ca2097c63d5a220 /lib/librthread/rthread_libc.c
parentremove ipx-related stuff. objections nobody. major bump by kurt in a few (diff)
downloadwireguard-openbsd-45e14c381361430fbd1edeac8cedeeb0decb1480.tar.xz
wireguard-openbsd-45e14c381361430fbd1edeac8cedeeb0decb1480.zip
_FD_LOCK/UNLOCK() is libpthread specific and not needed for librthread, so
isolate its usage to libpthread only and replace with generic non-static mutex support in the one place it is needed: - remove _FD_LOCK/UNLOCK from lseek and ftruncate in libc and make the functions weak so that libpthread can override with its own new versions that do the locking. - remove _thread_fd_lock/unlock() weak functions from libc and adjust libpthread for the change. - add generic _thread_mutex_lock/unlock/destroy() weak functions in libc to support non-static mutexes in libc and add libpthread and librthread implementations for them. libc can utilize non-static mutexes via the new _MUTEX_LOCK/UNLOCK/DESTROY() macros. Actually these new macros can support both static and non-static mutexes but currently only using them for non-static. - make opendir/closedir/readdir/readdir_r/seekdir/telldir() thread-safe for both thread libraries by using a non-static mutex in the struct _dirdesc (typedef DIR), utilizing it in the *dir functions and remove remaining and incorrect _FD_LOCK/UNLOCK() use in libc. - add comments to both thread libraries to indicate libc depends on the current implementation of static mutex initialization. suggested by marc@ - major bump libc and libpthread due to function removal, structure change and weak symbol conversions. okay marc@, tedu@
Diffstat (limited to 'lib/librthread/rthread_libc.c')
-rw-r--r--lib/librthread/rthread_libc.c29
1 files changed, 28 insertions, 1 deletions
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
*/