summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth/Makefile3
-rw-r--r--auth/auth.c34
-rw-r--r--boot/Makefile5
-rw-r--r--boot/boot.c49
-rw-r--r--boot/ux.c14
-rw-r--r--console-client/Makefile6
-rw-r--r--console-client/console.c120
-rw-r--r--console-client/driver.c60
-rw-r--r--console-client/driver.h33
-rw-r--r--console-client/generic-speaker.c2
-rw-r--r--console-client/kbd-repeat.c51
-rw-r--r--console-client/ncursesw.c66
-rw-r--r--console-client/pc-kbd.c16
-rw-r--r--console-client/pc-mouse.c65
-rw-r--r--console-client/timer.c42
-rw-r--r--console-client/trans.c30
-rw-r--r--console-client/vga.c14
-rw-r--r--console/Makefile3
-rw-r--r--console/console.c105
-rw-r--r--console/display.c110
-rw-r--r--console/input.c44
-rw-r--r--console/pager.c21
-rw-r--r--defpager/backing.c12
-rw-r--r--exec/Makefile3
-rw-r--r--exec/exec.c36
-rw-r--r--exec/hashexec.c4
-rw-r--r--exec/priv.h4
-rw-r--r--ext2fs/Makefile3
-rw-r--r--ext2fs/balloc.c32
-rw-r--r--ext2fs/dir.c8
-rw-r--r--ext2fs/ext2fs.c4
-rw-r--r--ext2fs/ext2fs.h18
-rw-r--r--ext2fs/ialloc.c24
-rw-r--r--ext2fs/inode.c34
-rw-r--r--ext2fs/msg.c19
-rw-r--r--ext2fs/pager.c66
-rw-r--r--ext2fs/pokel.c22
-rw-r--r--ext2fs/storeinfo.c4
-rw-r--r--ext2fs/truncate.c12
-rw-r--r--fatfs/Makefile3
-rw-r--r--fatfs/dir.c8
-rw-r--r--fatfs/fat.c18
-rw-r--r--fatfs/fatfs.h6
-rw-r--r--fatfs/inode.c74
-rw-r--r--fatfs/main.c4
-rw-r--r--fatfs/pager.c78
-rw-r--r--fatfs/virt-inode.c20
-rw-r--r--ftpfs/Makefile3
-rw-r--r--ftpfs/ccache.c24
-rw-r--r--ftpfs/ccache.h4
-rw-r--r--ftpfs/conn.c12
-rw-r--r--ftpfs/dir.c38
-rw-r--r--ftpfs/fs.c6
-rw-r--r--ftpfs/ftpfs.c18
-rw-r--r--ftpfs/ftpfs.h8
-rw-r--r--ftpfs/ncache.c4
-rw-r--r--ftpfs/netfs.c4
-rw-r--r--ftpfs/node.c12
-rw-r--r--hostmux/Makefile3
-rw-r--r--hostmux/hostmux.h4
-rw-r--r--hostmux/mux.c30
-rw-r--r--hostmux/node.c2
-rw-r--r--hostmux/stubs.c2
-rw-r--r--hurd/shared.h3
-rw-r--r--isofs/Makefile3
-rw-r--r--isofs/inode.c30
-rw-r--r--isofs/lookup.c4
-rw-r--r--isofs/main.c4
-rw-r--r--isofs/pager.c20
-rw-r--r--libcons/Makefile3
-rw-r--r--libcons/cons-switch.c9
-rw-r--r--libcons/cons.h4
-rw-r--r--libcons/dir-changed.c8
-rw-r--r--libcons/file-changed.c5
-rw-r--r--libcons/init-init.c3
-rw-r--r--libcons/vcons-close.c6
-rw-r--r--libcons/vcons-input.c5
-rw-r--r--libcons/vcons-move-mouse.c5
-rw-r--r--libcons/vcons-open.c5
-rw-r--r--libcons/vcons-scrollback.c6
-rw-r--r--libdiskfs/Makefile3
-rw-r--r--libdiskfs/boot-start.c20
-rw-r--r--libdiskfs/dead-name.c4
-rw-r--r--libdiskfs/dir-chg.c10
-rw-r--r--libdiskfs/dir-link.c28
-rw-r--r--libdiskfs/dir-lookup.c14
-rw-r--r--libdiskfs/dir-mkdir.c6
-rw-r--r--libdiskfs/dir-mkfile.c8
-rw-r--r--libdiskfs/dir-readdir.c8
-rw-r--r--libdiskfs/dir-rename.c52
-rw-r--r--libdiskfs/dir-renamed.c22
-rw-r--r--libdiskfs/dir-rmdir.c6
-rw-r--r--libdiskfs/dir-unlink.c10
-rw-r--r--libdiskfs/disk-pager.c25
-rw-r--r--libdiskfs/diskfs-pager.h12
-rw-r--r--libdiskfs/diskfs.h8
-rw-r--r--libdiskfs/file-access.c4
-rw-r--r--libdiskfs/file-chg.c6
-rw-r--r--libdiskfs/file-exec.c4
-rw-r--r--libdiskfs/file-get-fs-opts.c4
-rw-r--r--libdiskfs/file-get-trans.c4
-rw-r--r--libdiskfs/file-get-transcntl.c4
-rw-r--r--libdiskfs/file-getcontrol.c4
-rw-r--r--libdiskfs/file-getfh.c4
-rw-r--r--libdiskfs/file-lock-stat.c4
-rw-r--r--libdiskfs/file-lock.c4
-rw-r--r--libdiskfs/file-reparent.c4
-rw-r--r--libdiskfs/file-set-trans.c30
-rw-r--r--libdiskfs/file-sync.c4
-rw-r--r--libdiskfs/file-syncfs.c4
-rw-r--r--libdiskfs/fsys-getroot.c20
-rw-r--r--libdiskfs/fsys-options.c16
-rw-r--r--libdiskfs/fsys-syncfs.c8
-rw-r--r--libdiskfs/ifsock.c30
-rw-r--r--libdiskfs/init-first.c19
-rw-r--r--libdiskfs/init-init.c10
-rw-r--r--libdiskfs/init-startup.c12
-rw-r--r--libdiskfs/io-duplicate.c4
-rw-r--r--libdiskfs/io-get-conch.c6
-rw-r--r--libdiskfs/io-identity.c4
-rw-r--r--libdiskfs/io-map-cntl.c8
-rw-r--r--libdiskfs/io-map.c6
-rw-r--r--libdiskfs/io-modes-get.c4
-rw-r--r--libdiskfs/io-modes-off.c4
-rw-r--r--libdiskfs/io-modes-on.c4
-rw-r--r--libdiskfs/io-modes-set.c4
-rw-r--r--libdiskfs/io-owner-get.c4
-rw-r--r--libdiskfs/io-owner-mod.c4
-rw-r--r--libdiskfs/io-prenotify.c8
-rw-r--r--libdiskfs/io-read.c6
-rw-r--r--libdiskfs/io-readable.c4
-rw-r--r--libdiskfs/io-reauthenticate.c6
-rw-r--r--libdiskfs/io-rel-conch.c6
-rw-r--r--libdiskfs/io-restrict-auth.c4
-rw-r--r--libdiskfs/io-revoke.c4
-rw-r--r--libdiskfs/io-seek.c4
-rw-r--r--libdiskfs/io-sigio.c4
-rw-r--r--libdiskfs/io-stat.c4
-rw-r--r--libdiskfs/io-write.c4
-rw-r--r--libdiskfs/lookup.c6
-rw-r--r--libdiskfs/name-cache.c26
-rw-r--r--libdiskfs/node-drop.c4
-rw-r--r--libdiskfs/node-make.c2
-rw-r--r--libdiskfs/node-nput.c14
-rw-r--r--libdiskfs/node-nputl.c6
-rw-r--r--libdiskfs/node-nref.c8
-rw-r--r--libdiskfs/node-nrefl.c4
-rw-r--r--libdiskfs/node-nrele.c18
-rw-r--r--libdiskfs/node-nrelel.c6
-rw-r--r--libdiskfs/peropen-rele.c4
-rw-r--r--libdiskfs/priv.h6
-rw-r--r--libdiskfs/shutdown.c10
-rw-r--r--libdiskfs/sync-interval.c34
-rw-r--r--libfshelp/Makefile3
-rw-r--r--libfshelp/fetch-root.c12
-rw-r--r--libfshelp/fshelp.h14
-rw-r--r--libfshelp/get-identity.c10
-rw-r--r--libfshelp/lock-acquire.c12
-rw-r--r--libfshelp/lock-init.c2
-rw-r--r--libfshelp/locks.h2
-rw-r--r--libfshelp/set-active.c2
-rw-r--r--libfshelp/trans.h4
-rw-r--r--libfshelp/transbox-init.c6
-rw-r--r--libiohelp/Makefile3
-rw-r--r--libiohelp/get_conch.c10
-rw-r--r--libiohelp/handle_io_release_conch.c6
-rw-r--r--libiohelp/initialize_conch.c4
-rw-r--r--libiohelp/iohelp.h8
-rw-r--r--libiohelp/verify_user_conch.c6
-rw-r--r--libnetfs/Makefile3
-rw-r--r--libnetfs/dir-lookup.c14
-rw-r--r--libnetfs/dir-mkdir.c4
-rw-r--r--libnetfs/dir-mkfile.c2
-rw-r--r--libnetfs/dir-readdir.c4
-rw-r--r--libnetfs/dir-rmdir.c4
-rw-r--r--libnetfs/dir-unlink.c4
-rw-r--r--libnetfs/drop-node.c2
-rw-r--r--libnetfs/file-chauthor.c4
-rw-r--r--libnetfs/file-check-access.c4
-rw-r--r--libnetfs/file-chflags.c4
-rw-r--r--libnetfs/file-chmod.c4
-rw-r--r--libnetfs/file-chown.c4
-rw-r--r--libnetfs/file-exec.c4
-rw-r--r--libnetfs/file-get-storage-info.c4
-rw-r--r--libnetfs/file-get-translator.c6
-rw-r--r--libnetfs/file-lock-stat.c4
-rw-r--r--libnetfs/file-lock.c4
-rw-r--r--libnetfs/file-reparent.c6
-rw-r--r--libnetfs/file-set-size.c4
-rw-r--r--libnetfs/file-set-translator.c14
-rw-r--r--libnetfs/file-statfs.c4
-rw-r--r--libnetfs/file-sync.c4
-rw-r--r--libnetfs/file-syncfs.c4
-rw-r--r--libnetfs/file-utimes.c4
-rw-r--r--libnetfs/fsys-getroot.c8
-rw-r--r--libnetfs/fsys-set-options.c4
-rw-r--r--libnetfs/init-init.c2
-rw-r--r--libnetfs/io-clear-some-openmodes.c4
-rw-r--r--libnetfs/io-duplicate.c4
-rw-r--r--libnetfs/io-get-openmodes.c4
-rw-r--r--libnetfs/io-get-owner.c4
-rw-r--r--libnetfs/io-identity.c8
-rw-r--r--libnetfs/io-mod-owner.c4
-rw-r--r--libnetfs/io-read.c6
-rw-r--r--libnetfs/io-readable.c4
-rw-r--r--libnetfs/io-reauthenticate.c4
-rw-r--r--libnetfs/io-restrict-auth.c6
-rw-r--r--libnetfs/io-revoke.c4
-rw-r--r--libnetfs/io-seek.c4
-rw-r--r--libnetfs/io-set-all-openmodes.c4
-rw-r--r--libnetfs/io-set-some-openmodes.c4
-rw-r--r--libnetfs/io-stat.c4
-rw-r--r--libnetfs/io-write.c6
-rw-r--r--libnetfs/make-node.c2
-rw-r--r--libnetfs/netfs.h5
-rw-r--r--libnetfs/nput.c6
-rw-r--r--libnetfs/nref.c4
-rw-r--r--libnetfs/nrele.c6
-rw-r--r--libnetfs/release-peropen.c6
-rw-r--r--libnetfs/shutdown.c6
-rw-r--r--libpager/Makefile3
-rw-r--r--libpager/chg-compl.c6
-rw-r--r--libpager/clean.c4
-rw-r--r--libpager/data-request.c14
-rw-r--r--libpager/data-return.c14
-rw-r--r--libpager/data-unlock.c4
-rw-r--r--libpager/inhibit-term.c2
-rw-r--r--libpager/lock-completed.c6
-rw-r--r--libpager/lock-object.c8
-rw-r--r--libpager/mark-error.c4
-rw-r--r--libpager/no-senders.c4
-rw-r--r--libpager/object-init.c4
-rw-r--r--libpager/object-terminate.c8
-rw-r--r--libpager/offer-page.c8
-rw-r--r--libpager/pager-attr.c10
-rw-r--r--libpager/pager-create.c4
-rw-r--r--libpager/pager-shutdown.c4
-rw-r--r--libpager/priv.h5
-rw-r--r--libpager/seqnos.c8
-rw-r--r--libpipe/Makefile3
-rw-r--r--libpipe/pipe.c76
-rw-r--r--libpipe/pipe.h40
-rw-r--r--libports/Makefile1
-rw-r--r--libports/begin-rpc.c13
-rw-r--r--libports/bucket-iterate.c5
-rw-r--r--libports/claim-right.c6
-rw-r--r--libports/class-iterate.c7
-rw-r--r--libports/complete-deallocate.c3
-rw-r--r--libports/count-bucket.c5
-rw-r--r--libports/count-class.c5
-rw-r--r--libports/create-bucket.c5
-rw-r--r--libports/create-internal.c11
-rw-r--r--libports/destroy-right.c5
-rw-r--r--libports/enable-bucket.c7
-rw-r--r--libports/enable-class.c7
-rw-r--r--libports/end-rpc.c7
-rw-r--r--libports/get-right.c7
-rw-r--r--libports/import-port.c11
-rw-r--r--libports/inhibit-all-rpcs.c7
-rw-r--r--libports/inhibit-bucket-rpcs.c7
-rw-r--r--libports/inhibit-class-rpcs.c7
-rw-r--r--libports/inhibit-port-rpcs.c7
-rw-r--r--libports/init.c5
-rw-r--r--libports/interrupt-notified-rpcs.c4
-rw-r--r--libports/interrupt-on-notify.c22
-rw-r--r--libports/interrupt-operation.c4
-rw-r--r--libports/interrupt-rpcs.c5
-rw-r--r--libports/interrupted.c14
-rw-r--r--libports/lookup-port.c5
-rw-r--r--libports/manage-multithread.c67
-rw-r--r--libports/no-senders.c7
-rw-r--r--libports/port-deref-weak.c5
-rw-r--r--libports/port-deref.c7
-rw-r--r--libports/port-ref-weak.c5
-rw-r--r--libports/port-ref.c5
-rw-r--r--libports/ports.h7
-rw-r--r--libports/reallocate-from-external.c5
-rw-r--r--libports/reallocate-port.c5
-rw-r--r--libports/resume-all-rpcs.c7
-rw-r--r--libports/resume-bucket-rpcs.c7
-rw-r--r--libports/resume-class-rpcs.c7
-rw-r--r--libports/resume-port-rpcs.c7
-rw-r--r--libports/stubs.c2
-rw-r--r--libports/transfer-right.c4
-rw-r--r--libstore/Makefile1
-rw-r--r--libstore/gunzip.c1
-rw-r--r--libstore/part.c11
-rw-r--r--libstore/unzipstore.c8
-rw-r--r--libthreads/Makefile18
-rw-r--r--libtreefs/dir-lookup.c16
-rw-r--r--libtreefs/fsys-getroot.c2
-rw-r--r--libtreefs/fsys-hooks.c4
-rw-r--r--libtreefs/fsys.c4
-rw-r--r--libtreefs/trans-help.c22
-rw-r--r--libtreefs/trans-start.c2
-rw-r--r--libtreefs/treefs.h62
-rw-r--r--libtrivfs/cntl-create.c2
-rw-r--r--libtrivfs/dyn-classes.c15
-rw-r--r--libtrivfs/io-reauthenticate.c4
-rw-r--r--libtrivfs/io-restrict-auth.c4
-rw-r--r--libtrivfs/protid-clean.c8
-rw-r--r--libtrivfs/protid-dup.c4
-rw-r--r--libtrivfs/trivfs.h4
-rw-r--r--mach-defpager/Makefile2
-rw-r--r--mach-defpager/default_pager.c238
-rw-r--r--mach-defpager/kalloc.c32
-rw-r--r--mach-defpager/main.c10
-rw-r--r--nfs/Makefile3
-rw-r--r--nfs/cache.c36
-rw-r--r--nfs/main.c20
-rw-r--r--nfs/mount.c2
-rw-r--r--nfs/name-cache.c30
-rw-r--r--nfs/nfs.h5
-rw-r--r--nfs/ops.c168
-rw-r--r--nfs/rpc.c44
-rw-r--r--nfsd/Makefile3
-rw-r--r--nfsd/cache.c71
-rw-r--r--nfsd/loop.c5
-rw-r--r--nfsd/main.c23
-rw-r--r--nfsd/nfsd.h6
-rw-r--r--pfinet/Makefile3
-rw-r--r--pfinet/ethernet.c21
-rw-r--r--pfinet/glue-include/asm/spinlock.h2
-rw-r--r--pfinet/glue-include/linux/interrupt.h10
-rw-r--r--pfinet/glue-include/linux/sched.h14
-rw-r--r--pfinet/glue-include/linux/timer.h2
-rw-r--r--pfinet/glue-include/linux/wait.h8
-rw-r--r--pfinet/iioctl-ops.c24
-rw-r--r--pfinet/io-ops.c52
-rw-r--r--pfinet/kmem_cache.c16
-rw-r--r--pfinet/main.c14
-rw-r--r--pfinet/options.c10
-rw-r--r--pfinet/pfinet-ops.c6
-rw-r--r--pfinet/pfinet.h7
-rw-r--r--pfinet/sched.c18
-rw-r--r--pfinet/socket-ops.c52
-rw-r--r--pfinet/socket.c10
-rw-r--r--pfinet/timer-emul.c25
-rw-r--r--pfinet/tunnel.c54
-rw-r--r--pflocal/Makefile3
-rw-r--r--pflocal/connq.c60
-rw-r--r--pflocal/io.c48
-rw-r--r--pflocal/sock.c64
-rw-r--r--pflocal/sock.h8
-rw-r--r--pflocal/socket.c20
-rw-r--r--pflocal/sserver.c34
-rw-r--r--proc/Makefile3
-rw-r--r--proc/info.c4
-rw-r--r--proc/main.c6
-rw-r--r--proc/mgt.c8
-rw-r--r--proc/msg.c27
-rw-r--r--proc/proc.h6
-rw-r--r--proc/stubs.c18
-rw-r--r--proc/wait.c6
-rw-r--r--storeio/Makefile3
-rw-r--r--storeio/dev.c18
-rw-r--r--storeio/dev.h8
-rw-r--r--storeio/open.c14
-rw-r--r--storeio/open.h2
-rw-r--r--storeio/pager.c40
-rw-r--r--storeio/storeio.c20
-rw-r--r--term/Makefile3
-rw-r--r--term/devio.c28
-rw-r--r--term/hurdio.c70
-rw-r--r--term/main.c10
-rw-r--r--term/munge.c6
-rw-r--r--term/ptyio.c80
-rw-r--r--term/term.h36
-rw-r--r--term/users.c265
-rw-r--r--tmpfs/Makefile3
-rw-r--r--tmpfs/dir.c4
-rw-r--r--tmpfs/node.c20
-rw-r--r--tmpfs/tmpfs.c26
-rw-r--r--tmpfs/tmpfs.h4
-rw-r--r--trans/Makefile9
-rw-r--r--trans/fakeroot.c58
-rw-r--r--trans/fifo.c51
-rw-r--r--trans/hello-mt.c37
-rw-r--r--trans/new-fifo.c56
-rw-r--r--trans/streamio.c124
-rw-r--r--ufs/Makefile3
-rw-r--r--ufs/alloc.c38
-rw-r--r--ufs/dir.c8
-rw-r--r--ufs/hyper.c10
-rw-r--r--ufs/inode.c44
-rw-r--r--ufs/main.c10
-rw-r--r--ufs/pager.c105
-rw-r--r--ufs/pokeloc.c14
-rw-r--r--ufs/sizes.c47
-rw-r--r--ufs/ufs.h13
-rw-r--r--usermux/Makefile3
-rw-r--r--usermux/mux.c38
-rw-r--r--usermux/node.c2
-rw-r--r--usermux/usermux.h4
-rw-r--r--utils/Makefile11
-rw-r--r--utils/fakeauth.c14
-rw-r--r--utils/rpctrace.c12
397 files changed, 3298 insertions, 2945 deletions
diff --git a/auth/Makefile b/auth/Makefile
index 56b99135..75910c77 100644
--- a/auth/Makefile
+++ b/auth/Makefile
@@ -22,7 +22,8 @@ makemode := server
SRCS = auth.c
OBJS = auth.o authServer.o auth_replyUser.o
target = auth
-HURDLIBS = threads ports ihash shouldbeinlibc
+HURDLIBS = ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
MIGSFLAGS = -imacros $(srcdir)/authmutations.h
diff --git a/auth/auth.c b/auth/auth.c
index ba02b963..167d8f02 100644
--- a/auth/auth.c
+++ b/auth/auth.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <mach.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/startup.h>
#include <hurd/ports.h>
@@ -266,7 +266,7 @@ S_auth_makeauth (struct authhandle *auth,
struct pending_user
{
hurd_ihash_locp_t locp; /* Position in the pending_users ihash table. */
- struct condition wakeup; /* The reader is blocked on this condition. */
+ pthread_cond_t wakeup; /* The reader is blocked on this condition. */
/* The user's auth handle. */
struct authhandle *user;
@@ -279,7 +279,7 @@ struct pending_user
struct pending_server
{
hurd_ihash_locp_t locp; /* Position in the pending_servers ihash table. */
- struct condition wakeup; /* The server is blocked on this condition. */
+ pthread_cond_t wakeup; /* The server is blocked on this condition. */
};
/* Table of pending transactions keyed on RENDEZVOUS. */
@@ -287,7 +287,7 @@ struct hurd_ihash pending_users
= HURD_IHASH_INITIALIZER (offsetof (struct pending_user, locp));
struct hurd_ihash pending_servers
= HURD_IHASH_INITIALIZER (offsetof (struct pending_server, locp));
-struct mutex pending_lock = MUTEX_INITIALIZER;
+pthread_mutex_t pending_lock = PTHREAD_MUTEX_INITIALIZER;
/* Implement auth_user_authenticate as described in <hurd/auth.defs>. */
kern_return_t
@@ -309,13 +309,13 @@ S_auth_user_authenticate (struct authhandle *userauth,
return EINVAL;
u.user = userauth;
- condition_init (&u.wakeup);
+ pthread_cond_init (&u.wakeup, NULL);
- mutex_lock (&pending_lock);
+ pthread_mutex_lock (&pending_lock);
err = hurd_ihash_add (&pending_users, rendezvous, &u);
if (err) {
- mutex_unlock (&pending_lock);
+ pthread_mutex_unlock (&pending_lock);
return err;
}
@@ -332,12 +332,12 @@ S_auth_user_authenticate (struct authhandle *userauth,
hurd_ihash_locp_remove (&pending_servers, s->locp);
/* Tell it we eventually arrived. */
- condition_signal (&s->wakeup);
+ pthread_cond_signal (&s->wakeup);
}
ports_interrupt_self_on_port_death (userauth, rendezvous);
/* Wait for server answer. */
- if (hurd_condition_wait (&u.wakeup, &pending_lock) &&
+ if (pthread_hurd_cond_wait_np (&u.wakeup, &pending_lock) &&
hurd_ihash_find (&pending_users, rendezvous))
/* We were interrupted; remove our record. */
{
@@ -349,7 +349,7 @@ S_auth_user_authenticate (struct authhandle *userauth,
err = type & MACH_PORT_TYPE_DEAD_NAME ? EINVAL : EINTR;
}
- mutex_unlock (&pending_lock);
+ pthread_mutex_unlock (&pending_lock);
if (! err)
{
@@ -389,7 +389,7 @@ S_auth_server_authenticate (struct authhandle *serverauth,
if (rendezvous == MACH_PORT_NULL || rendezvous == MACH_PORT_DEAD)
return EINVAL;
- mutex_lock (&pending_lock);
+ pthread_mutex_lock (&pending_lock);
/* Look for this rendezvous in the user list. */
u = hurd_ihash_find (&pending_users, rendezvous);
@@ -397,12 +397,12 @@ S_auth_server_authenticate (struct authhandle *serverauth,
{
/* User not here yet, have to wait for it. */
struct pending_server s;
- condition_init (&s.wakeup);
+ pthread_cond_init (&s.wakeup, NULL);
err = hurd_ihash_add (&pending_servers, rendezvous, &s);
if (! err)
{
ports_interrupt_self_on_port_death (serverauth, rendezvous);
- if (hurd_condition_wait (&s.wakeup, &pending_lock) &&
+ if (pthread_hurd_cond_wait_np (&s.wakeup, &pending_lock) &&
hurd_ihash_find (&pending_servers, rendezvous))
/* We were interrupted; remove our record. */
{
@@ -433,7 +433,7 @@ S_auth_server_authenticate (struct authhandle *serverauth,
/* Found it! */
user = u->user;
- mutex_unlock (&pending_lock);
+ pthread_mutex_unlock (&pending_lock);
/* Tell third party. */
err2 = auth_server_authenticate_reply (reply, reply_type, 0,
@@ -445,15 +445,15 @@ S_auth_server_authenticate (struct authhandle *serverauth,
if (err2)
mach_port_deallocate (mach_task_self (), reply);
- mutex_lock (&pending_lock);
+ pthread_mutex_lock (&pending_lock);
/* Give the user the new port and wake the RPC up. */
u->passthrough = newport;
- condition_signal (&u->wakeup);
+ pthread_cond_signal (&u->wakeup);
}
- mutex_unlock (&pending_lock);
+ pthread_mutex_unlock (&pending_lock);
if (err)
return err;
diff --git a/boot/Makefile b/boot/Makefile
index b7a835d0..0d883b06 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -27,7 +27,8 @@ OBJS = boot.o $(COMMON-OBJS)
UX-OBJS = mach-crt0.o uxboot.o sigvec.o syscall.o ux.o $(COMMON-OBJS)
target = boot
io-MIGSFLAGS=-DREPLY_PORTS
-HURDLIBS=store shouldbeinlibc threads
+HURDLIBS = store shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
@@ -45,7 +46,7 @@ ourdevice.defs: device.defs
uxboot.o: boot.c
$(COMPILE.c) -DUX $< -o $@
-uxboot.0: $(UX-OBJS) ../libthreads/libthreads.a
+uxboot.0: $(UX-OBJS)
$(LINK.o) -o $@ -static -nostartfiles -Wl,-T -Wl,$(srcdir)/frank1.ld $^
uxboot.1: frankemul.ld uxboot.0
$(LD) -o $@ -T $^
diff --git a/boot/boot.c b/boot/boot.c
index 2b143844..fbbced77 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -30,11 +30,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <fcntl.h>
#include <elf.h>
#include <mach/mig_support.h>
#include <mach/default_pager.h>
+#include <mach/machine/vm_param.h> /* For VM_XXX_ADDRESS */
#include <argp.h>
#include <hurd/store.h>
#include <sys/mman.h>
@@ -116,8 +117,8 @@ auth_t authserver;
struct store *root_store;
-spin_lock_t queuelock = SPIN_LOCK_INITIALIZER;
-spin_lock_t readlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t queuelock = PTHREAD_SPINLOCK_INITIALIZER;
+pthread_spinlock_t readlock = PTHREAD_SPINLOCK_INITIALIZER;
mach_port_t php_child_name, psmdp_child_name, taskname;
@@ -291,7 +292,7 @@ load_image (task_t t,
void read_reply ();
-void msg_thread ();
+void * msg_thread (void *);
/* Callbacks for boot_script.c; see boot_script.h. */
@@ -528,6 +529,7 @@ main (int argc, char **argv, char **envp)
mach_port_t foo;
char *buf = 0;
int i, len;
+ pthread_t pthread_id;
char *root_store_name;
const struct argp_child kids[] = { { &store_argp }, { 0 }};
struct argp argp = { options, parse_opt, args_doc, doc, kids };
@@ -738,7 +740,14 @@ main (int argc, char **argv, char **envp)
mach_port_deallocate (mach_task_self (), pseudo_master_device_port);
- cthread_detach (cthread_fork ((cthread_fn_t) msg_thread, (any_t) 0));
+ err = pthread_create (&pthread_id, NULL, msg_thread, NULL);
+ if (!err)
+ pthread_detach (pthread_id);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
for (;;)
{
@@ -754,8 +763,8 @@ main (int argc, char **argv, char **envp)
/* mach_msg_server (request_server, __vm_page_size * 2, receive_set); */
}
-void
-msg_thread()
+void *
+msg_thread (void *arg)
{
while (1)
mach_msg_server (request_server, 0, receive_set);
@@ -791,7 +800,7 @@ queue_read (enum read_type type,
if (!qr)
return D_NO_MEMORY;
- spin_lock (&queuelock);
+ pthread_spin_lock (&queuelock);
qr->type = type;
qr->reply_port = reply_port;
@@ -803,7 +812,7 @@ queue_read (enum read_type type,
else
qrhead = qrtail = qr;
- spin_unlock (&queuelock);
+ pthread_spin_unlock (&queuelock);
return D_SUCCESS;
}
@@ -824,7 +833,7 @@ read_reply ()
either we get the lock ourselves or that whoever currently holds the
lock will service this read when he unlocks it. */
should_read = 1;
- if (! spin_try_lock (&readlock))
+ if (pthread_spin_trylock (&readlock))
return;
/* Since we're committed to servicing the read, no one else need do so. */
@@ -833,16 +842,16 @@ read_reply ()
ioctl (0, FIONREAD, &avail);
if (!avail)
{
- spin_unlock (&readlock);
+ pthread_spin_unlock (&readlock);
return;
}
- spin_lock (&queuelock);
+ pthread_spin_lock (&queuelock);
if (!qrhead)
{
- spin_unlock (&queuelock);
- spin_unlock (&readlock);
+ pthread_spin_unlock (&queuelock);
+ pthread_spin_unlock (&readlock);
return;
}
@@ -851,7 +860,7 @@ read_reply ()
if (qr == qrtail)
qrtail = 0;
- spin_unlock (&queuelock);
+ pthread_spin_unlock (&queuelock);
if (qr->type == DEV_READ)
buf = mmap (0, qr->amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
@@ -859,7 +868,7 @@ read_reply ()
buf = alloca (qr->amount);
amtread = read (0, buf, qr->amount);
- spin_unlock (&readlock);
+ pthread_spin_unlock (&readlock);
switch (qr->type)
{
@@ -897,7 +906,7 @@ read_reply ()
static void
unlock_readlock ()
{
- spin_unlock (&readlock);
+ pthread_spin_unlock (&readlock);
while (should_read)
read_reply ();
}
@@ -1131,7 +1140,7 @@ ds_device_read (device_t device,
}
#endif
- spin_lock (&readlock);
+ pthread_spin_lock (&readlock);
ioctl (0, FIONREAD, &avail);
if (avail)
{
@@ -1186,7 +1195,7 @@ ds_device_read_inband (device_t device,
}
#endif
- spin_lock (&readlock);
+ pthread_spin_lock (&readlock);
ioctl (0, FIONREAD, &avail);
if (avail)
{
@@ -1459,7 +1468,7 @@ S_io_read (mach_port_t object,
}
#endif
- spin_lock (&readlock);
+ pthread_spin_lock (&readlock);
ioctl (0, FIONREAD, &avail);
if (avail)
{
diff --git a/boot/ux.c b/boot/ux.c
index b532f19e..7239762c 100644
--- a/boot/ux.c
+++ b/boot/ux.c
@@ -24,7 +24,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "ux.h"
@@ -54,14 +54,14 @@ struct free_reply_port
struct free_reply_port *next;
};
static struct free_reply_port *free_reply_ports = NULL;
-static spin_lock_t free_reply_ports_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t free_reply_ports_lock = PTHREAD_SPINLOCK_INITIALIZER;
mach_port_t __mig_get_reply_port ()
{
- spin_lock (&free_reply_ports_lock);
+ pthread_spin_lock (&free_reply_ports_lock);
if (free_reply_ports == NULL)
{
- spin_unlock (&free_reply_ports_lock);
+ pthread_spin_unlock (&free_reply_ports_lock);
return __mach_reply_port ();
}
else
@@ -69,7 +69,7 @@ mach_port_t __mig_get_reply_port ()
struct free_reply_port *frp = free_reply_ports;
mach_port_t reply_port = frp->port;
free_reply_ports = free_reply_ports->next;
- spin_unlock (&free_reply_ports_lock);
+ pthread_spin_unlock (&free_reply_ports_lock);
free (frp);
return reply_port;
}
@@ -82,10 +82,10 @@ void __mig_put_reply_port (mach_port_t port)
{
struct free_reply_port *frp = malloc (sizeof (struct free_reply_port));
frp->port = port;
- spin_lock (&free_reply_ports_lock);
+ pthread_spin_lock (&free_reply_ports_lock);
frp->next = free_reply_ports;
free_reply_ports = frp;
- spin_unlock (&free_reply_ports_lock);
+ pthread_spin_unlock (&free_reply_ports_lock);
}
void mig_put_reply_port (mach_port_t port)
{
diff --git a/console-client/Makefile b/console-client/Makefile
index ce8ce353..69a7e371 100644
--- a/console-client/Makefile
+++ b/console-client/Makefile
@@ -36,8 +36,8 @@ SRCS = $(CONSOLE_SRCS) \
VPATH += $(srcdir)/xkb
OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS)))) kdioctlServer.o
-HURDLIBS = cons threads ports netfs fshelp iohelp ihash shouldbeinlibc
-LDLIBS = -ldl
+HURDLIBS = cons ports netfs fshelp iohelp ihash shouldbeinlibc
+LDLIBS = -ldl -lpthread
module-dir = $(libdir)/hurd/console
console-LDFLAGS = -Wl,-E
@@ -62,7 +62,7 @@ driver-DEPS = $(..)config.make
console: $(CONSOLE_SRCS:.c=.o) \
../libnetfs/libnetfs.a ../libfshelp/libfshelp.a \
../libcons/libcons.a ../libports/libports.a \
- ../libthreads/libthreads.a ../libshouldbeinlibc/libshouldbeinlibc.a
+ ../libshouldbeinlibc/libshouldbeinlibc.a
modules = vga pc_kbd generic_speaker pc_mouse current_vcs
diff --git a/console-client/console.c b/console-client/console.c
index 06a8c1ac..806bec6d 100644
--- a/console-client/console.c
+++ b/console-client/console.c
@@ -25,7 +25,7 @@
#include <error.h>
#include <assert.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/console.h>
#include <hurd/cons.h>
@@ -45,7 +45,7 @@ const char *cons_client_version = HURD_VERSION;
/* The global lock protects the active_vcons variable, and thus all
operations on the virtual console that is currently active. */
-static struct mutex global_lock;
+static pthread_mutex_t global_lock;
/* The active virtual console. This is the one currently
displayed. */
@@ -70,15 +70,15 @@ console_current_id (int *cur)
{
vcons_t vcons;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
vcons = active_vcons;
if (!vcons)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENODEV;
}
*cur = vcons->id;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -99,28 +99,28 @@ console_switch (int id, int delta)
it isn't deallocated while we are outside of the global lock. We
also know that */
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
vcons = active_vcons;
if (!vcons)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINVAL;
}
ports_port_ref (vcons);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
err = cons_switch (vcons, id, delta, &new_vcons);
if (!err)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (active_vcons != new_vcons)
{
cons_vcons_close (active_vcons);
active_vcons = new_vcons;
}
- mutex_unlock (&new_vcons->lock);
+ pthread_mutex_unlock (&new_vcons->lock);
ports_port_deref (vcons);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
return err;
}
@@ -134,15 +134,15 @@ console_input (char *buf, size_t size)
error_t err = 0;
vcons_t vcons;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
vcons = active_vcons;
if (!vcons)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINVAL;
}
ports_port_ref (vcons);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (vcons)
{
@@ -161,16 +161,16 @@ console_move_mouse (mouse_event_t ev)
error_t err;
vcons_t vcons;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
vcons = active_vcons;
if (!vcons)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINVAL;
}
ports_port_ref (vcons);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (vcons)
{
@@ -178,7 +178,7 @@ console_move_mouse (mouse_event_t ev)
ports_port_deref (vcons);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -192,15 +192,15 @@ console_scrollback (cons_scroll_t type, float value)
int nr = 0;
vcons_t vcons;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
vcons = active_vcons;
if (!vcons)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINVAL;
}
ports_port_ref (vcons);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (vcons)
{
@@ -216,7 +216,7 @@ console_scrollback (cons_scroll_t type, float value)
void
console_switch_away (void)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
driver_iterate
if (driver->ops->save_status)
@@ -226,7 +226,7 @@ console_switch_away (void)
saved_cons = active_vcons->cons;
cons_vcons_close (active_vcons);
active_vcons = NULL;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
/* Switch back to the console client from an external user of the
@@ -235,7 +235,7 @@ void
console_switch_back (void)
{
vcons_list_t conslist;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
driver_iterate
if (driver->ops->restore_status)
@@ -248,22 +248,22 @@ console_switch_back (void)
err = cons_lookup (saved_cons, saved_id, 1, &conslist);
if (err)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return;
}
err = cons_vcons_open (saved_cons, conslist, &active_vcons);
if (err)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return;
}
conslist->vcons = active_vcons;
saved_cons = NULL;
- mutex_unlock (&active_vcons->lock);
+ pthread_mutex_unlock (&active_vcons->lock);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -278,18 +278,18 @@ console_exit (void)
/* Signal an error to the user. */
void console_error (const wchar_t *const err_msg)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
bell_iterate
if (bell->ops->beep)
bell->ops->beep (bell->handle);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
#if QUAERENDO_INVENIETIS
void
console_deprecated (int key)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
input_iterate
if (input->ops->deprecated)
(*input->ops->deprecated) (input->handle, key);
@@ -299,7 +299,7 @@ console_deprecated (int key)
bell_iterate
if (bell->ops->deprecated)
(*bell->ops->deprecated) (bell->handle, key);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
#endif /* QUAERENDO_INVENIETIS */
@@ -312,7 +312,7 @@ void
cons_vcons_add (cons_t cons, vcons_list_t vcons_entry)
{
error_t err = 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!active_vcons)
{
vcons_t vcons;
@@ -324,10 +324,10 @@ cons_vcons_add (cons_t cons, vcons_list_t vcons_entry)
{
vcons_entry->vcons = vcons;
active_vcons = vcons;
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -341,12 +341,12 @@ cons_vcons_add (cons_t cons, vcons_list_t vcons_entry)
void
cons_vcons_update (vcons_t vcons)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->update)
display->ops->update (display->handle);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -355,12 +355,12 @@ cons_vcons_update (vcons_t vcons)
void
cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->set_cursor_pos)
display->ops->set_cursor_pos (display->handle, col, row);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -369,12 +369,12 @@ cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row)
void
cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->set_cursor_status)
display->ops->set_cursor_status (display->handle, status);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -388,12 +388,12 @@ cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status)
void
cons_vcons_scroll (vcons_t vcons, int delta)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->scroll)
display->ops->scroll (display->handle, delta);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -407,12 +407,12 @@ cons_vcons_scroll (vcons_t vcons, int delta)
void cons_vcons_clear (vcons_t vcons, size_t length,
uint32_t col, uint32_t row)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->clear)
display->ops->clear (display->handle, length, col, row);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -423,12 +423,12 @@ void
cons_vcons_write (vcons_t vcons, conchar_t *str, size_t length,
uint32_t col, uint32_t row)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->write)
display->ops->write (display->handle, str, length, col, row);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -437,12 +437,12 @@ cons_vcons_write (vcons_t vcons, conchar_t *str, size_t length,
void
cons_vcons_beep (vcons_t vcons)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
bell_iterate
if (bell->ops->beep)
bell->ops->beep (bell->handle);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -451,12 +451,12 @@ cons_vcons_beep (vcons_t vcons)
void
cons_vcons_flash (vcons_t vcons)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->flash)
display->ops->flash (display->handle);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -465,12 +465,12 @@ cons_vcons_flash (vcons_t vcons)
void
cons_vcons_set_scroll_lock (vcons_t vcons, int onoff)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
input_iterate
if (input->ops->set_scroll_lock_status)
input->ops->set_scroll_lock_status (input->handle, onoff);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
@@ -481,12 +481,12 @@ cons_vcons_set_scroll_lock (vcons_t vcons, int onoff)
error_t
cons_vcons_set_dimension (vcons_t vcons, uint32_t col, uint32_t row)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->set_dimension)
display->ops->set_dimension (display->handle, col, row);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -494,12 +494,12 @@ cons_vcons_set_dimension (vcons_t vcons, uint32_t col, uint32_t row)
error_t
cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->set_mousecursor_pos)
display->ops->set_mousecursor_pos (display->handle, x, y);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -507,12 +507,12 @@ cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y)
error_t
cons_vcons_set_mousecursor_status (vcons_t vcons, int status)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (vcons == active_vcons)
display_iterate
if (display->ops->set_mousecursor_status)
display->ops->set_mousecursor_status (display->handle, status);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -615,7 +615,7 @@ main (int argc, char *argv[])
if (err)
error (1, err, "Starting driver %s failed", errname);
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
err = cons_init ();
if (err)
diff --git a/console-client/driver.c b/console-client/driver.c
index 7f799f0a..64078241 100644
--- a/console-client/driver.c
+++ b/console-client/driver.c
@@ -25,7 +25,7 @@
#include <dlfcn.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "driver.h"
@@ -42,7 +42,7 @@ char *driver_path;
/* The driver list lock, the list itself, its current length and the
total number of entries in the list. */
-struct mutex driver_list_lock;
+pthread_mutex_t driver_list_lock;
driver_t driver_list;
size_t driver_list_len;
size_t driver_list_alloc;
@@ -52,10 +52,10 @@ size_t driver_list_alloc;
error_t
driver_init (void)
{
- mutex_init (&driver_list_lock);
- mutex_init (&display_list_lock);
- mutex_init (&input_list_lock);
- mutex_init (&bell_list_lock);
+ pthread_mutex_init (&driver_list_lock, NULL);
+ pthread_mutex_init (&display_list_lock, NULL);
+ pthread_mutex_init (&input_list_lock, NULL);
+ pthread_mutex_init (&bell_list_lock, NULL);
return 0;
}
@@ -67,7 +67,7 @@ driver_fini (void)
{
unsigned int i;
- mutex_lock (&driver_list_lock);
+ pthread_mutex_lock (&driver_list_lock);
for (i = 0; i < driver_list_len; i++)
{
driver_list[i].ops->fini (driver_list[i].handle, 1);
@@ -76,7 +76,7 @@ driver_fini (void)
free (driver_list[i].driver);
}
driver_list_len = 0;
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return 0;
}
@@ -101,11 +101,11 @@ error_t driver_add (const char *const name, const char *const driver,
int defpath = 0;
char *opt_backup;
- mutex_lock (&driver_list_lock);
+ pthread_mutex_lock (&driver_list_lock);
for (i = 0; i < driver_list_len; i++)
if (driver_list[i].name && !strcmp (driver_list[i].name, name))
{
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return EEXIST;
}
@@ -122,7 +122,7 @@ error_t driver_add (const char *const name, const char *const driver,
if (asprintf (&filename,
"%s/%s%s", dir, driver, CONSOLE_SONAME_SUFFIX) < 0)
{
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return ENOMEM;
}
@@ -134,7 +134,7 @@ error_t driver_add (const char *const name, const char *const driver,
if (errno != ENOENT)
{
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return errno ?: EGRATUITOUS;
}
}
@@ -158,7 +158,7 @@ error_t driver_add (const char *const name, const char *const driver,
{
if (filename)
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return ENOENT;
}
@@ -166,7 +166,7 @@ error_t driver_add (const char *const name, const char *const driver,
{
dlclose (shobj);
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return ENOMEM;
}
@@ -176,7 +176,7 @@ error_t driver_add (const char *const name, const char *const driver,
{
dlclose (shobj);
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return EGRATUITOUS;
}
@@ -189,7 +189,7 @@ error_t driver_add (const char *const name, const char *const driver,
{
dlclose (shobj);
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return errno;
}
driver_list = new_list;
@@ -210,7 +210,7 @@ error_t driver_add (const char *const name, const char *const driver,
free (drv->driver);
dlclose (shobj);
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return ENOMEM;
}
@@ -229,12 +229,12 @@ error_t driver_add (const char *const name, const char *const driver,
free (drv->driver);
dlclose (shobj);
free (filename);
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return err;
}
driver_list_len++;
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return 0;
}
@@ -250,7 +250,7 @@ driver_start (char **name)
error_t err = 0;
int i;
- mutex_lock (&driver_list_lock);
+ pthread_mutex_lock (&driver_list_lock);
for (i = 0; i < driver_list_len; i++)
{
if (driver_list[i].ops->start)
@@ -266,7 +266,7 @@ driver_start (char **name)
break;
}
}
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return err;
}
@@ -279,7 +279,7 @@ error_t driver_remove (const char *const name)
error_t err;
unsigned int i;
- mutex_lock (&driver_list_lock);
+ pthread_mutex_lock (&driver_list_lock);
for (i = 0; i < driver_list_len; i++)
if (driver_list[i].name && !strcmp (driver_list[i].name, name))
{
@@ -297,15 +297,15 @@ error_t driver_remove (const char *const name)
}
driver_list_len--;
}
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return err;
}
- mutex_unlock (&driver_list_lock);
+ pthread_mutex_unlock (&driver_list_lock);
return ESRCH;
}
#define ADD_REMOVE_COMPONENT(component) \
-struct mutex component##_list_lock; \
+pthread_mutex_t component##_list_lock; \
component##_t component##_list; \
size_t component##_list_len; \
size_t component##_list_alloc; \
@@ -313,7 +313,7 @@ size_t component##_list_alloc; \
error_t \
driver_add_##component (component##_ops_t ops, void *handle) \
{ \
- mutex_lock (&component##_list_lock); \
+ pthread_mutex_lock (&component##_list_lock); \
if (component##_list_len == component##_list_alloc) \
{ \
size_t new_alloc = component##_list_alloc + LIST_GROW; \
@@ -322,7 +322,7 @@ driver_add_##component (component##_ops_t ops, void *handle) \
* sizeof (*component##_list)); \
if (!new_list) \
{ \
- mutex_unlock (&component##_list_lock); \
+ pthread_mutex_unlock (&component##_list_lock); \
return errno; \
} \
component##_list = new_list; \
@@ -331,7 +331,7 @@ driver_add_##component (component##_ops_t ops, void *handle) \
component##_list[component##_list_len].ops = ops; \
component##_list[component##_list_len].handle = handle; \
component##_list_len++; \
- mutex_unlock (&component##_list_lock); \
+ pthread_mutex_unlock (&component##_list_lock); \
return 0; \
} \
\
@@ -340,7 +340,7 @@ driver_remove_##component (component##_ops_t ops, void *handle) \
{ \
unsigned int i; \
\
- mutex_lock (&component##_list_lock); \
+ pthread_mutex_lock (&component##_list_lock); \
for (i = 0; i < component##_list_len; i++) \
if (component##_list[i].ops == ops \
&& component##_list[i].handle == handle) \
@@ -352,7 +352,7 @@ driver_remove_##component (component##_ops_t ops, void *handle) \
} \
component##_list_len--; \
} \
- mutex_unlock (&component##_list_lock); \
+ pthread_mutex_unlock (&component##_list_lock); \
return 0; \
}
diff --git a/console-client/driver.h b/console-client/driver.h
index aacd5890..c1b24b07 100644
--- a/console-client/driver.h
+++ b/console-client/driver.h
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stddef.h>
+#include <pthread.h>
#include "display.h"
#include "input.h"
@@ -87,10 +88,10 @@ error_t driver_remove (const char *const name);
The variable DRIVER is provided by the macro. */
#define driver_iterate \
- for (driver_t driver = (mutex_lock (&driver_list_lock), \
+ for (driver_t driver = (pthread_mutex_lock (&driver_list_lock), \
&driver_list[0]); \
driver < &driver_list[driver_list_len] \
- || (mutex_unlock (&driver_list_lock), 0); \
+ || (pthread_mutex_unlock (&driver_list_lock), 0); \
driver++)
@@ -194,7 +195,7 @@ typedef struct driver *driver_t;
/* Forward declarations needed by the macro above. Don't use these
variables directly. */
-extern struct mutex driver_list_lock;
+extern pthread_mutex_t driver_list_lock;
extern driver_t driver_list;
extern size_t driver_list_len;
@@ -206,10 +207,10 @@ extern size_t driver_list_len;
The variable DISPLAY is provided by the macro. */
#define display_iterate \
- for (display_t display = (mutex_lock (&display_list_lock), \
+ for (display_t display = (pthread_mutex_lock (&display_list_lock), \
&display_list[0]); \
display < &display_list[display_list_len] \
- || (mutex_unlock (&display_list_lock), 0); \
+ || (pthread_mutex_unlock (&display_list_lock), 0); \
display++)
@@ -224,7 +225,7 @@ typedef struct display *display_t;
/* Forward declarations needed by the macro above. Don't use these
variables directly. */
-extern struct mutex display_list_lock;
+extern pthread_mutex_t display_list_lock;
extern display_t display_list;
extern size_t display_list_len;
@@ -235,10 +236,10 @@ extern size_t display_list_len;
input_iterate input->ops->set_scroll_lock_status (input->handle, 0);
The variable INPUT is provided by the macro. */
-#define input_iterate \
- for (input_t input = (mutex_lock (&input_list_lock), &input_list[0]); \
- input < &input_list[input_list_len] \
- || (mutex_unlock (&input_list_lock), 0); \
+#define input_iterate \
+ for (input_t input = (pthread_mutex_lock (&input_list_lock), &input_list[0]); \
+ input < &input_list[input_list_len] \
+ || (pthread_mutex_unlock (&input_list_lock), 0); \
input++)
@@ -253,7 +254,7 @@ typedef struct input *input_t;
/* Forward declarations needed by the macro above. Don't use these
variables directly. */
-extern struct mutex input_list_lock;
+extern pthread_mutex_t input_list_lock;
extern input_t input_list;
extern size_t input_list_len;
@@ -264,10 +265,10 @@ extern size_t input_list_len;
bell_iterate bell->ops->beep (bell->handle);
The variable BELL is provided by the macro. */
-#define bell_iterate \
- for (bell_t bell = (mutex_lock (&bell_list_lock), &bell_list[0]); \
- bell < &bell_list[bell_list_len] \
- || (mutex_unlock (&bell_list_lock), 0); \
+#define bell_iterate \
+ for (bell_t bell = (pthread_mutex_lock (&bell_list_lock), &bell_list[0]); \
+ bell < &bell_list[bell_list_len] \
+ || (pthread_mutex_unlock (&bell_list_lock), 0); \
bell++)
@@ -282,7 +283,7 @@ typedef struct bell *bell_t;
/* Forward declarations needed by the macro above. Don't use these
variables directly. */
-extern struct mutex bell_list_lock;
+extern pthread_mutex_t bell_list_lock;
extern bell_t bell_list;
extern size_t bell_list_len;
diff --git a/console-client/generic-speaker.c b/console-client/generic-speaker.c
index 5d8f509c..c03cc47e 100644
--- a/console-client/generic-speaker.c
+++ b/console-client/generic-speaker.c
@@ -23,8 +23,6 @@
#include <string.h>
#include <argp.h>
-#include <cthreads.h>
-
#include "driver.h"
#include "timer.h"
diff --git a/console-client/kbd-repeat.c b/console-client/kbd-repeat.c
index b9000b22..ddfd1cf4 100644
--- a/console-client/kbd-repeat.c
+++ b/console-client/kbd-repeat.c
@@ -23,6 +23,7 @@
#include <error.h>
#include <string.h>
#include <fcntl.h>
+#include <pthread.h>
#include <sys/mman.h>
#include "kdioctl_S.h"
@@ -44,15 +45,15 @@ static struct kbdbuf
char keybuffer[KBDBUFSZ];
int pos;
size_t size;
- struct condition readcond;
- struct condition writecond;
+ pthread_cond_t readcond;
+ pthread_cond_t writecond;
} kbdbuf;
/* Wakeup for select */
-static struct condition select_alert;
+static pthread_cond_t select_alert;
/* The global lock */
-static struct mutex global_lock;
+static pthread_mutex_t global_lock;
/* Amount of times the device was opened. Normally this translator
should be only opened once. */
@@ -65,13 +66,13 @@ kbd_repeat_key (kd_event *key)
{
kd_event *ev;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (kbdbuf.size + sizeof (kd_event) > KBDBUFSZ)
{
/* The input buffer is full, wait until there is some space. */
- if (hurd_condition_wait (&kbdbuf.writecond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&kbdbuf.writecond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* Interrupt, silently continue. */
}
}
@@ -80,9 +81,9 @@ kbd_repeat_key (kd_event *key)
kbdbuf.size += sizeof (kd_event);
memcpy (ev, key, sizeof (kd_event));
- condition_broadcast (&kbdbuf.readcond);
- condition_broadcast (&select_alert);
- mutex_unlock (&global_lock);
+ pthread_cond_broadcast (&kbdbuf.readcond);
+ pthread_cond_broadcast (&select_alert);
+ pthread_mutex_unlock (&global_lock);
}
@@ -99,22 +100,22 @@ repeater_select (struct protid *cred, mach_port_t reply,
if (*type == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
if (kbdbuf.size > 0)
{
*type = SELECT_READ;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
- if (hurd_condition_wait (&select_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -133,18 +134,18 @@ repeater_read (struct protid *cred, char **data,
else if (! (cred->po->openstat & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (amount > kbdbuf.size)
{
if (cred->po->openstat & O_NONBLOCK && amount > kbdbuf.size)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
- if (hurd_condition_wait (&kbdbuf.readcond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&kbdbuf.readcond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -160,7 +161,7 @@ repeater_read (struct protid *cred, char **data,
*data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
if (*data == MAP_FAILED)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENOMEM;
}
}
@@ -174,11 +175,11 @@ repeater_read (struct protid *cred, char **data,
kbdbuf.pos = KBDBUF_POS (kbdbuf.pos);
}
kbdbuf.size -= amount;
- condition_broadcast (&kbdbuf.writecond);
+ pthread_cond_broadcast (&kbdbuf.writecond);
}
*datalen = amount;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -228,11 +229,11 @@ kbd_setrepeater (const char *nodename, consnode_t *cn)
(*cn)->close = repeater_close;
(*cn)->demuxer = kdioctl_server;
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
- condition_init (&kbdbuf.readcond);
- condition_init (&kbdbuf.writecond);
- condition_init (&select_alert);
+ pthread_cond_init (&kbdbuf.readcond, NULL);
+ pthread_cond_init (&kbdbuf.writecond, NULL);
+ pthread_cond_init (&select_alert, NULL);
console_register_consnode (*cn);
diff --git a/console-client/ncursesw.c b/console-client/ncursesw.c
index a34026a2..881acad7 100644
--- a/console-client/ncursesw.c
+++ b/console-client/ncursesw.c
@@ -26,7 +26,7 @@
-I${prefix}/ncursesw. */
#include <curses.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/console.h>
#include "driver.h"
@@ -34,7 +34,7 @@
/* ncurses is not thread-safe. This lock protects all calls into the
ncurses library. */
-static struct mutex ncurses_lock;
+static pthread_mutex_t ncurses_lock;
/* The current width and height the ncursesw driver is using. */
static unsigned int current_width;
@@ -286,8 +286,8 @@ refresh_screen (void)
? current_width : (unsigned int) COLS) - 1);
}
-static any_t
-input_loop (any_t unused)
+static void *
+input_loop (void *unused)
{
int fd = 0;
fd_set rfds;
@@ -309,7 +309,7 @@ input_loop (any_t unused)
char *buf = buffer;
size_t size = 0;
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
while ((ret = wgetch (conspad)) != ERR)
{
unsigned int i;
@@ -320,7 +320,7 @@ input_loop (any_t unused)
switch (ret)
{
case 'x':
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
console_exit ();
break;
case 23: /* ^W */
@@ -337,9 +337,9 @@ input_loop (any_t unused)
case '8':
case '9':
/* Avoid a dead lock. */
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
console_switch (1 + (ret - '1'), 0);
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
break;
case 'j':
/* Scroll pad to left. */
@@ -414,7 +414,7 @@ input_loop (any_t unused)
break;
}
}
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
if (size)
console_input (buf, size);
}
@@ -494,9 +494,9 @@ mvwputsn (conchar_t *str, size_t len, off_t x, off_t y)
static error_t
ncursesw_update (void *handle)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
refresh_screen ();
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -504,7 +504,7 @@ ncursesw_update (void *handle)
static error_t
ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
assert (current_width && current_height);
if (autoscroll)
{
@@ -544,7 +544,7 @@ ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row)
wmove (conspad, row, col);
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -552,7 +552,7 @@ ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row)
static error_t
ncursesw_set_cursor_status (void *handle, uint32_t status)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
/* If the cursor is invisible and switching to one visible state is
impossible, switch to the other visible state or else the cursor
@@ -560,7 +560,7 @@ ncursesw_set_cursor_status (void *handle, uint32_t status)
if (curs_set (status) == -1 && status)
curs_set (status == 1 ? 2 : 1);
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -571,13 +571,13 @@ ncursesw_scroll (void *handle, int delta)
/* XXX We don't support scrollback for now. */
assert (delta >= 0);
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
idlok (conspad, TRUE);
scrollok (conspad, TRUE);
wscrl (conspad, delta);
idlok (conspad, FALSE);
scrollok (conspad, FALSE);
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -589,11 +589,11 @@ ncursesw_write (void *handle, conchar_t *str, size_t length,
int x;
int y;
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
getyx (conspad, y, x);
mvwputsn (str, length, col, row);
wmove (conspad, y, x);
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -601,9 +601,9 @@ ncursesw_write (void *handle, conchar_t *str, size_t length,
static error_t
ncursesw_flash (void *handle)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
flash ();
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -612,9 +612,9 @@ ncursesw_flash (void *handle)
error_t
ncursesw_beep (void *handle)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
beep ();
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
return 0;
}
@@ -624,13 +624,14 @@ static error_t
ncursesw_driver_init (void **handle, int no_exit,
int argc, char *argv[], int *next)
{
- mutex_init (&ncurses_lock);
+ pthread_mutex_init (&ncurses_lock, NULL);
return 0;
}
static error_t
ncursesw_driver_start (void *handle)
{
+ pthread_t thread;
error_t err;
int i;
@@ -675,7 +676,14 @@ ncursesw_driver_start (void *handle)
return err;
}
- cthread_detach (cthread_fork (input_loop, NULL));
+ err = pthread_create (&thread, NULL, input_loop, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
return 0;
}
@@ -685,11 +693,11 @@ static error_t
ncursesw_driver_fini (void *handle, int force)
{
/* XXX Cancel the input thread. */
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
driver_remove_display (&ncursesw_display_ops, NULL);
driver_remove_input (&ncursesw_input_ops, NULL);
driver_remove_bell (&ncursesw_bell_ops, NULL);
- mutex_unlock (&ncurses_lock);
+ pthread_mutex_unlock (&ncurses_lock);
endwin ();
return 0;
@@ -698,7 +706,7 @@ ncursesw_driver_fini (void *handle, int force)
static error_t
ncursesw_set_dimension (void *handle, unsigned int width, unsigned int height)
{
- mutex_lock (&ncurses_lock);
+ pthread_mutex_lock (&ncurses_lock);
if (width != current_width || height != current_height)
{
wresize (conspad, height, width);
@@ -707,7 +715,7 @@ ncursesw_set_dimension (void *handle, unsigned int width, unsigned int height)
}
current_width = width;
current_height = height;
- mutex_unlock(&ncurses_lock);
+ pthread_mutex_unlock(&ncurses_lock);
return 0;
}
diff --git a/console-client/pc-kbd.c b/console-client/pc-kbd.c
index 95109e52..c6eda86f 100644
--- a/console-client/pc-kbd.c
+++ b/console-client/pc-kbd.c
@@ -26,7 +26,7 @@
#include <argp.h>
#include <device/device.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/console.h>
#include <hurd/cons.h>
@@ -786,8 +786,8 @@ read_keycode (void)
#endif /* XKB_SUPPORT */
/* The input loop. */
-static any_t
-input_loop (any_t unused)
+static void *
+input_loop (void *unused)
{
#ifdef XKB_SUPPORT
/* XXX: until conversion from scancode to keycode is properly implemented
@@ -1350,6 +1350,7 @@ static error_t
pc_kbd_start (void *handle)
{
error_t err;
+ pthread_t thread;
device_t device_master;
cd = iconv_open ("UTF-8", "WCHAR_T");
@@ -1412,7 +1413,14 @@ pc_kbd_start (void *handle)
if (repeater_node)
kbd_setrepeater (repeater_node, &cnode);
- cthread_detach (cthread_fork (input_loop, NULL));
+ err = pthread_create (&thread, NULL, input_loop, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
return 0;
}
diff --git a/console-client/pc-mouse.c b/console-client/pc-mouse.c
index 8a9009fb..1b7bb5d7 100644
--- a/console-client/pc-mouse.c
+++ b/console-client/pc-mouse.c
@@ -23,6 +23,7 @@
#include <hurd/ports.h>
#include <device/device.h>
#include <fcntl.h>
+#include <pthread.h>
#include <sys/mman.h>
#include "driver.h"
#include "mach-inputdev.h"
@@ -60,15 +61,15 @@ static struct mousebuf
char evtbuffer[MOUSEBUFSZ];
int pos;
size_t size;
- struct condition readcond;
- struct condition writecond;
+ pthread_cond_t readcond;
+ pthread_cond_t writecond;
} mousebuf;
/* Wakeup for select */
-static struct condition select_alert;
+static pthread_cond_t select_alert;
/* The global lock */
-static struct mutex global_lock;
+static pthread_mutex_t global_lock;
/* Amount of times the device was opened. Normally this translator
should be only opened once. */
@@ -89,13 +90,13 @@ repeat_event (kd_event *evt)
{
kd_event *ev;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (mousebuf.size + sizeof (kd_event) > MOUSEBUFSZ)
{
/* The input buffer is full, wait until there is some space. */
- if (hurd_condition_wait (&mousebuf.writecond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&mousebuf.writecond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* Interrupt, silently continue. */
}
}
@@ -104,9 +105,9 @@ repeat_event (kd_event *evt)
mousebuf.size += sizeof (kd_event);
memcpy (ev, evt, sizeof (kd_event));
- condition_broadcast (&mousebuf.readcond);
- condition_broadcast (&select_alert);
- mutex_unlock (&global_lock);
+ pthread_cond_broadcast (&mousebuf.readcond);
+ pthread_cond_broadcast (&select_alert);
+ pthread_mutex_unlock (&global_lock);
}
@@ -123,22 +124,22 @@ repeater_select (struct protid *cred, mach_port_t reply,
if (*type == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
if (mousebuf.size > 0)
{
*type = SELECT_READ;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
- if (hurd_condition_wait (&select_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -176,18 +177,18 @@ repeater_read (struct protid *cred, char **data,
else if (! (cred->po->openstat & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (!mousebuf.size)
{
if (cred->po->openstat & O_NONBLOCK && mousebuf.size == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
- if (hurd_condition_wait (&mousebuf.readcond, &global_lock))
+ if (pthread_hurd_cond_wait_np (&mousebuf.readcond, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -207,7 +208,7 @@ repeater_read (struct protid *cred, char **data,
*data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
if (*data == MAP_FAILED)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENOMEM;
}
}
@@ -221,19 +222,19 @@ repeater_read (struct protid *cred, char **data,
mousebuf.pos = MOUSEBUF_POS (mousebuf.pos);
}
mousebuf.size -= amount;
- condition_broadcast (&mousebuf.writecond);
+ pthread_cond_broadcast (&mousebuf.writecond);
}
*datalen = amount;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
-static any_t
-input_loop (any_t unused)
+static void *
+input_loop (void *unused)
{
kd_event *ev;
vm_offset_t buf;
@@ -420,6 +421,7 @@ static error_t
pc_mouse_start (void *handle)
{
error_t err;
+ pthread_t thread;
char device_name[9];
int devnum = majordev << 3 | minordev;
device_t device_master;
@@ -443,7 +445,14 @@ pc_mouse_start (void *handle)
return err;
}
- cthread_detach (cthread_fork (input_loop, NULL));
+ err = pthread_create (&thread, NULL, input_loop, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
if (repeater_node)
setrepeater (repeater_node);
@@ -496,11 +505,11 @@ setrepeater (const char *nodename)
cnode->close = repeater_close;
cnode->demuxer = 0;
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
- condition_init (&mousebuf.readcond);
- condition_init (&mousebuf.writecond);
- condition_init (&select_alert);
+ pthread_cond_init (&mousebuf.readcond, NULL);
+ pthread_cond_init (&mousebuf.writecond, NULL);
+ pthread_cond_init (&select_alert, NULL);
console_register_consnode (cnode);
diff --git a/console-client/timer.c b/console-client/timer.c
index 7bcdeab0..a8869b5e 100644
--- a/console-client/timer.c
+++ b/console-client/timer.c
@@ -21,8 +21,9 @@
#include <errno.h>
#include <string.h>
#include <maptime.h>
-
-#include <cthreads.h>
+#include <mach.h>
+#include <pthread.h>
+#include <stdio.h>
#include "timer.h"
@@ -37,7 +38,7 @@ volatile struct mapped_time_value *timer_mapped_time;
static thread_t timer_thread;
/* The lock protects the timer list TIMERS. */
-static struct mutex timer_lock;
+static pthread_mutex_t timer_lock;
/* A list of all active timers. */
static struct timer_list *timers;
@@ -84,15 +85,15 @@ kick_timer_thread (void)
}
/* The timer thread. */
-static int
-timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
+static void *
+timer_function (void *this_is_a_pointless_variable_with_a_rather_long_name)
{
mach_port_t recv = mach_reply_port ();
int wait = 0;
timer_thread = mach_thread_self ();
- mutex_lock (&timer_lock);
+ pthread_mutex_lock (&timer_lock);
while (1)
{
int jiff = fetch_jiffies ();
@@ -104,11 +105,11 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
else
wait = ((timers->expires - jiff) * 1000) / HZ;
- mutex_unlock (&timer_lock);
+ pthread_mutex_unlock (&timer_lock);
mach_msg (NULL, (MACH_RCV_MSG | MACH_RCV_INTERRUPT
| (wait == -1 ? 0 : MACH_RCV_TIMEOUT)),
0, 0, recv, wait, MACH_PORT_NULL);
- mutex_lock (&timer_lock);
+ pthread_mutex_lock (&timer_lock);
while (timers && timers->expires < fetch_jiffies ())
{
@@ -128,7 +129,7 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
}
}
- return 0;
+ return NULL;
}
@@ -138,8 +139,9 @@ timer_init (void)
{
error_t err;
struct timeval tp;
+ pthread_t thread;
- mutex_init (&timer_lock);
+ pthread_mutex_init (&timer_lock, NULL);
err = maptime_map (0, 0, &timer_mapped_time);
if (err)
@@ -150,7 +152,15 @@ timer_init (void)
timer_root_jiffies = (long long) tp.tv_sec * HZ
+ ((long long) tp.tv_usec * HZ) / 1000000;
- cthread_detach (cthread_fork ((cthread_fn_t) timer_function, 0));
+ err = pthread_create (&thread, NULL, timer_function, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
+
return 0;
}
@@ -166,20 +176,20 @@ timer_clear (struct timer_list *timer)
void
timer_add (struct timer_list *timer)
{
- mutex_lock (&timer_lock);
+ pthread_mutex_lock (&timer_lock);
timer_add_internal (timer);
if (timers == timer)
kick_timer_thread ();
- mutex_unlock (&timer_lock);
+ pthread_mutex_unlock (&timer_lock);
}
/* Remove the timer TIMER from the list. */
int
timer_remove (struct timer_list *timer)
{
- mutex_lock (&timer_lock);
+ pthread_mutex_lock (&timer_lock);
if (timer->prev)
{
*timer->prev = timer->next;
@@ -188,12 +198,12 @@ timer_remove (struct timer_list *timer)
timer->next = 0;
timer->prev = 0;
- mutex_unlock (&timer_lock);
+ pthread_mutex_unlock (&timer_lock);
return 1;
}
else
{
- mutex_unlock (&timer_lock);
+ pthread_mutex_unlock (&timer_lock);
return 0;
}
}
diff --git a/console-client/trans.c b/console-client/trans.c
index a90b5c5d..67c84b4e 100644
--- a/console-client/trans.c
+++ b/console-client/trans.c
@@ -22,11 +22,13 @@
#include <maptime.h>
#include <stddef.h>
#include <dirent.h>
+#include <pthread.h>
#include <sys/mman.h>
#include <unistd.h>
#include <hurd/hurd_types.h>
#include <error.h>
#include <version.h>
+#include <stdio.h>
#include "trans.h"
@@ -305,11 +307,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
err = ENOENT;
out:
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (err)
*node = 0;
else
- mutex_lock (&(*node)->lock);
+ pthread_mutex_lock (&(*node)->lock);
if (!err && *node != dir && (*node)->nn->node->open)
(*node)->nn->node->open ();
@@ -454,15 +456,15 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir,
return err;
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
nn = calloc (1, sizeof (*nn));
if (!nn)
return ENOMEM;
*np = netfs_make_node (nn);
- mutex_lock (&(*np)->lock);
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_mutex_lock (&(*np)->lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
return 0;
}
@@ -477,7 +479,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **np)
{
*np = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -604,7 +606,7 @@ void netfs_node_norefs (struct node *np)
if (np->nn->symlink_path)
free (np->nn->symlink_path);
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
free (np->nn);
free (np);
}
@@ -738,8 +740,8 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
-static any_t
-console_client_translator (any_t unused)
+static void *
+console_client_translator (void *unused)
{
error_t err;
@@ -831,6 +833,7 @@ console_setup_node (char *path)
file_t node;
struct port_info *newpi;
mach_port_t right;
+ pthread_t thread;
node = file_name_lookup (path, O_CREAT|O_NOTRANS, 0664);
if (node == MACH_PORT_NULL)
@@ -886,7 +889,14 @@ console_setup_node (char *path)
fshelp_touch (&netfs_root_node->nn_stat, TOUCH_ATIME|TOUCH_MTIME|TOUCH_CTIME,
console_maptime);
- cthread_detach (cthread_fork (console_client_translator, NULL));
+ err = pthread_create (&thread, NULL, console_client_translator, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
return 0;
}
diff --git a/console-client/vga.c b/console-client/vga.c
index 9e8abb3a..8a3260bf 100644
--- a/console-client/vga.c
+++ b/console-client/vga.c
@@ -31,7 +31,7 @@
#include <sys/io.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/console.h>
#include "driver.h"
@@ -69,7 +69,7 @@ static int vga_display_max_glyphs;
static struct timer_list vga_display_timer;
/* The lock that protects the color palette manipulation. */
-static struct mutex vga_display_lock;
+static pthread_mutex_t vga_display_lock;
/* Forward declaration. */
static struct display_ops vga_display_ops;
@@ -134,13 +134,13 @@ vga_display_invert_border (void)
{
unsigned char col[3];
- mutex_lock (&vga_display_lock);
+ pthread_mutex_lock (&vga_display_lock);
vga_read_palette (0, col, 1);
col[0] = 0xff - col[0];
col[1] = 0xff - col[1];
col[2] = 0xff - col[2];
vga_write_palette (0, col, 1);
- mutex_unlock (&vga_display_lock);
+ pthread_mutex_unlock (&vga_display_lock);
}
@@ -274,7 +274,7 @@ vga_display_init (void **handle, int no_exit, int argc, char *argv[],
int pos = 1;
/* XXX Assert that we are called only once. */
- mutex_init (&vga_display_lock);
+ pthread_mutex_init (&vga_display_lock, NULL);
timer_clear (&vga_display_timer);
vga_display_timer.fnc = &vga_display_flash_off;
@@ -578,10 +578,10 @@ vga_display_recalculate_attr (dynacolor_t *dc, conchar_attr_t attr)
/* Try to get the colors as desired. This might change the palette,
so we need to take the lock (in case a flash operation times
out). */
- mutex_lock (&vga_display_lock);
+ pthread_mutex_lock (&vga_display_lock);
res_bgcol = dynacolor_lookup (*dc, bgcol);
res_fgcol = dynacolor_lookup (*dc, fgcol);
- mutex_unlock (&vga_display_lock);
+ pthread_mutex_unlock (&vga_display_lock);
if (res_bgcol == -1 || res_fgcol == -1)
dynacolor_replace_colors (dc, fgcol, bgcol, &res_fgcol, &res_bgcol);
vga_attr = res_bgcol << 4 | res_fgcol;
diff --git a/console/Makefile b/console/Makefile
index 10737489..c5ab543e 100644
--- a/console/Makefile
+++ b/console/Makefile
@@ -26,7 +26,8 @@ SRCS = console.c display.c pager.c input.c
MIGSTUBS = notifyServer.o tioctlServer.o fs_notifyUser.o
-HURDLIBS = netfs fshelp iohelp pager threads ports ihash shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp pager ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS))
MIGSFLAGS += -imacros $(srcdir)/mutations.h
diff --git a/console/console.c b/console/console.c
index cf208cff..0577ea04 100644
--- a/console/console.c
+++ b/console/console.c
@@ -33,9 +33,8 @@
#include <dirent.h>
#include <sys/mman.h>
#include <sys/stat.h>
-#include <rwlock.h>
#include <maptime.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <version.h>
@@ -104,7 +103,7 @@ struct vcons
display_t display;
input_t input;
- struct mutex lock;
+ pthread_mutex_t lock;
/* Nodes in the filesystem referring to this virtual console. */
struct node *dir_node;
struct node *cons_node;
@@ -124,7 +123,7 @@ struct cons
/* The lock protects the console, all virtual consoles contained in
it and the reference counters. It also locks the configuration
parameters. */
- struct mutex lock;
+ pthread_mutex_t lock;
vcons_t vcons_list;
/* The encoding. */
char *encoding;
@@ -188,7 +187,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
if (!id && !create)
return EINVAL;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
if (id)
{
if (cons->vcons_list && cons->vcons_list->id <= id)
@@ -199,14 +198,14 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
if (previous_vcons->id == id)
{
previous_vcons->refcnt++;
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
*r_vcons = previous_vcons;
return 0;
}
}
else if (!create)
{
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return ESRCH;
}
}
@@ -227,7 +226,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
vcons = calloc (1, sizeof (struct vcons));
if (!vcons)
{
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return ENOMEM;
}
vcons->cons = cons;
@@ -236,7 +235,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
asprintf (&vcons->name, "%i", id);
/* XXX Error checking. */
- mutex_init (&vcons->lock);
+ pthread_mutex_init (&vcons->lock, NULL);
err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
cons->attribute, cons->lines, cons->width,
cons->height);
@@ -244,7 +243,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
{
free (vcons->name);
free (vcons);
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return err;
}
@@ -254,7 +253,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
display_destroy (vcons->display);
free (vcons->name);
free (vcons);
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return err;
}
@@ -280,7 +279,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
}
cons_notice_dirchange (cons, DIR_CHANGED_NEW, vcons->name);
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
*r_vcons = vcons;
return 0;
}
@@ -291,9 +290,9 @@ vcons_ref (vcons_t vcons)
{
cons_t cons = vcons->cons;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
vcons->refcnt++;
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
}
/* Release a reference to the virtual console VCONS. If this was the
@@ -303,7 +302,7 @@ vcons_release (vcons_t vcons)
{
cons_t cons = vcons->cons;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
if (!--vcons->refcnt)
{
/* As we keep a reference for all input focus groups pointing to
@@ -326,7 +325,7 @@ vcons_release (vcons_t vcons)
free (vcons->name);
free (vcons);
}
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
}
struct netnode
@@ -424,19 +423,19 @@ netfs_node_norefs (struct node *np)
assert (!np->nn->cons && np->nn->vcons);
/* Avoid deadlock. */
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
/* Find the back reference to ourself in the virtual console
structure, and delete it. */
- mutex_lock (&vcons->lock);
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_mutex_lock (&vcons->lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
if (np->references)
{
/* Someone else got a reference while we were attempting to go
away. This can happen in netfs_attempt_lookup. In this
case, just unlock the node and do nothing else. */
- mutex_unlock (&vcons->lock);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&np->lock);
return;
}
if (np == vcons->dir_node)
@@ -450,7 +449,7 @@ netfs_node_norefs (struct node *np)
assert (np == vcons->inpt_node);
vcons->inpt_node = 0;
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
/* Release our reference. */
vcons_release (vcons);
@@ -470,7 +469,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
/* We create virtual consoles dynamically on the fly, so there is no
need for an explicit create operation. */
*np = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -616,7 +615,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
if (err)
goto out;
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
if (vcons->dir_node)
{
/* We already have a directory node for this virtual
@@ -636,7 +635,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
else
release_vcons = 1;
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
if (release_vcons)
vcons_release (vcons);
}
@@ -649,7 +648,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
if (!strcmp (name, "console"))
{
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
if (vcons->cons_node)
{
*node = vcons->cons_node;
@@ -664,11 +663,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
ref_vcons = 1;
}
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
}
else if (!strcmp (name, "display"))
{
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
if (vcons->disp_node)
{
*node = vcons->disp_node;
@@ -683,11 +682,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
ref_vcons = 1;
}
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
}
else if (!strcmp (name, "input"))
{
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
if (vcons->inpt_node)
{
*node = vcons->inpt_node;
@@ -702,7 +701,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
ref_vcons = 1;
}
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
}
else
err = ENOENT;
@@ -715,11 +714,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, console_maptime);
out:
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (err)
*node = 0;
else
- mutex_lock (&(*node)->lock);
+ pthread_mutex_lock (&(*node)->lock);
return err;
}
@@ -771,7 +770,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
if (dir->nn->cons)
{
- mutex_lock (&dir->nn->cons->lock);
+ pthread_mutex_lock (&dir->nn->cons->lock);
/* Find the first entry. */
for (first_vcons = dir->nn->cons->vcons_list, count = 2;
@@ -881,7 +880,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
}
if (dir->nn->cons)
- mutex_unlock(&dir->nn->cons->lock);
+ pthread_mutex_unlock(&dir->nn->cons->lock);
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, console_maptime);
return err;
@@ -916,7 +915,7 @@ netfs_attempt_chown (struct iouser *cred, struct node *node,
node->nn_stat.st_uid = uid;
node->nn_stat.st_gid = gid;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
cons->stat_template.st_uid = uid;
cons->stat_template.st_gid = gid;
@@ -944,7 +943,7 @@ netfs_attempt_chown (struct iouser *cred, struct node *node,
vcons->inpt_node->nn_stat.st_gid = gid;
}
}
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, console_maptime);
return err;
}
@@ -968,7 +967,7 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author)
/* Change NODE's author. */
node->nn_stat.st_author = author;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
cons->stat_template.st_author = author;
/* Change the author of each leaf node. */
@@ -983,7 +982,7 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author)
if (vcons->inpt_node)
vcons->inpt_node->nn_stat.st_author = author;
}
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, console_maptime);
return err;
}
@@ -1113,7 +1112,7 @@ netfs_attempt_read (struct iouser *cred, struct node *np,
|| np == vcons->inpt_node)
return EOPNOTSUPP;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (np == vcons->cons_node)
{
ssize_t amt = input_dequeue (vcons->input,
@@ -1143,7 +1142,7 @@ netfs_attempt_read (struct iouser *cred, struct node *np,
else
*len = amt;
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
return err;
}
@@ -1157,7 +1156,7 @@ netfs_attempt_write (struct iouser *cred, struct node *np,
|| np == vcons->disp_node)
return EOPNOTSUPP;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (np == vcons->cons_node)
{
/* The term server is writing to the console device. Feed the
@@ -1185,7 +1184,7 @@ netfs_attempt_write (struct iouser *cred, struct node *np,
else
*len = amt;
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
return err;
}
@@ -1214,7 +1213,7 @@ netfs_S_io_map (struct protid *cred,
flags = cred->po->openstat & (O_READ | O_WRITE);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
switch (flags)
{
case O_READ | O_WRITE:
@@ -1235,7 +1234,7 @@ netfs_S_io_map (struct protid *cred,
goto error;
break;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
*rdtype = MACH_MSG_TYPE_MOVE_SEND;
*wrtype = MACH_MSG_TYPE_MOVE_SEND;
@@ -1243,7 +1242,7 @@ netfs_S_io_map (struct protid *cred,
return 0;
error:
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return errno;
}
@@ -1263,7 +1262,7 @@ netfs_S_dir_notice_changes (struct protid *cred, mach_port_t notify)
if (!cons)
return EOPNOTSUPP;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
/* We have to prevent that we accumulate dead-names in the
notification list. They are cleaned up in cons_notice_dirchange,
but that is not called often enough, so we also clean them up
@@ -1292,19 +1291,19 @@ netfs_S_dir_notice_changes (struct protid *cred, mach_port_t notify)
err = dir_changed (notify, cons->dirmod_tick, DIR_CHANGED_NULL, "");
if (err)
{
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return err;
}
req = malloc (sizeof (struct modreq));
if (!req)
{
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return errno;
}
req->port = notify;
req->next = cons->dirmod_reqs;
cons->dirmod_reqs = req;
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return 0;
}
@@ -1473,11 +1472,11 @@ parse_opt (int opt, char *arg, struct argp_state *state)
break;
case ARGP_KEY_INIT:
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
break;
case ARGP_KEY_FINI:
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
break;
case 'f':
@@ -2001,7 +2000,7 @@ main (int argc, char **argv)
cons = malloc (sizeof (struct cons));
if (!cons)
error (1, ENOMEM, "Cannot create console structure");
- mutex_init (&cons->lock);
+ pthread_mutex_init (&cons->lock, NULL);
cons->encoding = NULL;
cons->width = DEFAULT_WIDTH;
cons->height = DEFAULT_HEIGHT;
diff --git a/console/display.c b/console/display.c
index e807c50f..97e16264 100644
--- a/console/display.c
+++ b/console/display.c
@@ -29,7 +29,7 @@
#include <assert.h>
#include <error.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/ports.h>
@@ -119,7 +119,7 @@ struct output
multi-byte or composed character at the end of the buffer, so we
have to keep them around. */
int stopped;
- struct condition resumed;
+ pthread_cond_t resumed;
char *buffer;
size_t allocated;
size_t size;
@@ -159,7 +159,7 @@ struct notify
struct display
{
/* The lock for the virtual console display structure. */
- struct mutex lock;
+ pthread_mutex_t lock;
/* Indicates if OWNER_ID is initialized. */
int has_owner;
@@ -339,7 +339,7 @@ do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_name)
return EOPNOTSUPP;
display = notify_port->display;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
/* Find request in pending queue. */
preq = &display->filemod_reqs_pending;
@@ -361,7 +361,7 @@ do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_name)
mach_port_deallocate (mach_task_self (), req->port);
free (req);
}
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
/* Drop gratuitous extra reference that the notification creates. */
mach_port_deallocate (mach_task_self (), dead_name);
@@ -406,7 +406,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send)
}
display = notify_port->display;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
/* Find request in pending queue. */
preq = &display->filemod_reqs_pending;
while (*preq && (*preq)->port != send)
@@ -417,7 +417,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send)
if (! *preq)
{
assert(0);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
ports_port_deref (notify_port);
return 0;
}
@@ -435,7 +435,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send)
{
mach_port_t old;
*preq = req->next;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
/* Cancel the dead-name notification. */
mach_port_request_notification (mach_task_self (), req->port,
@@ -451,7 +451,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send)
}
if (err == MACH_SEND_WILL_NOTIFY)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return 0;
}
/* The message was successfully queued, fall through. */
@@ -461,15 +461,15 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send)
/* Insert request into active queue. */
req->next = display->filemod_reqs;
display->filemod_reqs = req;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
ports_port_deref (notify_port);
return 0;
}
/* A top-level function for the notification thread that just services
notification messages. */
-static void
-service_notifications (any_t arg)
+static void *
+service_notifications (void *arg)
{
struct port_bucket *notify_bucket = arg;
extern int notify_server (mach_msg_header_t *inp, mach_msg_header_t *outp);
@@ -478,6 +478,7 @@ service_notifications (any_t arg)
ports_manage_port_operations_one_thread (notify_bucket,
notify_server,
1000 * 60 * 10);
+ return NULL;
}
error_t
@@ -488,19 +489,19 @@ display_notice_changes (display_t display, mach_port_t notify)
mach_port_t notify_port;
mach_port_t old;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
err = nowait_file_changed (notify, 0, FILE_CHANGED_NULL, 0, 0,
MACH_PORT_NULL);
if (err)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return err;
}
req = malloc (sizeof (struct modreq));
if (!req)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return errno;
}
@@ -514,7 +515,7 @@ display_notice_changes (display_t display, mach_port_t notify)
if (err)
{
free (req);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return err;
}
assert (old == MACH_PORT_NULL);
@@ -523,7 +524,7 @@ display_notice_changes (display_t display, mach_port_t notify)
req->pending = 0;
req->next = display->filemod_reqs;
display->filemod_reqs = req;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return 0;
}
@@ -924,7 +925,7 @@ screen_shift_right (display_t display, size_t col1, size_t row1, size_t col2,
static error_t
output_init (output_t output, const char *encoding)
{
- condition_init (&output->resumed);
+ pthread_cond_init (&output->resumed, NULL);
output->stopped = 0;
output->buffer = NULL;
output->allocated = 0;
@@ -1806,6 +1807,9 @@ void display_destroy_complete (void *pi);
void
display_init (void)
{
+ pthread_t thread;
+ error_t err;
+
user_pager_init ();
/* Create the notify bucket, and start to serve notifications. */
@@ -1816,8 +1820,14 @@ display_init (void)
if (! notify_class)
error (5, errno, "Cannot create notify class");
- cthread_detach (cthread_fork ((cthread_fn_t) service_notifications,
- (any_t) notify_bucket));
+ err = pthread_create (&thread, NULL, service_notifications, notify_bucket);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
@@ -1845,7 +1855,7 @@ display_create (display_t *r_display, const char *encoding,
}
display->notify_port->display = display;
- mutex_init (&display->lock);
+ pthread_mutex_init (&display->lock, NULL);
display->attr.attr_def = def_attr;
display->attr.current = display->attr.attr_def;
display->csr.bottom = height - 1;
@@ -1875,7 +1885,7 @@ display_create (display_t *r_display, const char *encoding,
void
display_destroy (display_t display)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
if (display->filemod_reqs_pending)
{
free_modreqs (display->filemod_reqs_pending);
@@ -1889,7 +1899,7 @@ display_destroy (display_t display)
ports_destroy_right (display->notify_port);
output_deinit (&display->output);
user_destroy (display);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
/* We can not free the display structure here, because it might
still be needed by pending modification requests when msg
@@ -1923,12 +1933,12 @@ display_get_size (display_t display)
void
display_getsize (display_t display, struct winsize *winsize)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
winsize->ws_row = display->user->screen.height;
winsize->ws_col = display->user->screen.width;
winsize->ws_xpixel = 0;
winsize->ws_ypixel = 0;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
}
@@ -1937,10 +1947,10 @@ display_getsize (display_t display, struct winsize *winsize)
error_t
display_set_owner (display_t display, pid_t pid)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
display->has_owner = 1;
display->owner_id = pid;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return 0;
}
@@ -1951,12 +1961,12 @@ error_t
display_get_owner (display_t display, pid_t *pid)
{
error_t err = 0;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
if (!display->has_owner)
err = ENOTTY;
else
*pid = display->owner_id;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return err;
}
@@ -1994,18 +2004,18 @@ display_output (display_t display, int nonblock, char *data, size_t datalen)
return 0;
}
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
while (output->stopped)
{
if (nonblock)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
errno = EWOULDBLOCK;
return -1;
}
- if (hurd_condition_wait (&output->resumed, &display->lock))
+ if (pthread_hurd_cond_wait_np (&output->resumed, &display->lock))
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
errno = EINTR;
return -1;
}
@@ -2016,7 +2026,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen)
err = ensure_output_buffer_size (output->size + datalen);
if (err)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
errno = ENOMEM;
return -1;
}
@@ -2036,7 +2046,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen)
if (err && !amount)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
errno = err;
return err;
}
@@ -2049,7 +2059,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen)
err = ensure_output_buffer_size (buffer_size);
if (err)
{
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return err;
}
memmove (output->buffer, buffer, buffer_size);
@@ -2057,7 +2067,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen)
output->size = buffer_size;
amount += buffer_size;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return amount;
}
@@ -2066,9 +2076,9 @@ ssize_t
display_read (display_t display, int nonblock, off_t off,
char *data, size_t len)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
memcpy (data, ((char *) display->user) + off, len);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return len;
}
@@ -2077,17 +2087,17 @@ display_read (display_t display, int nonblock, off_t off,
void
display_start_output (display_t display)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
if (display->output.stopped)
{
display->output.stopped = 0;
- condition_broadcast (&display->output.resumed);
+ pthread_cond_broadcast (&display->output.resumed);
}
display->changes.flags = display->user->flags;
display->changes.which = DISPLAY_CHANGE_FLAGS;
display->user->flags &= ~CONS_FLAGS_SCROLL_LOCK;
display_flush_filechange (display, DISPLAY_CHANGE_FLAGS);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
}
@@ -2095,13 +2105,13 @@ display_start_output (display_t display)
void
display_stop_output (display_t display)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
display->output.stopped = 1;
display->changes.flags = display->user->flags;
display->changes.which = DISPLAY_CHANGE_FLAGS;
display->user->flags |= CONS_FLAGS_SCROLL_LOCK;
display_flush_filechange (display, DISPLAY_CHANGE_FLAGS);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
}
@@ -2110,9 +2120,9 @@ size_t
display_pending_output (display_t display)
{
int output_size;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
output_size = display->output.size;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return output_size;
}
@@ -2121,9 +2131,9 @@ display_pending_output (display_t display)
void
display_discard_output (display_t display)
{
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
display->output.size = 0;
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
}
@@ -2131,8 +2141,8 @@ mach_port_t
display_get_filemap (display_t display, vm_prot_t prot)
{
mach_port_t memobj;
- mutex_lock (&display->lock);
+ pthread_mutex_lock (&display->lock);
memobj = user_pager_get_filemap (&display->user_pager, prot);
- mutex_unlock (&display->lock);
+ pthread_mutex_unlock (&display->lock);
return memobj;
}
diff --git a/console/input.c b/console/input.c
index 14879d07..7ebac302 100644
--- a/console/input.c
+++ b/console/input.c
@@ -25,16 +25,16 @@
#include <malloc.h>
#include <sys/types.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "input.h"
struct input
{
- struct mutex lock;
+ pthread_mutex_t lock;
- struct condition data_available;
- struct condition space_available;
+ pthread_cond_t data_available;
+ pthread_cond_t space_available;
#define INPUT_QUEUE_SIZE 300
char buffer[INPUT_QUEUE_SIZE];
int full;
@@ -58,9 +58,9 @@ error_t input_create (input_t *r_input, const char *encoding)
if (!input)
return ENOMEM;
- mutex_init (&input->lock);
- condition_init (&input->data_available);
- condition_init (&input->space_available);
+ pthread_mutex_init (&input->lock, NULL);
+ pthread_cond_init (&input->data_available, NULL);
+ pthread_cond_init (&input->space_available, NULL);
input->cd = iconv_open (encoding, "UTF-8");
if (input->cd == (iconv_t) -1)
@@ -119,7 +119,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data,
return 0;
}
- mutex_lock (&input->lock);
+ pthread_mutex_lock (&input->lock);
was_empty = !input->size;
while (datalen)
@@ -133,7 +133,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data,
err = EWOULDBLOCK;
goto out;
}
- if (hurd_condition_wait (&input->space_available, &input->lock))
+ if (pthread_hurd_cond_wait_np (&input->space_available, &input->lock))
{
err = EINTR;
goto out;
@@ -180,7 +180,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data,
readers and go to sleep (above). */
input->full = 1;
if (was_empty)
- condition_broadcast (&input->data_available);
+ pthread_cond_broadcast (&input->data_available);
/* Prevent calling condition_broadcast again if nonblock. */
was_empty = 0;
}
@@ -201,7 +201,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data,
err = ensure_cd_buffer_size (datalen);
if (err)
{
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
errno = err;
return enqueued ?: -1;
}
@@ -212,11 +212,11 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data,
if (enqueued)
{
if (was_empty)
- condition_broadcast (&input->data_available);
+ pthread_cond_broadcast (&input->data_available);
}
else
errno = err;
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
return enqueued ?: -1;
}
@@ -231,18 +231,18 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data,
{
size_t amount = datalen;
- mutex_lock (&input->lock);
+ pthread_mutex_lock (&input->lock);
while (!input->size)
{
if (nonblock)
{
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
errno = EWOULDBLOCK;
return -1;
}
- if (hurd_condition_wait (&input->data_available, &input->lock))
+ if (pthread_hurd_cond_wait_np (&input->data_available, &input->lock))
{
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
errno = EINTR;
return -1;
}
@@ -256,9 +256,9 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data,
if (amount && input->full)
{
input->full = 0;
- condition_broadcast (&input->space_available);
+ pthread_cond_broadcast (&input->space_available);
}
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
return amount;
}
@@ -266,12 +266,12 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data,
/* Flush the input buffer, discarding all pending data. */
void input_flush (input_t input)
{
- mutex_lock (&input->lock);
+ pthread_mutex_lock (&input->lock);
input->size = 0;
if (input->full)
{
input->full = 0;
- condition_broadcast (&input->space_available);
+ pthread_cond_broadcast (&input->space_available);
}
- mutex_unlock (&input->lock);
+ pthread_mutex_unlock (&input->lock);
}
diff --git a/console/pager.c b/console/pager.c
index 092a8820..781ba35e 100644
--- a/console/pager.c
+++ b/console/pager.c
@@ -21,9 +21,10 @@
#include <errno.h>
#include <assert.h>
#include <error.h>
+#include <stdio.h>
#include <sys/mman.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/pager.h>
@@ -114,8 +115,8 @@ pager_dropweak (struct user_pager_info *upi)
/* A top-level function for the paging thread that just services paging
requests. */
-static void
-service_paging_requests (any_t arg)
+static void *
+service_paging_requests (void *arg)
{
struct port_bucket *pager_bucket = arg;
for (;;)
@@ -123,6 +124,7 @@ service_paging_requests (any_t arg)
pager_demuxer,
1000 * 60 * 2,
1000 * 60 * 10, 0);
+ return NULL;
}
@@ -130,14 +132,23 @@ service_paging_requests (any_t arg)
void
user_pager_init (void)
{
+ pthread_t thread;
+ error_t err;
+
/* Create the pager bucket, and start to serve paging requests. */
pager_bucket = ports_create_bucket ();
if (! pager_bucket)
error (5, errno, "Cannot create pager bucket");
/* Make a thread to service paging requests. */
- cthread_detach (cthread_fork ((cthread_fn_t) service_paging_requests,
- (any_t) pager_bucket));
+ err = pthread_create (&thread, NULL, service_paging_requests, pager_bucket);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
diff --git a/defpager/backing.c b/defpager/backing.c
index 5e6fbb65..24aab6df 100644
--- a/defpager/backing.c
+++ b/defpager/backing.c
@@ -36,7 +36,7 @@ size_t bmap_len;
/* Allocation rotor */
char *bmap_rotor;
-struct mutex bmap_lock;
+pthread_mutex_t bmap_lock = PTHREAD_MUTEX_INITIALIZER;
error_t
init_backing (char *name)
@@ -69,7 +69,7 @@ allocate_backing_page ()
int bit;
int pfn;
- mutex_lock (&bmap_lock);
+ pthread_mutex_lock (&bmap_lock);
wrapped = (bmap_rotor == bmap);
@@ -85,7 +85,7 @@ allocate_backing_page ()
if (wrapped == 2)
{
/* Didn't find one... */
- mutex_unlock (&bmap_lock);
+ pthread_mutex_unlock (&bmap_lock);
printf ("WARNING: Out of paging space; pageout failing.");
return 0;
}
@@ -101,7 +101,7 @@ allocate_backing_page ()
/* Return the correct offset */
pfn = (bmap_rotor - bmap) * 8 + bit;
- mutex_unlock (&bmap_lock);
+ pthread_mutex_unlock (&bmap_lock);
return pfn * (vm_page_size / store->block_size);
}
@@ -112,7 +112,7 @@ return_backing_pages (off_t *map, int maplen)
{
int i;
- mutex_lock (&bmap_lock);
+ pthread_mutex_lock (&bmap_lock);
for (i = 0; i < maplen; i++)
{
int pfn;
@@ -126,6 +126,6 @@ return_backing_pages (off_t *map, int maplen)
assert ((*b & (1 << bit)) == 0);
*b |= 1 << bit;
}
- mutex_unlock (&bmap_lock);
+ pthread_mutex_unlock (&bmap_lock);
}
diff --git a/exec/Makefile b/exec/Makefile
index 92b4d480..3fc82739 100644
--- a/exec/Makefile
+++ b/exec/Makefile
@@ -33,7 +33,8 @@ bzip2-objects = $(bzip2-sources:%.c=%.o)
target = exec
#targets = exec exec.static
#OTHERLIBS = -lbfd -liberty
-HURDLIBS = trivfs fshelp iohelp threads ports ihash shouldbeinlibc
+HURDLIBS = trivfs fshelp iohelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
exec-MIGSFLAGS = -imacros $(srcdir)/execmutations.h
diff --git a/exec/exec.c b/exec/exec.c
index 4c2fcec1..a4f2f748 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -47,7 +47,7 @@ mach_port_t procserver; /* Our proc port. */
mach_port_t *std_ports;
int *std_ints;
size_t std_nports, std_nints;
-struct rwlock std_lock = RWLOCK_INITIALIZER;
+pthread_rwlock_t std_lock = PTHREAD_RWLOCK_INITIALIZER;
#ifdef BFD
@@ -762,19 +762,19 @@ prepare (file_t file, struct execdata *e)
if (e->cntl)
while (1)
{
- spin_lock (&e->cntl->lock);
+ pthread_spin_lock (&e->cntl->lock);
switch (e->cntl->conch_status)
{
case USER_COULD_HAVE_CONCH:
e->cntl->conch_status = USER_HAS_CONCH;
case USER_HAS_CONCH:
- spin_unlock (&e->cntl->lock);
+ pthread_spin_unlock (&e->cntl->lock);
/* Break out of the loop. */
break;
case USER_RELEASE_CONCH:
case USER_HAS_NOT_CONCH:
default: /* Oops. */
- spin_unlock (&e->cntl->lock);
+ pthread_spin_unlock (&e->cntl->lock);
e->error = io_get_conch (e->file);
if (e->error)
return;
@@ -974,16 +974,16 @@ finish_mapping (struct execdata *e)
{
if (e->cntl != NULL)
{
- spin_lock (&e->cntl->lock);
+ pthread_spin_lock (&e->cntl->lock);
if (e->cntl->conch_status == USER_RELEASE_CONCH)
{
- spin_unlock (&e->cntl->lock);
+ pthread_spin_unlock (&e->cntl->lock);
io_release_conch (e->file);
}
else
{
e->cntl->conch_status = USER_HAS_NOT_CONCH;
- spin_unlock (&e->cntl->lock);
+ pthread_spin_unlock (&e->cntl->lock);
}
munmap (e->cntl, vm_page_size);
e->cntl = NULL;
@@ -1394,13 +1394,13 @@ do_exec (file_t file,
if (e->error == ENOEXEC)
{
/* See if it is a compressed image. */
- static struct mutex lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
/* The gzip code is really cheesy, not even close to thread-safe.
So we serialize all uses of it. */
- mutex_lock (&lock);
+ pthread_mutex_lock (&lock);
e->error = 0;
check_gzip (e);
- mutex_unlock (&lock);
+ pthread_mutex_unlock (&lock);
if (e->error == 0)
/* The file was uncompressed into memory, and now E describes the
uncompressed image rather than the actual file. Check it again
@@ -1412,13 +1412,13 @@ do_exec (file_t file,
if (e->error == ENOEXEC)
{
/* See if it is a compressed image. */
- static struct mutex lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
/* The bzip2 code is really cheesy, not even close to thread-safe.
So we serialize all uses of it. */
- mutex_lock (&lock);
+ pthread_mutex_lock (&lock);
e->error = 0;
check_bzip2 (e);
- mutex_unlock (&lock);
+ pthread_mutex_unlock (&lock);
if (e->error == 0)
/* The file was uncompressed into memory, and now E describes the
uncompressed image rather than the actual file. Check it again
@@ -1505,7 +1505,7 @@ do_exec (file_t file,
newtask = oldtask;
- rwlock_reader_lock (&std_lock);
+ pthread_rwlock_rdlock (&std_lock);
{
/* Store the data that we will give in response
to the RPC on the new task's bootstrap port. */
@@ -1550,7 +1550,7 @@ do_exec (file_t file,
if (boot == NULL)
{
stdout:
- rwlock_reader_unlock (&std_lock);
+ pthread_rwlock_unlock (&std_lock);
goto out;
}
bzero (&boot->pi + 1, (char *) &boot[1] - (char *) (&boot->pi + 1));
@@ -1675,7 +1675,7 @@ do_exec (file_t file,
&& boot->portarray[INIT_PORT_CWDIR] == MACH_PORT_NULL)
use (INIT_PORT_CWDIR, std_ports[INIT_PORT_CWDIR], 1, 0);
}
- rwlock_reader_unlock (&std_lock);
+ pthread_rwlock_unlock (&std_lock);
/* We have now concocted in BOOT the complete Hurd context (ports and
@@ -2192,7 +2192,7 @@ S_exec_setexecdata (struct trivfs_protid *protid,
return err;
}
- rwlock_writer_lock (&std_lock);
+ pthread_rwlock_wrlock (&std_lock);
if (std_ports)
{
@@ -2211,7 +2211,7 @@ S_exec_setexecdata (struct trivfs_protid *protid,
std_ints = ints;
std_nints = nints;
- rwlock_writer_unlock (&std_lock);
+ pthread_rwlock_unlock (&std_lock);
return 0;
}
diff --git a/exec/hashexec.c b/exec/hashexec.c
index 2aa3844b..e20a462e 100644
--- a/exec/hashexec.c
+++ b/exec/hashexec.c
@@ -205,7 +205,7 @@ check_hashbang (struct execdata *e,
user_crdir = user_cwdir = MACH_PORT_NULL;
- rwlock_reader_lock (&std_lock);
+ pthread_rwlock_rdlock (&std_lock);
/* Open a port on the interpreter file. */
e->error = lookup (interp, O_EXEC, &interp_file);
@@ -404,7 +404,7 @@ check_hashbang (struct execdata *e,
&setup_args, &fault_handler);
}
- rwlock_reader_unlock (&std_lock);
+ pthread_rwlock_unlock (&std_lock);
if (user_crdir != MACH_PORT_NULL)
mach_port_deallocate (mach_task_self (), user_crdir);
diff --git a/exec/priv.h b/exec/priv.h
index 7cee15e4..dbecb7a9 100644
--- a/exec/priv.h
+++ b/exec/priv.h
@@ -26,7 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <hurd/trivfs.h>
#include <hurd/ports.h>
#include <hurd/lookup.h>
-#include <rwlock.h>
+#include <pthread.h>
#ifdef BFD
#include <bfd.h>
@@ -186,7 +186,7 @@ void check_hashbang (struct execdata *e,
extern mach_port_t *std_ports;
extern int *std_ints;
extern size_t std_nports, std_nints;
-extern struct rwlock std_lock;
+extern pthread_rwlock_t std_lock;
#endif /* exec_priv_h */
diff --git a/ext2fs/Makefile b/ext2fs/Makefile
index 8e16ebe6..983dbee3 100644
--- a/ext2fs/Makefile
+++ b/ext2fs/Makefile
@@ -23,7 +23,8 @@ target = ext2fs
SRCS = balloc.c dir.c ext2fs.c getblk.c hyper.c ialloc.c \
inode.c pager.c pokel.c truncate.c storeinfo.c msg.c xinl.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = diskfs pager iohelp fshelp store threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs pager iohelp fshelp store ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/ext2fs/balloc.c b/ext2fs/balloc.c
index 7fe82ba0..b2d2eab9 100644
--- a/ext2fs/balloc.c
+++ b/ext2fs/balloc.c
@@ -63,14 +63,14 @@ ext2_free_blocks (block_t block, unsigned long count)
unsigned long i;
struct ext2_group_desc *gdp;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
if (block < sblock->s_first_data_block ||
(block + count) > sblock->s_blocks_count)
{
ext2_error ("freeing blocks not in datazone - "
"block = %u, count = %lu", block, count);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return;
}
@@ -122,7 +122,7 @@ ext2_free_blocks (block_t block, unsigned long count)
sblock_dirty = 1;
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
alloc_sync (0);
}
@@ -149,7 +149,7 @@ ext2_new_block (block_t goal,
static int goal_hits = 0, goal_attempts = 0;
#endif
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
#ifdef XXX /* Auth check to use reserved blocks */
if (sblock->s_free_blocks_count <= sblock->s_r_blocks_count &&
@@ -157,7 +157,7 @@ ext2_new_block (block_t goal,
(sb->u.ext2_sb.s_resgid == 0 ||
!in_group_p (sb->u.ext2_sb.s_resgid))))
{
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return 0;
}
#endif
@@ -264,7 +264,7 @@ repeat:
}
if (k >= groups_count)
{
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return 0;
}
bh = bptr (gdp->bg_block_bitmap);
@@ -278,7 +278,7 @@ repeat:
if (j >= sblock->s_blocks_per_group)
{
ext2_error ("free blocks count corrupted for block group %d", i);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return 0;
}
@@ -312,9 +312,9 @@ got_block:
block is being allocated to a file (see pager.c). */
if (modified_global_blocks)
{
- spin_lock (&modified_global_blocks_lock);
+ pthread_spin_lock (&modified_global_blocks_lock);
clear_bit (tmp, modified_global_blocks);
- spin_unlock (&modified_global_blocks_lock);
+ pthread_spin_unlock (&modified_global_blocks_lock);
}
ext2_debug ("found bit %d", j);
@@ -337,9 +337,9 @@ got_block:
/* (See comment before the clear_bit above) */
if (modified_global_blocks)
{
- spin_lock (&modified_global_blocks_lock);
+ pthread_spin_lock (&modified_global_blocks_lock);
clear_bit (tmp + k, modified_global_blocks);
- spin_unlock (&modified_global_blocks_lock);
+ pthread_spin_unlock (&modified_global_blocks_lock);
}
}
gdp->bg_free_blocks_count -= *prealloc_count;
@@ -369,7 +369,7 @@ got_block:
sblock_dirty = 1;
sync_out:
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
alloc_sync (0);
return j;
@@ -383,7 +383,7 @@ ext2_count_free_blocks ()
struct ext2_group_desc *gdp;
int i;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
desc_count = 0;
bitmap_count = 0;
@@ -399,7 +399,7 @@ ext2_count_free_blocks ()
}
printf ("ext2_count_free_blocks: stored = %u, computed = %lu, %lu",
sblock->s_free_blocks_count, desc_count, bitmap_count);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return bitmap_count;
#else
return sblock->s_free_blocks_count;
@@ -422,7 +422,7 @@ ext2_check_blocks_bitmap ()
struct ext2_group_desc *gdp;
int i, j;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
desc_count = 0;
bitmap_count = 0;
@@ -489,5 +489,5 @@ ext2_check_blocks_bitmap ()
ext2_error ("wrong free blocks count in super block,"
" stored = %lu, counted = %lu",
(unsigned long) sblock->s_free_blocks_count, bitmap_count);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
}
diff --git a/ext2fs/dir.c b/ext2fs/dir.c
index 714c1b7c..3a3e648d 100644
--- a/ext2fs/dir.c
+++ b/ext2fs/dir.c
@@ -278,9 +278,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Drop what we *thought* was .. (but isn't any more) and
try *again*. */
diskfs_nput (np);
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
@@ -293,9 +293,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Lock them in the proper order, and then
repeat the directory scan to see if this is still
right. */
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
diff --git a/ext2fs/ext2fs.c b/ext2fs/ext2fs.c
index 0857a749..993f1997 100644
--- a/ext2fs/ext2fs.c
+++ b/ext2fs/ext2fs.c
@@ -193,7 +193,7 @@ main (int argc, char **argv)
ext2_panic ("can't get root: %s", strerror (err));
else if ((diskfs_root_node->dn_stat.st_mode & S_IFMT) == 0)
ext2_panic ("no root node!");
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
/* Now that we are all set up to handle requests, and diskfs_root_node is
set properly, it is safe to export our fsys control port to the
@@ -201,7 +201,7 @@ main (int argc, char **argv)
diskfs_startup_diskfs (bootstrap, 0);
/* and so we die, leaving others to do the real work. */
- cthread_exit (0);
+ pthread_exit (NULL);
/* NOTREACHED */
return 0;
}
diff --git a/ext2fs/ext2fs.h b/ext2fs/ext2fs.h
index 2ad4a9df..52bf2b19 100644
--- a/ext2fs/ext2fs.h
+++ b/ext2fs/ext2fs.h
@@ -25,7 +25,7 @@
#include <hurd/iohelp.h>
#include <hurd/diskfs.h>
#include <assert.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <sys/mman.h>
#define __hurd__ /* Enable some hurd-specific fields. */
@@ -80,7 +80,7 @@ struct poke
struct pokel
{
struct poke *pokes, *free_pokes;
- spin_lock_t lock;
+ pthread_spinlock_t lock;
struct pager *pager;
void *image;
};
@@ -161,7 +161,7 @@ struct disknode
struct node *hnext, **hprevp;
/* Lock to lock while fiddling with this inode's block allocation info. */
- struct rwlock alloc_lock;
+ pthread_rwlock_t alloc_lock;
/* Where changes to our indirect blocks are added. */
struct pokel indir_pokel;
@@ -268,9 +268,9 @@ unsigned long groups_count; /* Number of groups in the fs */
/* ---------------------------------------------------------------- */
-spin_lock_t node_to_page_lock;
+pthread_spinlock_t node_to_page_lock;
-spin_lock_t generation_lock;
+pthread_spinlock_t generation_lock;
unsigned long next_generation;
/* ---------------------------------------------------------------- */
@@ -335,7 +335,7 @@ void inode_init (void);
/* What to lock if changing global data data (e.g., the superblock or block
group descriptors or bitmaps). */
-spin_lock_t global_lock;
+pthread_spinlock_t global_lock;
/* Where to record such changes. */
struct pokel global_pokel;
@@ -344,7 +344,7 @@ struct pokel global_pokel;
record which disk blocks are actually modified, so we don't stomp on parts
of the disk which are backed by file pagers. */
char *modified_global_blocks;
-spin_lock_t modified_global_blocks_lock;
+pthread_spinlock_t modified_global_blocks_lock;
extern int global_block_modified (block_t block);
extern void record_global_poke (void *ptr);
@@ -364,9 +364,9 @@ global_block_modified (block_t block)
if (modified_global_blocks)
{
int was_clean;
- spin_lock (&modified_global_blocks_lock);
+ pthread_spin_lock (&modified_global_blocks_lock);
was_clean = !set_bit(block, modified_global_blocks);
- spin_unlock (&modified_global_blocks_lock);
+ pthread_spin_unlock (&modified_global_blocks_lock);
return was_clean;
}
else
diff --git a/ext2fs/ialloc.c b/ext2fs/ialloc.c
index 15c17a4e..aa018d94 100644
--- a/ext2fs/ialloc.c
+++ b/ext2fs/ialloc.c
@@ -62,12 +62,12 @@ diskfs_free_node (struct node *np, mode_t old_mode)
ext2_debug ("freeing inode %u", inum);
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
if (inum < EXT2_FIRST_INO (sblock) || inum > sblock->s_inodes_count)
{
ext2_error ("reserved inode or nonexistent inode: %Ld", inum);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return;
}
@@ -92,7 +92,7 @@ diskfs_free_node (struct node *np, mode_t old_mode)
}
sblock_dirty = 1;
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
alloc_sync(0);
}
@@ -116,7 +116,7 @@ ext2_alloc_inode (ino_t dir_inum, mode_t mode)
struct ext2_group_desc *gdp;
struct ext2_group_desc *tmp;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
repeat:
gdp = NULL;
@@ -209,7 +209,7 @@ repeat:
if (!gdp)
{
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return 0;
}
@@ -254,7 +254,7 @@ repeat:
sblock_dirty = 1;
sync_out:
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
alloc_sync (0);
return inum;
@@ -323,12 +323,12 @@ diskfs_alloc_node (struct node *dir, mode_t mode, struct node **node)
/*
* Set up a new generation number for this inode.
*/
- spin_lock (&generation_lock);
+ pthread_spin_lock (&generation_lock);
sex = diskfs_mtime->seconds;
if (++next_generation < (u_long)sex)
next_generation = sex;
st->st_gen = next_generation;
- spin_unlock (&generation_lock);
+ pthread_spin_unlock (&generation_lock);
alloc_sync (np);
@@ -346,7 +346,7 @@ ext2_count_free_inodes ()
struct ext2_group_desc *gdp;
int i;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
desc_count = 0;
bitmap_count = 0;
@@ -363,7 +363,7 @@ ext2_count_free_inodes ()
}
ext2_debug ("stored = %u, computed = %lu, %lu",
sblock->s_free_inodes_count, desc_count, bitmap_count);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
return desc_count;
#else
return sblock->s_free_inodes_count;
@@ -379,7 +379,7 @@ ext2_check_inodes_bitmap ()
struct ext2_group_desc *gdp;
unsigned long desc_count, bitmap_count, x;
- spin_lock (&global_lock);
+ pthread_spin_lock (&global_lock);
desc_count = 0;
bitmap_count = 0;
@@ -401,5 +401,5 @@ ext2_check_inodes_bitmap ()
"stored = %lu, counted = %lu",
(unsigned long) sblock->s_free_inodes_count, bitmap_count);
- spin_unlock (&global_lock);
+ pthread_spin_unlock (&global_lock);
}
diff --git a/ext2fs/inode.c b/ext2fs/inode.c
index 2da8a95e..2c442795 100644
--- a/ext2fs/inode.c
+++ b/ext2fs/inode.c
@@ -50,7 +50,7 @@ static struct node *nodehash[INOHSZ];
static error_t read_node (struct node *np);
-spin_lock_t generation_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t generation_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Initialize the inode hash table. */
void
@@ -70,13 +70,13 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
struct node *np;
struct disknode *dn;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
if (np->cache_id == inum)
{
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -85,20 +85,20 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
dn = malloc (sizeof (struct disknode));
if (! dn)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return ENOMEM;
}
dn->dirents = 0;
dn->dir_idx = 0;
dn->pager = 0;
- rwlock_init (&dn->alloc_lock);
+ pthread_rwlock_init (&dn->alloc_lock, NULL);
pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image);
/* Create the new node. */
np = diskfs_make_node (dn);
np->cache_id = inum;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* Put NP in NODEHASH. */
dn->hnext = nodehash[INOHASH(inum)];
@@ -107,18 +107,18 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
dn->hprevp = &nodehash[INOHASH(inum)];
nodehash[INOHASH(inum)] = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
/* Get the contents of NP off disk. */
err = read_node (np);
if (!diskfs_check_readonly () && !np->dn_stat.st_gen)
{
- spin_lock (&generation_lock);
+ pthread_spin_lock (&generation_lock);
if (++next_generation < diskfs_mtime->seconds)
next_generation = diskfs_mtime->seconds;
np->dn_stat.st_gen = next_generation;
- spin_unlock (&generation_lock);
+ pthread_spin_unlock (&generation_lock);
np->dn_set_ctime = 1;
}
@@ -138,14 +138,14 @@ ifind (ino_t inum)
{
struct node *np;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->cache_id != inum)
continue;
assert (np->references);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return np;
}
assert (0);
@@ -540,7 +540,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
int n, num_nodes = 0;
struct node *node, **node_list, **p;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
/* We must copy everything from the hash table into another data structure
to avoid running into any problems with the hash-table being modified
@@ -557,7 +557,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
node_list = malloc (num_nodes * sizeof (struct node *));
if (node_list == NULL)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
ext2_debug ("unable to allocate temporary node table");
return ENOMEM;
}
@@ -570,7 +570,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
node->references++;
}
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
p = node_list;
while (num_nodes-- > 0)
@@ -578,9 +578,9 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
node = *p++;
if (!err)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
err = (*fun)(node);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
diskfs_nrele (node);
}
diff --git a/ext2fs/msg.c b/ext2fs/msg.c
index 727d926d..83939b06 100644
--- a/ext2fs/msg.c
+++ b/ext2fs/msg.c
@@ -23,16 +23,17 @@
#include "ext2fs.h"
-struct mutex printf_lock = MUTEX_INITIALIZER; /* XXX */
+pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER; /* XXX */
+
int printf (const char *fmt, ...)
{
va_list arg;
int done;
va_start (arg, fmt);
- mutex_lock (&printf_lock);
+ pthread_mutex_lock (&printf_lock);
done = vprintf (fmt, arg);
- mutex_unlock (&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
va_end (arg);
return done;
}
@@ -43,7 +44,7 @@ void _ext2_error (const char * function, const char * fmt, ...)
{
va_list args;
- mutex_lock(&printf_lock);
+ pthread_mutex_lock (&printf_lock);
va_start (args, fmt);
vsprintf (error_buf, fmt, args);
@@ -51,14 +52,14 @@ void _ext2_error (const char * function, const char * fmt, ...)
fprintf (stderr, "ext2fs: %s: %s: %s\n", diskfs_disk_name, function, error_buf);
- mutex_unlock(&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
}
void _ext2_panic (const char * function, const char * fmt, ...)
{
va_list args;
- mutex_lock(&printf_lock);
+ pthread_mutex_lock (&printf_lock);
va_start (args, fmt);
vsprintf (error_buf, fmt, args);
@@ -67,7 +68,7 @@ void _ext2_panic (const char * function, const char * fmt, ...)
fprintf(stderr, "ext2fs: %s: panic: %s: %s\n",
diskfs_disk_name, function, error_buf);
- mutex_unlock(&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
exit (1);
}
@@ -76,7 +77,7 @@ void ext2_warning (const char * fmt, ...)
{
va_list args;
- mutex_lock(&printf_lock);
+ pthread_mutex_lock (&printf_lock);
va_start (args, fmt);
vsprintf (error_buf, fmt, args);
@@ -84,5 +85,5 @@ void ext2_warning (const char * fmt, ...)
fprintf (stderr, "ext2fs: %s: warning: %s\n", diskfs_disk_name, error_buf);
- mutex_unlock(&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
}
diff --git a/ext2fs/pager.c b/ext2fs/pager.c
index 0136f9b1..f740434a 100644
--- a/ext2fs/pager.c
+++ b/ext2fs/pager.c
@@ -29,7 +29,8 @@ struct port_bucket *pager_bucket;
/* Mapped image of the disk. */
void *disk_image;
-spin_lock_t node_to_page_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t node_to_page_lock = PTHREAD_SPINLOCK_INITIALIZER;
+
#ifdef DONT_CACHE_MEMORY_OBJECTS
#define MAY_CACHE 0
@@ -42,7 +43,7 @@ spin_lock_t node_to_page_lock = SPIN_LOCK_INITIALIZER;
#ifdef STATS
struct ext2fs_pager_stats
{
- spin_lock_t lock;
+ pthread_spinlock_t lock;
unsigned long disk_pageins;
unsigned long disk_pageouts;
@@ -58,12 +59,13 @@ struct ext2fs_pager_stats
unsigned long file_grows;
};
-static struct ext2fs_pager_stats ext2s_pager_stats;
+static struct ext2fs_pager_stats ext2s_pager_stats =
+ { .lock = PTHREAD_SPINLOCK_INITIALIZER };
#define STAT_INC(field) \
-do { spin_lock (&ext2s_pager_stats.lock); \
+do { pthread_spin_lock (&ext2s_pager_stats.lock); \
ext2s_pager_stats.field++; \
- spin_unlock (&ext2s_pager_stats.lock); } while (0)
+ pthread_spin_unlock (&ext2s_pager_stats.lock); } while (0)
#else /* !STATS */
#define STAT_INC(field) /* nop */0
@@ -75,12 +77,12 @@ do { spin_lock (&ext2s_pager_stats.lock); \
static void *
get_page_buf ()
{
- static struct mutex free_page_bufs_lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t free_page_bufs_lock = PTHREAD_MUTEX_INITIALIZER;
static void *free_page_bufs;
static int num_free_page_bufs;
void *buf;
- mutex_lock (&free_page_bufs_lock);
+ pthread_mutex_lock (&free_page_bufs_lock);
if (num_free_page_bufs > 0)
{
buf = free_page_bufs;
@@ -106,7 +108,7 @@ get_page_buf ()
}
}
- mutex_unlock (&free_page_bufs_lock);
+ pthread_mutex_unlock (&free_page_bufs_lock);
return buf;
}
@@ -124,14 +126,14 @@ free_page_buf (void *buf)
on success otherwise an error code. */
static error_t
find_block (struct node *node, vm_offset_t offset,
- block_t *block, struct rwlock **lock)
+ block_t *block, pthread_rwlock_t **lock)
{
error_t err;
if (!*lock)
{
*lock = &node->dn->alloc_lock;
- rwlock_reader_lock (*lock);
+ pthread_rwlock_rdlock (*lock);
}
if (offset + block_size > node->allocsize)
@@ -158,7 +160,7 @@ file_pager_read_page (struct node *node, vm_offset_t page,
error_t err;
int offs = 0;
int partial = 0; /* A page truncated by the EOF. */
- struct rwlock *lock = NULL;
+ pthread_rwlock_t *lock = NULL;
int left = vm_page_size;
block_t pending_blocks = 0;
int num_pending_blocks = 0;
@@ -271,7 +273,7 @@ file_pager_read_page (struct node *node, vm_offset_t page,
node->dn->last_page_partially_writable = 1;
if (lock)
- rwlock_reader_unlock (lock);
+ pthread_rwlock_unlock (lock);
return err;
}
@@ -365,7 +367,7 @@ file_pager_write_page (struct node *node, vm_offset_t offset, void *buf)
{
error_t err = 0;
struct pending_blocks pb;
- struct rwlock *lock = &node->dn->alloc_lock;
+ pthread_rwlock_t *lock = &node->dn->alloc_lock;
block_t block;
int left = vm_page_size;
@@ -374,7 +376,7 @@ file_pager_write_page (struct node *node, vm_offset_t offset, void *buf)
/* Holding NODE->dn->alloc_lock effectively locks NODE->allocsize,
at least for the cases we care about: pager_unlock_page,
diskfs_grow and diskfs_truncate. */
- rwlock_reader_lock (&node->dn->alloc_lock);
+ pthread_rwlock_rdlock (&node->dn->alloc_lock);
if (offset >= node->allocsize)
left = 0;
@@ -399,7 +401,7 @@ file_pager_write_page (struct node *node, vm_offset_t offset, void *buf)
if (!err)
pending_blocks_write (&pb);
- rwlock_reader_unlock (&node->dn->alloc_lock);
+ pthread_rwlock_unlock (&node->dn->alloc_lock);
return err;
}
@@ -525,7 +527,7 @@ pager_unlock_page (struct user_pager_info *pager, vm_offset_t page)
struct node *node = pager->node;
struct disknode *dn = node->dn;
- rwlock_writer_lock (&dn->alloc_lock);
+ pthread_rwlock_wrlock (&dn->alloc_lock);
partial_page = (page + vm_page_size > node->allocsize);
@@ -567,7 +569,7 @@ pager_unlock_page (struct user_pager_info *pager, vm_offset_t page)
STAT_INC (file_page_unlocks);
- rwlock_writer_unlock (&dn->alloc_lock);
+ pthread_rwlock_unlock (&dn->alloc_lock);
if (err == ENOSPC)
ext2_warning ("This filesystem is out of space, and will now crash. Bye!");
@@ -598,7 +600,7 @@ diskfs_grow (struct node *node, off_t size, struct protid *cred)
block_t new_end_block;
struct disknode *dn = node->dn;
- rwlock_writer_lock (&dn->alloc_lock);
+ pthread_rwlock_wrlock (&dn->alloc_lock);
old_size = node->allocsize;
new_size = round_block (size);
@@ -665,7 +667,7 @@ diskfs_grow (struct node *node, off_t size, struct protid *cred)
node->allocsize = new_size;
- rwlock_writer_unlock (&dn->alloc_lock);
+ pthread_rwlock_unlock (&dn->alloc_lock);
return err;
}
@@ -680,11 +682,11 @@ diskfs_file_update (struct node *node, int wait)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -704,11 +706,11 @@ flush_node_pager (struct node *node)
struct pager *pager;
struct disknode *dn = node->dn;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -745,11 +747,11 @@ pager_clear_user_data (struct user_pager_info *upi)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = upi->node->dn->pager;
if (pager && pager_get_upi (pager) == upi)
upi->node->dn->pager = 0;
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
diskfs_nrele_light (upi->node);
}
@@ -789,7 +791,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
|| S_ISREG (node->dn_stat.st_mode)
|| (S_ISLNK (node->dn_stat.st_mode)));
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
do
{
struct pager *pager = node->dn->pager;
@@ -820,7 +822,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
{
diskfs_nrele_light (node);
free (upi);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
return MACH_PORT_NULL;
}
@@ -829,7 +831,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
}
}
while (right == MACH_PORT_NULL);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
mach_port_insert_right (mach_task_self (), right, right,
MACH_MSG_TYPE_MAKE_SEND);
@@ -844,11 +846,11 @@ drop_pager_softrefs (struct node *node)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (MAY_CACHE && pager)
{
@@ -866,11 +868,11 @@ allow_pager_softrefs (struct node *node)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (MAY_CACHE && pager)
pager_change_attributes (pager, 1, MEMORY_OBJECT_COPY_DELAY, 0);
diff --git a/ext2fs/pokel.c b/ext2fs/pokel.c
index 85b4d2d1..a8b16c97 100644
--- a/ext2fs/pokel.c
+++ b/ext2fs/pokel.c
@@ -25,7 +25,7 @@
void
pokel_init (struct pokel *pokel, struct pager *pager, void *image)
{
- pokel->lock = SPIN_LOCK_INITIALIZER;
+ pokel->lock = PTHREAD_SPINLOCK_INITIALIZER;
pokel->pokes = NULL;
pokel->free_pokes = NULL;
pokel->pager = pager;
@@ -59,7 +59,7 @@ pokel_add (struct pokel *pokel, void *loc, vm_size_t length)
ext2_debug ("adding %p[%ul] (range 0x%x to 0x%x)", loc, length, offset, end);
- spin_lock (&pokel->lock);
+ pthread_spin_lock (&pokel->lock);
pl = pokel->pokes;
while (pl != NULL)
@@ -97,7 +97,7 @@ pokel_add (struct pokel *pokel, void *loc, vm_size_t length)
pokel->pokes = pl;
}
- spin_unlock (&pokel->lock);
+ pthread_spin_unlock (&pokel->lock);
}
/* Move all pending pokes from POKEL into its free list. If SYNC is true,
@@ -107,10 +107,10 @@ _pokel_exec (struct pokel *pokel, int sync, int wait)
{
struct poke *pl, *pokes, *last = NULL;
- spin_lock (&pokel->lock);
+ pthread_spin_lock (&pokel->lock);
pokes = pokel->pokes;
pokel->pokes = NULL;
- spin_unlock (&pokel->lock);
+ pthread_spin_unlock (&pokel->lock);
for (pl = pokes; pl; last = pl, pl = pl->next)
if (sync)
@@ -121,10 +121,10 @@ _pokel_exec (struct pokel *pokel, int sync, int wait)
if (last)
{
- spin_lock (&pokel->lock);
+ pthread_spin_lock (&pokel->lock);
last->next = pokel->free_pokes;
pokel->free_pokes = pokes;
- spin_unlock (&pokel->lock);
+ pthread_spin_unlock (&pokel->lock);
}
}
@@ -152,13 +152,13 @@ pokel_inherit (struct pokel *pokel, struct pokel *from)
assert (pokel->image == from->image);
/* Take all pokes from FROM... */
- spin_lock (&from->lock);
+ pthread_spin_lock (&from->lock);
pokes = from->pokes;
from->pokes = NULL;
- spin_unlock (&from->lock);
+ pthread_spin_unlock (&from->lock);
/* And put them in POKEL. */
- spin_lock (&pokel->lock);
+ pthread_spin_lock (&pokel->lock);
last = pokel->pokes;
if (last)
{
@@ -168,5 +168,5 @@ pokel_inherit (struct pokel *pokel, struct pokel *from)
}
else
pokel->pokes = pokes;
- spin_unlock (&pokel->lock);
+ pthread_spin_unlock (&pokel->lock);
}
diff --git a/ext2fs/storeinfo.c b/ext2fs/storeinfo.c
index 395ab5ca..5d21b05e 100644
--- a/ext2fs/storeinfo.c
+++ b/ext2fs/storeinfo.c
@@ -45,7 +45,7 @@ diskfs_S_file_get_storage_info (struct protid *cred,
if (! runs)
return ENOMEM;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
/* NUM_FS_BLOCKS counts down the blocks in the file that we've not
enumerated yet; when it hits zero, we can stop. */
@@ -100,7 +100,7 @@ diskfs_S_file_get_storage_info (struct protid *cred,
run->length += 1 << log2_dev_blocks_per_fs_block;
}
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
if (! err)
err = store_clone (store, &file_store);
diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c
index 2058a1c1..37e360bb 100644
--- a/ext2fs/truncate.c
+++ b/ext2fs/truncate.c
@@ -224,11 +224,11 @@ force_delayed_copies (struct node *node, off_t length)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -254,11 +254,11 @@ enable_delayed_copies (struct node *node)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -317,7 +317,7 @@ diskfs_truncate (struct node *node, off_t length)
force_delayed_copies (node, length);
- rwlock_writer_lock (&node->dn->alloc_lock);
+ pthread_rwlock_wrlock (&node->dn->alloc_lock);
/* Update the size on disk; fsck will finish freeing blocks if necessary
should we crash. */
@@ -363,7 +363,7 @@ diskfs_truncate (struct node *node, off_t length)
/* Now we can permit delayed copies again. */
enable_delayed_copies (node);
- rwlock_writer_unlock (&node->dn->alloc_lock);
+ pthread_rwlock_unlock (&node->dn->alloc_lock);
return err;
}
diff --git a/fatfs/Makefile b/fatfs/Makefile
index 24dcab12..c673b1ba 100644
--- a/fatfs/Makefile
+++ b/fatfs/Makefile
@@ -22,7 +22,8 @@ target = fatfs
SRCS = inode.c main.c dir.c pager.c fat.c virt-inode.c node-create.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = diskfs iohelp fshelp store pager threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/fatfs/dir.c b/fatfs/dir.c
index 762320f8..b2b7d7e4 100644
--- a/fatfs/dir.c
+++ b/fatfs/dir.c
@@ -314,9 +314,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Drop what we *thought* was .. (but isn't any more) and
try *again*. */
diskfs_nput (np);
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup_in_dirbuf (inum, &np, buf);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
@@ -329,9 +329,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Lock them in the proper order, and then
repeat the directory scan to see if this is still
right. */
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup_in_dirbuf (inum, &np, buf);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
diff --git a/fatfs/fat.c b/fatfs/fat.c
index 1d110c40..14926ff3 100644
--- a/fatfs/fat.c
+++ b/fatfs/fat.c
@@ -51,10 +51,10 @@ size_t first_fat_sector;
cluster_t nr_of_clusters;
/* Hold this lock while converting times using gmtime. */
-spin_lock_t epoch_to_time_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t epoch_to_time_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Hold this lock while allocating a new cluster in the FAT. */
-spin_lock_t allocate_free_cluster_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t allocate_free_cluster_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Where to look for the next free cluster. This is meant to avoid
searching through a nearly full file system from the beginning at
@@ -323,7 +323,7 @@ fat_allocate_cluster (cluster_t content, cluster_t *cluster)
assert (content != FAT_FREE_CLUSTER);
- spin_lock (&allocate_free_cluster_lock);
+ pthread_spin_lock (&allocate_free_cluster_lock);
old_next_free_cluster = next_free_cluster;
/* Loop over all clusters, starting from next_free_cluster and
@@ -356,7 +356,7 @@ fat_allocate_cluster (cluster_t content, cluster_t *cluster)
else
err = ENOSPC;
- spin_unlock(&allocate_free_cluster_lock);
+ pthread_spin_unlock (&allocate_free_cluster_lock);
return err;
}
@@ -390,14 +390,14 @@ fat_extend_chain (struct node *node, cluster_t new_last_cluster, int create)
return 0;
}
- spin_lock(&dn->chain_extension_lock);
+ pthread_spin_lock (&dn->chain_extension_lock);
/* If we already have what we need, or we have all clusters that are
available without allocating new ones, go out. */
if (new_last_cluster < dn->length_of_chain
|| (!create && dn->chain_complete))
{
- spin_unlock(&dn->chain_extension_lock);
+ pthread_spin_unlock (&dn->chain_extension_lock);
return 0;
}
@@ -460,7 +460,7 @@ fat_extend_chain (struct node *node, cluster_t new_last_cluster, int create)
if (dn->length_of_chain << log2_bytes_per_cluster > node->allocsize)
node->allocsize = dn->length_of_chain << log2_bytes_per_cluster;
- spin_unlock(&dn->chain_extension_lock);
+ pthread_spin_unlock (&dn->chain_extension_lock);
return err;
}
@@ -739,7 +739,7 @@ fat_from_epoch (char *date, char *time, time_t *tp)
{
struct tm *tm;
- spin_lock(&epoch_to_time_lock);
+ pthread_spin_lock (&epoch_to_time_lock);
tm = gmtime (tp);
/* Date format:
@@ -757,5 +757,5 @@ fat_from_epoch (char *date, char *time, time_t *tp)
| ((tm->tm_year - 80) << 9));
write_word(time, (tm->tm_hour << 11) | (tm->tm_min << 5)
| (tm->tm_sec >> 1));
- spin_unlock(&epoch_to_time_lock);
+ pthread_spin_unlock (&epoch_to_time_lock);
}
diff --git a/fatfs/fatfs.h b/fatfs/fatfs.h
index 16b058a8..06955a4a 100644
--- a/fatfs/fatfs.h
+++ b/fatfs/fatfs.h
@@ -45,7 +45,7 @@ struct disknode
/* The directory that hold this file, always hold a reference. */
struct node *dirnode;
- struct rwlock dirent_lock;
+ pthread_rwlock_t dirent_lock;
char *link_target; /* For S_ISLNK. */
@@ -54,11 +54,11 @@ struct disknode
/* Lock to hold while fiddling with this inode's block allocation
info. */
- struct rwlock alloc_lock;
+ pthread_rwlock_t alloc_lock;
/* Lock to hold while extending this inode's block allocation info.
Hold only if you hold readers alloc_lock, then you don't need to
hold it if you hold writers alloc_lock already. */
- spin_lock_t chain_extension_lock;
+ pthread_spinlock_t chain_extension_lock;
struct cluster_chain *first;
struct cluster_chain *last;
cluster_t length_of_chain;
diff --git a/fatfs/inode.c b/fatfs/inode.c
index 2a427933..e3ca09d5 100644
--- a/fatfs/inode.c
+++ b/fatfs/inode.c
@@ -65,13 +65,13 @@ diskfs_cached_lookup (ino64_t inum, struct node **npp)
struct node *np;
struct disknode *dn;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
if (np->cache_id == inum)
{
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -80,7 +80,7 @@ diskfs_cached_lookup (ino64_t inum, struct node **npp)
dn = malloc (sizeof (struct disknode));
if (! dn)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return ENOMEM;
}
dn->pager = 0;
@@ -88,16 +88,16 @@ diskfs_cached_lookup (ino64_t inum, struct node **npp)
dn->last = 0;
dn->length_of_chain = 0;
dn->chain_complete = 0;
- dn->chain_extension_lock = SPIN_LOCK_INITIALIZER;
- rwlock_init (&dn->alloc_lock);
- rwlock_init (&dn->dirent_lock);
+ dn->chain_extension_lock = PTHREAD_SPINLOCK_INITIALIZER;
+ pthread_rwlock_init (&dn->alloc_lock, NULL);
+ pthread_rwlock_init (&dn->dirent_lock, NULL);
/* Create the new node. */
np = diskfs_make_node (dn);
np->cache_id = inum;
np->dn->inode = vi_lookup(inum);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* Put NP in NODEHASH. */
dn->hnext = nodehash[INOHASH(inum)];
@@ -106,7 +106,7 @@ diskfs_cached_lookup (ino64_t inum, struct node **npp)
dn->hprevp = &nodehash[INOHASH(inum)];
nodehash[INOHASH(inum)] = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
/* Get the contents of NP off disk. */
err = read_node (np, 0);
@@ -130,13 +130,13 @@ diskfs_cached_lookup_in_dirbuf (int inum, struct node **npp, vm_address_t buf)
struct node *np;
struct disknode *dn;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
if (np->cache_id == inum)
{
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -145,7 +145,7 @@ diskfs_cached_lookup_in_dirbuf (int inum, struct node **npp, vm_address_t buf)
dn = malloc (sizeof (struct disknode));
if (! dn)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return ENOMEM;
}
dn->pager = 0;
@@ -153,16 +153,16 @@ diskfs_cached_lookup_in_dirbuf (int inum, struct node **npp, vm_address_t buf)
dn->last = 0;
dn->length_of_chain = 0;
dn->chain_complete = 0;
- dn->chain_extension_lock = SPIN_LOCK_INITIALIZER;
- rwlock_init (&dn->alloc_lock);
- rwlock_init (&dn->dirent_lock);
+ dn->chain_extension_lock = PTHREAD_SPINLOCK_INITIALIZER;
+ pthread_rwlock_init (&dn->alloc_lock, NULL);
+ pthread_rwlock_init (&dn->dirent_lock, NULL);
/* Create the new node. */
np = diskfs_make_node (dn);
np->cache_id = inum;
np->dn->inode = vi_lookup(inum);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* Put NP in NODEHASH. */
dn->hnext = nodehash[INOHASH(inum)];
@@ -171,7 +171,7 @@ diskfs_cached_lookup_in_dirbuf (int inum, struct node **npp, vm_address_t buf)
dn->hprevp = &nodehash[INOHASH(inum)];
nodehash[INOHASH(inum)] = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
/* Get the contents of NP off disk. */
err = read_node (np, buf);
@@ -192,14 +192,14 @@ ifind (ino_t inum)
{
struct node *np;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->cache_id != inum)
continue;
assert (np->references);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return np;
}
assert (0);
@@ -230,9 +230,9 @@ diskfs_node_norefs (struct node *np)
all references to the node have been deleted. */
if (np->dn->dirnode)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
diskfs_nrele (np->dn->dirnode);
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
}
assert (!np->dn->pager);
@@ -336,7 +336,7 @@ read_node (struct node *np, vm_address_t buf)
if (dp)
dp->references++;
- rwlock_reader_lock(&np->dn->dirent_lock);
+ pthread_rwlock_rdlock (&np->dn->dirent_lock);
dn->start_cluster = (read_word (dr->first_cluster_high) << 16)
+ read_word (dr->first_cluster_low);
@@ -355,9 +355,9 @@ read_node (struct node *np, vm_address_t buf)
else
{
np->allocsize = 0;
- rwlock_reader_lock(&dn->alloc_lock);
+ pthread_rwlock_rdlock (&dn->alloc_lock);
err = fat_extend_chain (np, FAT_EOC, 0);
- rwlock_reader_unlock(&dn->alloc_lock);
+ pthread_rwlock_unlock (&dn->alloc_lock);
if (err)
{
if (our_buf && buf)
@@ -391,7 +391,7 @@ read_node (struct node *np, vm_address_t buf)
st->st_blksize = bytes_per_sector;
st->st_blocks = (st->st_size - 1) / bytes_per_sector + 1;
- rwlock_reader_unlock(&np->dn->dirent_lock);
+ pthread_rwlock_unlock (&np->dn->dirent_lock);
if (our_buf && buf)
munmap ((caddr_t) buf, buflen);
@@ -482,14 +482,14 @@ write_node (struct node *np)
dp = np->dn->dirnode;
assert (dp);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
/* Map in the directory contents. */
memobj = diskfs_get_filemap (dp, prot);
if (memobj == MACH_PORT_NULL)
{
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
/* FIXME: We shouldn't ignore this error. */
return;
}
@@ -501,7 +501,7 @@ write_node (struct node *np)
dr = (struct dirrect *) (buf + vk.dir_offset);
- rwlock_writer_lock(&np->dn->dirent_lock);
+ pthread_rwlock_wrlock (&np->dn->dirent_lock);
write_word (dr->first_cluster_low, np->dn->start_cluster & 0xffff);
write_word (dr->first_cluster_high, np->dn->start_cluster >> 16);
@@ -511,11 +511,11 @@ write_node (struct node *np)
fat_from_epoch ((unsigned char *) &dr->write_date,
(unsigned char *) &dr->write_time, &st->st_mtime);
- rwlock_writer_unlock(&np->dn->dirent_lock);
+ pthread_rwlock_unlock (&np->dn->dirent_lock);
np->dn_stat_dirty = 0;
munmap ((caddr_t) buf, buflen);
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
}
}
@@ -548,7 +548,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
int n, num_nodes = 0;
struct node *node, **node_list, **p;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
/* We must copy everything from the hash table into another data structure
to avoid running into any problems with the hash-table being modified
@@ -569,7 +569,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
node->references++;
}
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
p = node_list;
while (num_nodes-- > 0)
@@ -577,9 +577,9 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
node = *p++;
if (!err)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
err = (*fun)(node);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
diskfs_nrele (node);
}
@@ -700,7 +700,7 @@ diskfs_truncate (struct node *node, loff_t length)
diskfs_file_update (node, 1);
}
- rwlock_writer_lock (&node->dn->alloc_lock);
+ pthread_rwlock_wrlock (&node->dn->alloc_lock);
/* Update the size on disk; if we crash, we'll loose. */
node->dn_stat.st_size = length;
@@ -720,7 +720,7 @@ diskfs_truncate (struct node *node, loff_t length)
node->dn_set_ctime = 1;
node->dn_stat_dirty = 1;
- rwlock_writer_unlock (&node->dn->alloc_lock);
+ pthread_rwlock_unlock (&node->dn->alloc_lock);
return err;
}
diff --git a/fatfs/main.c b/fatfs/main.c
index b85d7fe7..b34f8dae 100644
--- a/fatfs/main.c
+++ b/fatfs/main.c
@@ -205,7 +205,7 @@ fetch_root ()
assert_perror (err);
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
}
@@ -239,7 +239,7 @@ main (int argc, char **argv)
diskfs_startup_diskfs (bootstrap, 0);
- cthread_exit (0);
+ pthread_exit (NULL);
return 0;
}
diff --git a/fatfs/pager.c b/fatfs/pager.c
index e617af03..f892c88f 100644
--- a/fatfs/pager.c
+++ b/fatfs/pager.c
@@ -28,7 +28,7 @@ struct port_bucket *pager_bucket;
/* Mapped image of the FAT. */
void *fat_image;
-spin_lock_t node_to_page_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t node_to_page_lock = PTHREAD_SPINLOCK_INITIALIZER;
#ifdef DONT_CACHE_MEMORY_OBJECTS
#define MAY_CACHE 0
@@ -40,7 +40,7 @@ spin_lock_t node_to_page_lock = SPIN_LOCK_INITIALIZER;
#define MAX_FREE_PAGE_BUFS 32
-static spin_lock_t free_page_bufs_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t free_page_bufs_lock = PTHREAD_SPINLOCK_INITIALIZER;
static void *free_page_bufs = 0;
static int num_free_page_bufs = 0;
@@ -50,12 +50,12 @@ get_page_buf ()
{
void *buf;
- spin_lock (&free_page_bufs_lock);
+ pthread_spin_lock (&free_page_bufs_lock);
buf = free_page_bufs;
if (buf == 0)
{
- spin_unlock (&free_page_bufs_lock);
+ pthread_spin_unlock (&free_page_bufs_lock);
buf = mmap (0, vm_page_size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
if (buf == (void *) -1)
buf = 0;
@@ -64,7 +64,7 @@ get_page_buf ()
{
free_page_bufs = *(void **)buf;
num_free_page_bufs--;
- spin_unlock (&free_page_bufs_lock);
+ pthread_spin_unlock (&free_page_bufs_lock);
}
return buf;
@@ -74,17 +74,17 @@ get_page_buf ()
static void
free_page_buf (void *buf)
{
- spin_lock (&free_page_bufs_lock);
+ pthread_spin_lock (&free_page_bufs_lock);
if (num_free_page_bufs < MAX_FREE_PAGE_BUFS)
{
*(void **)buf = free_page_bufs;
free_page_bufs = buf;
num_free_page_bufs++;
- spin_unlock (&free_page_bufs_lock);
+ pthread_spin_unlock (&free_page_bufs_lock);
}
else
{
- spin_unlock (&free_page_bufs_lock);
+ pthread_spin_unlock (&free_page_bufs_lock);
munmap (buf, vm_page_size);
}
}
@@ -96,14 +96,14 @@ free_page_buf (void *buf)
error code otherwise is returned. */
static error_t
find_cluster (struct node *node, vm_offset_t offset,
- cluster_t *cluster, struct rwlock **lock)
+ cluster_t *cluster, pthread_rwlock_t **lock)
{
error_t err;
if (!*lock)
{
*lock = &node->dn->alloc_lock;
- rwlock_reader_lock (*lock);
+ pthread_rwlock_rdlock (*lock);
}
if (round_cluster (offset) > node->allocsize)
@@ -134,7 +134,7 @@ root_dir_pager_read_page (vm_offset_t page, void **buf, int *writelock)
return EIO;
}
- rwlock_reader_lock(&diskfs_root_node->dn->alloc_lock);
+ pthread_rwlock_rdlock (&diskfs_root_node->dn->alloc_lock);
addr = first_root_dir_byte + page;
if (page + vm_page_size > diskfs_root_node->allocsize)
@@ -145,7 +145,7 @@ root_dir_pager_read_page (vm_offset_t page, void **buf, int *writelock)
if (!err && read != vm_page_size)
err = EIO;
- rwlock_reader_unlock (&diskfs_root_node->dn->alloc_lock);
+ pthread_rwlock_unlock (&diskfs_root_node->dn->alloc_lock);
if (overrun)
bzero ((void *) *buf + vm_page_size - overrun, overrun);
@@ -162,7 +162,7 @@ file_pager_read_small_page (struct node *node, vm_offset_t page,
void **buf, int *writelock)
{
error_t err;
- struct rwlock *lock = NULL;
+ pthread_rwlock_t *lock = NULL;
cluster_t cluster;
size_t read = 0;
@@ -188,7 +188,7 @@ file_pager_read_small_page (struct node *node, vm_offset_t page,
}
if (lock)
- rwlock_reader_unlock (lock);
+ pthread_rwlock_unlock (lock);
return err;
}
@@ -204,7 +204,7 @@ file_pager_read_huge_page (struct node *node, vm_offset_t page,
{
error_t err;
int offs = 0;
- struct rwlock *lock = NULL;
+ pthread_rwlock_t *lock = NULL;
int left = vm_page_size;
cluster_t pending_clusters = 0;
int num_pending_clusters = 0;
@@ -295,7 +295,7 @@ file_pager_read_huge_page (struct node *node, vm_offset_t page,
err = do_pending_reads();
if (lock)
- rwlock_reader_unlock (lock);
+ pthread_rwlock_unlock (lock);
return err;
}
@@ -380,7 +380,7 @@ file_pager_write_huge_page (struct node *node, vm_offset_t offset, void *buf)
{
error_t err = 0;
struct pending_clusters pc;
- struct rwlock *lock = &node->dn->alloc_lock;
+ pthread_rwlock_t *lock = &node->dn->alloc_lock;
cluster_t cluster;
int left = vm_page_size;
@@ -389,7 +389,7 @@ file_pager_write_huge_page (struct node *node, vm_offset_t offset, void *buf)
/* Holding NODE->dn->alloc_lock effectively locks NODE->allocsize,
at least for the cases we care about: pager_unlock_page,
diskfs_grow and diskfs_truncate. */
- rwlock_reader_lock (&node->dn->alloc_lock);
+ pthread_rwlock_rdlock (&node->dn->alloc_lock);
if (offset >= node->allocsize)
left = 0;
@@ -411,7 +411,7 @@ file_pager_write_huge_page (struct node *node, vm_offset_t offset, void *buf)
if (!err)
pending_clusters_write (&pc);
- rwlock_reader_unlock (&node->dn->alloc_lock);
+ pthread_rwlock_unlock (&node->dn->alloc_lock);
return err;
}
@@ -436,7 +436,7 @@ root_dir_pager_write_page (vm_offset_t offset, void *buf)
/* Holding NODE->dn->alloc_lock effectively locks NODE->allocsize,
at least for the cases we care about: pager_unlock_page,
diskfs_grow and diskfs_truncate. */
- rwlock_reader_lock (&diskfs_root_node->dn->alloc_lock);
+ pthread_rwlock_rdlock (&diskfs_root_node->dn->alloc_lock);
addr = first_root_dir_byte + offset;
@@ -450,7 +450,7 @@ root_dir_pager_write_page (vm_offset_t offset, void *buf)
if (!err && write != length)
err = EIO;
- rwlock_reader_unlock (&diskfs_root_node->dn->alloc_lock);
+ pthread_rwlock_unlock (&diskfs_root_node->dn->alloc_lock);
return err;
}
@@ -464,7 +464,7 @@ static error_t
file_pager_write_small_page (struct node *node, vm_offset_t offset, void *buf)
{
error_t err;
- struct rwlock *lock = NULL;
+ pthread_rwlock_t *lock = NULL;
cluster_t cluster;
size_t write = 0;
@@ -474,7 +474,7 @@ file_pager_write_small_page (struct node *node, vm_offset_t offset, void *buf)
/* Holding NODE->dn->alloc_lock effectively locks NODE->allocsize,
at least for the cases we care about: pager_unlock_page,
diskfs_grow and diskfs_truncate. */
- rwlock_reader_lock (&node->dn->alloc_lock);
+ pthread_rwlock_rdlock (&node->dn->alloc_lock);
err = find_cluster (node, offset, &cluster, &lock);
@@ -489,7 +489,7 @@ file_pager_write_small_page (struct node *node, vm_offset_t offset, void *buf)
}
if (lock)
- rwlock_reader_unlock (lock);
+ pthread_rwlock_unlock (lock);
return err;
}
@@ -617,7 +617,7 @@ diskfs_grow (struct node *node, loff_t size, struct protid *cred)
cluster_t new_end_cluster;
struct disknode *dn = node->dn;
- rwlock_writer_lock (&dn->alloc_lock);
+ pthread_rwlock_wrlock (&dn->alloc_lock);
old_size = node->allocsize;
new_size = ((size + bytes_per_cluster - 1) >> log2_bytes_per_cluster)
@@ -647,7 +647,7 @@ diskfs_grow (struct node *node, loff_t size, struct protid *cred)
node->allocsize = new_size;
- rwlock_writer_unlock (&dn->alloc_lock);
+ pthread_rwlock_unlock (&dn->alloc_lock);
return err;
}
@@ -662,11 +662,11 @@ diskfs_file_update (struct node *node, int wait)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -684,11 +684,11 @@ flush_node_pager (struct node *node)
struct pager *pager;
struct disknode *dn = node->dn;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (pager)
{
@@ -724,11 +724,11 @@ pager_clear_user_data (struct user_pager_info *upi)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = upi->node->dn->pager;
if (pager && pager_get_upi (pager) == upi)
upi->node->dn->pager = 0;
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
diskfs_nrele_light (upi->node);
}
@@ -768,7 +768,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
|| S_ISREG (node->dn_stat.st_mode)
|| (S_ISLNK (node->dn_stat.st_mode)));
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
do
{
struct pager *pager = node->dn->pager;
@@ -799,7 +799,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
{
diskfs_nrele_light (node);
free (upi);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
return MACH_PORT_NULL;
}
@@ -808,7 +808,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
}
}
while (right == MACH_PORT_NULL);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
mach_port_insert_right (mach_task_self (), right, right,
MACH_MSG_TYPE_MAKE_SEND);
@@ -823,11 +823,11 @@ drop_pager_softrefs (struct node *node)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (MAY_CACHE && pager)
pager_change_attributes (pager, 0, MEMORY_OBJECT_COPY_DELAY, 0);
@@ -842,11 +842,11 @@ allow_pager_softrefs (struct node *node)
{
struct pager *pager;
- spin_lock (&node_to_page_lock);
+ pthread_spin_lock (&node_to_page_lock);
pager = node->dn->pager;
if (pager)
ports_port_ref (pager);
- spin_unlock (&node_to_page_lock);
+ pthread_spin_unlock (&node_to_page_lock);
if (MAY_CACHE && pager)
pager_change_attributes (pager, 1, MEMORY_OBJECT_COPY_DELAY, 0);
diff --git a/fatfs/virt-inode.c b/fatfs/virt-inode.c
index d7c990d6..5d134b00 100644
--- a/fatfs/virt-inode.c
+++ b/fatfs/virt-inode.c
@@ -27,7 +27,7 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
-#include <spin-lock.h>
+#include <pthread.h>
#include "virt-inode.h"
/* Each virtual inode contains the UNIQUE key it belongs to,
@@ -56,7 +56,7 @@ struct table_page
struct table_page *inode_table;
-spin_lock_t inode_table_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t inode_table_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* See vi_new and vi_rlookup. */
error_t
@@ -119,9 +119,9 @@ vi_new(vi_key_t key, ino_t *inode, inode_t *v_inode)
assert (memcmp(&vi_zero_key, &key, sizeof (vi_key_t)));
- spin_lock (&inode_table_lock);
+ pthread_spin_lock (&inode_table_lock);
err = _vi_new(key, inode, v_inode);
- spin_unlock (&inode_table_lock);
+ pthread_spin_unlock (&inode_table_lock);
return err;
}
@@ -144,7 +144,7 @@ vi_lookup(ino_t inode)
int offset = (inode - 1) & (TABLE_PAGE_SIZE - 1);
inode_t v_inode = 0;
- spin_lock (&inode_table_lock);
+ pthread_spin_lock (&inode_table_lock);
while (table && page > 0)
{
@@ -155,7 +155,7 @@ vi_lookup(ino_t inode)
if (table)
v_inode = &table->vi[offset];
- spin_unlock (&inode_table_lock);
+ pthread_spin_unlock (&inode_table_lock);
return v_inode;
}
@@ -173,7 +173,7 @@ vi_rlookup(vi_key_t key, ino_t *inode, inode_t *v_inode, int create)
assert (memcmp(&vi_zero_key, &key, sizeof (vi_key_t)));
- spin_lock (&inode_table_lock);
+ pthread_spin_lock (&inode_table_lock);
while (table && memcmp(&table->vi[offset].key, &key, sizeof (vi_key_t)))
{
@@ -200,7 +200,7 @@ vi_rlookup(vi_key_t key, ino_t *inode, inode_t *v_inode, int create)
err = EINVAL;
}
- spin_unlock (&inode_table_lock);
+ pthread_spin_unlock (&inode_table_lock);
return err;
}
@@ -221,10 +221,10 @@ vi_key_t vi_change(inode_t v_inode, vi_key_t key)
vi_key_t vi_free(inode_t v_inode)
{
vi_key_t key;
- spin_lock (&inode_table_lock);
+ pthread_spin_lock (&inode_table_lock);
key = v_inode->key;
v_inode->key = vi_zero_key;
- spin_unlock (&inode_table_lock);
+ pthread_spin_unlock (&inode_table_lock);
return key;
}
diff --git a/ftpfs/Makefile b/ftpfs/Makefile
index 581c5da6..70398908 100644
--- a/ftpfs/Makefile
+++ b/ftpfs/Makefile
@@ -24,6 +24,7 @@ target = ftpfs
SRCS = ftpfs.c fs.c host.c netfs.c dir.c conn.c ccache.c node.c ncache.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = netfs fshelp iohelp threads ports ihash ftpconn shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp ports ihash ftpconn shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/ftpfs/ccache.c b/ftpfs/ccache.c
index 56f3bf1e..fa63c687 100644
--- a/ftpfs/ccache.c
+++ b/ftpfs/ccache.c
@@ -37,7 +37,7 @@ ccache_read (struct ccache *cc, off_t offs, size_t len, void *data)
error_t err = 0;
size_t max = offs + len;
- mutex_lock (&cc->lock);
+ pthread_mutex_lock (&cc->lock);
if (max > cc->size)
max = cc->size;
@@ -48,7 +48,7 @@ ccache_read (struct ccache *cc, off_t offs, size_t len, void *data)
/* Some thread is fetching data, so just let it do its thing, but get
a wakeup call when it's done. */
{
- if (hurd_condition_wait (&cc->wakeup, &cc->lock))
+ if (pthread_hurd_cond_wait_np (&cc->wakeup, &cc->lock))
err = EINTR;
}
else
@@ -60,7 +60,7 @@ ccache_read (struct ccache *cc, off_t offs, size_t len, void *data)
while (cc->max < max && !err)
{
- mutex_unlock (&cc->lock);
+ pthread_mutex_unlock (&cc->lock);
if (! cc->conn)
/* We need to setup a connection to fetch data over. */
@@ -179,12 +179,12 @@ ccache_read (struct ccache *cc, off_t offs, size_t len, void *data)
err = EINTR;
}
- mutex_lock (&cc->lock);
+ pthread_mutex_lock (&cc->lock);
if (cc->max < max && !err)
/* If anyone's waiting for data, let them look (if we're done
fetching, this gets delayed until below). */
- condition_broadcast (&cc->wakeup);
+ pthread_cond_broadcast (&cc->wakeup);
}
if (!err && cc->conn && cc->max == cc->size)
@@ -200,14 +200,14 @@ ccache_read (struct ccache *cc, off_t offs, size_t len, void *data)
cc->fetching_active = 0;
/* Let others know something's going on. */
- condition_broadcast (&cc->wakeup);
+ pthread_cond_broadcast (&cc->wakeup);
}
}
if (! err)
bcopy (cc->image + offs, data, max - offs);
- mutex_unlock (&cc->lock);
+ pthread_mutex_unlock (&cc->lock);
return err;
}
@@ -218,13 +218,13 @@ ccache_invalidate (struct ccache *cc)
{
error_t err = 0;
- mutex_lock (&cc->lock);
+ pthread_mutex_lock (&cc->lock);
while (cc->fetching_active && !err)
/* Some thread is fetching data, so just let it do its thing, but get
a wakeup call when it's done. */
{
- if (hurd_condition_wait (&cc->wakeup, &cc->lock))
+ if (pthread_hurd_cond_wait_np (&cc->wakeup, &cc->lock))
err = EINTR;
}
@@ -246,7 +246,7 @@ ccache_invalidate (struct ccache *cc)
}
}
- mutex_unlock (&cc->lock);
+ pthread_mutex_unlock (&cc->lock);
return err;
}
@@ -265,8 +265,8 @@ ccache_create (struct node *node, struct ccache **cc)
new->size = node->nn_stat.st_size;
new->max = 0;
new->alloced = 0;
- mutex_init (&new->lock);
- condition_init (&new->wakeup);
+ pthread_mutex_init (&new->lock, NULL);
+ pthread_cond_init (&new->wakeup, NULL);
new->fetching_active = 0;
new->conn = 0;
new->data_conn = -1;
diff --git a/ftpfs/ccache.h b/ftpfs/ccache.h
index 410720c3..78f90bd2 100644
--- a/ftpfs/ccache.h
+++ b/ftpfs/ccache.h
@@ -40,10 +40,10 @@ struct ccache
/* Amount of IMAGE that has been allocated. */
size_t alloced;
- struct mutex lock;
+ pthread_mutex_t lock;
/* People can wait for a reading thread on this condition. */
- struct condition wakeup;
+ pthread_cond_t wakeup;
/* True if some thread is now fetching data. Only that thread should
modify the DATA_CONN, DATA_CONN_POS, and MAX fields. */
diff --git a/ftpfs/conn.c b/ftpfs/conn.c
index 9be7dd28..0f1b0973 100644
--- a/ftpfs/conn.c
+++ b/ftpfs/conn.c
@@ -39,11 +39,11 @@ ftpfs_get_ftp_conn (struct ftpfs *fs, struct ftp_conn **conn)
{
struct ftpfs_conn *fsc;
- spin_lock (&fs->conn_lock);
+ pthread_spin_lock (&fs->conn_lock);
fsc = fs->free_conns;
if (fsc)
fs->free_conns = fsc->next;
- spin_unlock (&fs->conn_lock);
+ pthread_spin_unlock (&fs->conn_lock);
if (! fsc)
{
@@ -73,10 +73,10 @@ ftpfs_get_ftp_conn (struct ftpfs *fs, struct ftp_conn **conn)
fsc->conn->hook = (void *)(uintptr_t)conn_id++;
}
- spin_lock (&fs->conn_lock);
+ pthread_spin_lock (&fs->conn_lock);
fsc->next = fs->conns;
fs->conns = fsc;
- spin_unlock (&fs->conn_lock);
+ pthread_spin_unlock (&fs->conn_lock);
*conn = fsc->conn;
@@ -89,7 +89,7 @@ ftpfs_release_ftp_conn (struct ftpfs *fs, struct ftp_conn *conn)
{
struct ftpfs_conn *fsc, *pfsc;
- spin_lock (&fs->conn_lock);
+ pthread_spin_lock (&fs->conn_lock);
for (pfsc = 0, fsc = fs->conns; fsc; pfsc = fsc, fsc = fsc->next)
if (fsc->conn == conn)
{
@@ -102,5 +102,5 @@ ftpfs_release_ftp_conn (struct ftpfs *fs, struct ftp_conn *conn)
break;
}
assert (fsc);
- spin_unlock (&fs->conn_lock);
+ pthread_spin_unlock (&fs->conn_lock);
}
diff --git a/ftpfs/dir.c b/ftpfs/dir.c
index 8ef719d8..da5ddbe5 100644
--- a/ftpfs/dir.c
+++ b/ftpfs/dir.c
@@ -460,7 +460,7 @@ ftpfs_refresh_node (struct node *node)
time_t timestamp = NOW;
struct ftpfs_dir *dir = entry->dir;
- mutex_lock (&dir->node->lock);
+ pthread_mutex_lock (&dir->node->lock);
if (! entry->self_p)
/* This is a deleted entry, just awaiting disposal; do so. */
@@ -545,7 +545,7 @@ ftpfs_refresh_node (struct node *node)
if (!nn->dir && S_ISDIR (entry->stat.st_mode))
ftpfs_dir_create (nn->fs, node, nn->rmt_path, &nn->dir);
- mutex_unlock (&dir->node->lock);
+ pthread_mutex_unlock (&dir->node->lock);
ftpfs_cache_node (node);
@@ -566,7 +566,7 @@ ftpfs_detach_node (struct node *node)
{
struct ftpfs_dir *dir = entry->dir;
- mutex_lock (&dir->node->lock);
+ pthread_mutex_lock (&dir->node->lock);
if (entry->self_p)
/* Just detach NODE from the still active entry. */
@@ -581,7 +581,7 @@ ftpfs_detach_node (struct node *node)
if (--dir->num_live_entries == 0)
netfs_nput (dir->node);
else
- mutex_unlock (&dir->node->lock);
+ pthread_mutex_unlock (&dir->node->lock);
}
return 0;
@@ -642,7 +642,7 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
if (dir->node->nn->dir_entry)
{
*node = dir->node->nn->dir_entry->dir->node;
- mutex_lock (&(*node)->lock);
+ pthread_mutex_lock (&(*node)->lock);
netfs_nref (*node);
}
else
@@ -651,7 +651,7 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
*node = 0;
}
- mutex_unlock (&dir->node->lock);
+ pthread_mutex_unlock (&dir->node->lock);
return err;
}
@@ -711,10 +711,10 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
{
/* If there's already a node, add a ref so that it doesn't go
away. */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
if (e->node)
e->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
if (! e->node)
/* No node; make one and install it into E. */
@@ -740,9 +740,9 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
/* Keep a reference to dir's node corresponding to
children. */
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
dir->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
}
}
}
@@ -754,8 +754,8 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
because the locking order is always child-parent. We know
the child node won't go away because we already hold the
additional reference to it. */
- mutex_unlock (&dir->node->lock);
- mutex_lock (&e->node->lock);
+ pthread_mutex_unlock (&dir->node->lock);
+ pthread_mutex_lock (&e->node->lock);
}
}
else
@@ -765,7 +765,7 @@ ftpfs_dir_lookup (struct ftpfs_dir *dir, const char *name,
if (err)
{
*node = 0;
- mutex_unlock (&dir->node->lock);
+ pthread_mutex_unlock (&dir->node->lock);
}
if (rmt_path)
@@ -794,10 +794,10 @@ ftpfs_dir_null_lookup (struct ftpfs_dir *dir, struct node **node)
/* We've got a dir entry, get a node for it. */
{
/* If there's already a node, add a ref so that it doesn't go away. */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
if (e->node)
e->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
if (! e->node)
/* No node; make one and install it into E. */
@@ -807,9 +807,9 @@ ftpfs_dir_null_lookup (struct ftpfs_dir *dir, struct node **node)
if (!err && dir->num_live_entries++ == 0)
/* Keep a reference to dir's node corresponding to children. */
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
dir->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
}
}
@@ -846,9 +846,9 @@ ftpfs_dir_create (struct ftpfs *fs, struct node *node, const char *rmt_path,
}
/* Hold a reference to the new dir's node. */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
new->num_entries = 0;
new->num_live_entries = 0;
diff --git a/ftpfs/fs.c b/ftpfs/fs.c
index e4db3031..d3a93070 100644
--- a/ftpfs/fs.c
+++ b/ftpfs/fs.c
@@ -48,10 +48,10 @@ ftpfs_create (char *rmt_path, int fsid,
new->free_conns = 0;
new->conns = 0;
- spin_lock_init (&new->conn_lock);
+ pthread_spin_init (&new->conn_lock, PTHREAD_PROCESS_PRIVATE);
new->node_cache_mru = new->node_cache_lru = 0;
new->node_cache_len = 0;
- mutex_init (&new->node_cache_lock);
+ pthread_mutex_init (&new->node_cache_lock, NULL);
new->fsid = fsid;
new->next_inode = 2;
@@ -62,7 +62,7 @@ ftpfs_create (char *rmt_path, int fsid,
hurd_ihash_init (&new->inode_mappings,
offsetof (struct ftpfs_dir_entry, inode_locp));
- spin_lock_init (&new->inode_mappings_lock);
+ pthread_spin_init (&new->inode_mappings_lock, PTHREAD_PROCESS_PRIVATE);
super_root = netfs_make_node (0);
if (! super_root)
diff --git a/ftpfs/ftpfs.c b/ftpfs/ftpfs.c
index 393cc5ba..794439b4 100644
--- a/ftpfs/ftpfs.c
+++ b/ftpfs/ftpfs.c
@@ -72,7 +72,7 @@ extern error_t lookup_server (const char *server,
static FILE *debug_stream = 0;
static char *debug_stream_name = 0;
-static struct mutex debug_lock = MUTEX_INITIALIZER;
+static pthread_mutex_t debug_lock = PTHREAD_MUTEX_INITIALIZER;
/* Prints ftp connection log to DEBUG_STREAM. */
static void
@@ -87,14 +87,14 @@ cntl_debug (struct ftp_conn *conn, int type, const char *txt)
default: type_str = "?"; break;
}
- mutex_lock (&debug_lock);
+ pthread_mutex_lock (&debug_lock);
if (debug_stream)
{
fprintf (debug_stream, "%u.%s%s\n",
(unsigned)(uintptr_t)conn->hook, type_str, txt);
fflush (debug_stream);
}
- mutex_unlock (&debug_lock);
+ pthread_mutex_unlock (&debug_lock);
}
/* Various default parameters. */
@@ -154,7 +154,7 @@ parse_common_opt (int key, char *arg, struct argp_state *state)
switch (key)
{
case 'D':
- mutex_lock (&debug_lock);
+ pthread_mutex_lock (&debug_lock);
if (debug_stream && debug_stream != stderr)
fclose (debug_stream);
@@ -189,16 +189,16 @@ parse_common_opt (int key, char *arg, struct argp_state *state)
if (! err)
ftpfs_ftp_hooks.cntl_debug = cntl_debug;
- mutex_unlock (&debug_lock);
+ pthread_mutex_unlock (&debug_lock);
return err;
case OPT_NO_DEBUG:
- mutex_lock (&debug_lock);
+ pthread_mutex_lock (&debug_lock);
if (debug_stream && debug_stream != stderr)
fclose (debug_stream);
ftpfs_ftp_hooks.cntl_debug = 0;
- mutex_unlock (&debug_lock);
+ pthread_mutex_unlock (&debug_lock);
break;
case OPT_NODE_CACHE_MAX:
@@ -338,7 +338,7 @@ netfs_append_args (char **argz, size_t *argz_len)
} \
} while (0)
- mutex_lock (&debug_lock);
+ pthread_mutex_lock (&debug_lock);
if (ftpfs_ftp_hooks.cntl_debug && debug_stream)
{
if (debug_stream != stderr)
@@ -351,7 +351,7 @@ netfs_append_args (char **argz, size_t *argz_len)
else
err = argz_add (argz, argz_len, "--debug");
}
- mutex_unlock (&debug_lock);
+ pthread_mutex_unlock (&debug_lock);
if (ftpfs->params.name_timeout != DEFAULT_NAME_TIMEOUT)
FOPT ("--name-timeout=%ld", ftpfs->params.name_timeout);
diff --git a/ftpfs/ftpfs.h b/ftpfs/ftpfs.h
index 0eef5bde..206726f1 100644
--- a/ftpfs/ftpfs.h
+++ b/ftpfs/ftpfs.h
@@ -22,7 +22,7 @@
#define __FTPFS_H__
#include <stdlib.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <ftpconn.h>
#include <maptime.h>
#include <hurd/ihash.h>
@@ -163,7 +163,7 @@ struct ftpfs
/* A pool of ftp connections for server threads to use. */
struct ftpfs_conn *free_conns;
struct ftpfs_conn *conns;
- spin_lock_t conn_lock;
+ pthread_spinlock_t conn_lock;
/* Parameters for making new ftp connections. */
struct ftp_conn_params *ftp_params;
@@ -175,14 +175,14 @@ struct ftpfs
/* A hash table mapping inode numbers to directory entries. */
struct hurd_ihash inode_mappings;
- spin_lock_t inode_mappings_lock;
+ pthread_spinlock_t inode_mappings_lock;
struct ftpfs_params params;
/* A cache that holds a reference to recently used nodes. */
struct node *node_cache_mru, *node_cache_lru;
size_t node_cache_len; /* Number of entries in it. */
- struct mutex node_cache_lock;
+ pthread_mutex_t node_cache_lock;
};
extern volatile struct mapped_time_value *ftpfs_maptime;
diff --git a/ftpfs/ncache.c b/ftpfs/ncache.c
index 27b868a7..612dc081 100644
--- a/ftpfs/ncache.c
+++ b/ftpfs/ncache.c
@@ -51,7 +51,7 @@ ftpfs_cache_node (struct node *node)
struct netnode *nn = node->nn;
struct ftpfs *fs = nn->fs;
- mutex_lock (&fs->node_cache_lock);
+ pthread_mutex_lock (&fs->node_cache_lock);
if (fs->params.node_cache_max > 0 || fs->node_cache_len > 0)
{
@@ -83,5 +83,5 @@ ftpfs_cache_node (struct node *node)
}
}
- mutex_unlock (&fs->node_cache_lock);
+ pthread_mutex_unlock (&fs->node_cache_lock);
}
diff --git a/ftpfs/netfs.c b/ftpfs/netfs.c
index 8922f3ab..5359acb9 100644
--- a/ftpfs/netfs.c
+++ b/ftpfs/netfs.c
@@ -41,7 +41,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **node)
{
*node = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -413,7 +413,7 @@ error_t netfs_attempt_mkfile (struct iouser *user, struct node *dir,
mode_t mode, struct node **node)
{
*node = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EROFS;
}
diff --git a/ftpfs/node.c b/ftpfs/node.c
index d949016c..74cd402e 100644
--- a/ftpfs/node.c
+++ b/ftpfs/node.c
@@ -61,9 +61,9 @@ ftpfs_create_node (struct ftpfs_dir_entry *e, const char *rmt_path,
fshelp_touch (&new->nn_stat, TOUCH_ATIME|TOUCH_MTIME|TOUCH_CTIME,
ftpfs_maptime);
- spin_lock (&nn->fs->inode_mappings_lock);
+ pthread_spin_lock (&nn->fs->inode_mappings_lock);
err = hurd_ihash_add (&nn->fs->inode_mappings, e->stat.st_ino, e);
- spin_unlock (&nn->fs->inode_mappings_lock);
+ pthread_spin_unlock (&nn->fs->inode_mappings_lock);
if (err)
{
@@ -87,7 +87,7 @@ netfs_node_norefs (struct node *node)
/* Ftpfs_detach_node does ref count frobbing (of other nodes), so we have
to unlock NETFS_NODE_REFCNT_LOCK during it. */
node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
/* Remove NODE from any entry it is attached to. */
ftpfs_detach_node (node);
@@ -99,9 +99,9 @@ netfs_node_norefs (struct node *node)
}
/* Remove this entry from the set of known inodes. */
- spin_lock (&nn->fs->inode_mappings_lock);
+ pthread_spin_lock (&nn->fs->inode_mappings_lock);
hurd_ihash_locp_remove (&nn->fs->inode_mappings, nn->dir_entry->inode_locp);
- spin_unlock (&nn->fs->inode_mappings_lock);
+ pthread_spin_unlock (&nn->fs->inode_mappings_lock);
if (nn->contents)
ccache_free (nn->contents);
@@ -110,5 +110,5 @@ netfs_node_norefs (struct node *node)
free (node);
/* Caller expects us to leave this locked... */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
}
diff --git a/hostmux/Makefile b/hostmux/Makefile
index b139922f..939a9f62 100644
--- a/hostmux/Makefile
+++ b/hostmux/Makefile
@@ -24,6 +24,7 @@ target = hostmux
SRCS = hostmux.c mux.c leaf.c node.c stubs.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = netfs fshelp iohelp threads ports ihash shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/hostmux/hostmux.h b/hostmux/hostmux.h
index 98ef04ac..e6cfb767 100644
--- a/hostmux/hostmux.h
+++ b/hostmux/hostmux.h
@@ -22,7 +22,7 @@
#define __HOSTMUX_H__
#include <hurd/netfs.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <maptime.h>
#include <features.h>
@@ -40,7 +40,7 @@ struct hostmux
{
/* The host hodes in this mux. */
struct hostmux_name *names;
- struct rwlock names_lock;
+ pthread_rwlock_t names_lock;
/* The next inode number we'll use; protected by NAMES_LOCK. */
ino_t next_fileno;
diff --git a/hostmux/mux.c b/hostmux/mux.c
index dd976c57..737240af 100644
--- a/hostmux/mux.c
+++ b/hostmux/mux.c
@@ -80,11 +80,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, hostmux_maptime);
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (err)
*node = 0;
else
- mutex_lock (&(*node)->lock);
+ pthread_mutex_lock (&(*node)->lock);
return err;
}
@@ -123,7 +123,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
if (dir->nn->name)
return ENOTDIR;
- rwlock_reader_lock (&dir->nn->mux->names_lock);
+ pthread_rwlock_rdlock (&dir->nn->mux->names_lock);
/* Find the first entry. */
for (first_name = dir->nn->mux->names, count = 2;
@@ -204,7 +204,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
break;
}
- rwlock_reader_unlock (&dir->nn->mux->names_lock);
+ pthread_rwlock_unlock (&dir->nn->mux->names_lock);
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, hostmux_maptime);
@@ -240,10 +240,10 @@ lookup_cached (struct hostmux *mux, const char *host, int purge,
if (strcasecmp (host, nm->name) == 0)
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
if (nm->node)
nm->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
if (nm->node)
{
@@ -295,13 +295,13 @@ lookup_addrinfo (struct hostmux *mux, const char *host, struct addrinfo *he,
return err;
}
- rwlock_writer_lock (&mux->names_lock);
+ pthread_rwlock_wrlock (&mux->names_lock);
if (lookup_cached (mux, host, 1, node))
/* An entry for HOST has already been created between the time we last
looked and now (which is possible because we didn't lock MUX).
Just throw away our version and return the one already in the cache. */
{
- rwlock_writer_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
nm->node->nn->name = 0; /* Avoid touching the mux name list. */
netfs_nrele (nm->node); /* Free the tentative new node. */
free_name (nm); /* And the name it was under. */
@@ -312,7 +312,7 @@ lookup_addrinfo (struct hostmux *mux, const char *host, struct addrinfo *he,
nm->fileno = mux->next_fileno++; /* Now that we hold the lock... */
nm->next = mux->names;
mux->names = nm;
- rwlock_writer_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
}
return 0;
@@ -333,9 +333,9 @@ lookup_host (struct hostmux *mux, const char *host, struct node **node)
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_IP;
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
was_cached = lookup_cached (mux, host, 0, node);
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
if (was_cached)
return 0;
@@ -381,14 +381,14 @@ netfs_attempt_chown (struct iouser *cred, struct node *node, uid_t uid, uid_t gi
node->nn_stat.st_gid = gid;
/* Change the owner of each leaf node. */
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
for (nm = mux->names; nm; nm = nm->next)
if (nm->node)
{
nm->node->nn_stat.st_uid = uid;
nm->node->nn_stat.st_gid = gid;
}
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, hostmux_maptime);
}
@@ -418,11 +418,11 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author)
node->nn_stat.st_author = author;
/* Change the owner of each leaf node. */
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
for (nm = mux->names; nm; nm = nm->next)
if (nm->node)
nm->node->nn_stat.st_author = author;
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, hostmux_maptime);
}
diff --git a/hostmux/node.c b/hostmux/node.c
index d6edc53e..7167300f 100644
--- a/hostmux/node.c
+++ b/hostmux/node.c
@@ -46,7 +46,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **node)
{
*node = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
diff --git a/hostmux/stubs.c b/hostmux/stubs.c
index f5dd9b67..1d94f219 100644
--- a/hostmux/stubs.c
+++ b/hostmux/stubs.c
@@ -120,7 +120,7 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir,
mode_t mode, struct node **node)
{
*node = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
diff --git a/hurd/shared.h b/hurd/shared.h
index a63cdb91..9d467328 100644
--- a/hurd/shared.h
+++ b/hurd/shared.h
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with the GNU Hurd; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+#include <pthread.h>
#include <sys/types.h> /* Defines `off_t'. */
struct shared_io
@@ -24,7 +25,7 @@ struct shared_io
int shared_page_magic;
/* This lock protects against modification to conch_status. */
- spin_lock_t lock;
+ pthread_spinlock_t lock;
enum
{
diff --git a/isofs/Makefile b/isofs/Makefile
index 4f788368..053b622e 100644
--- a/isofs/Makefile
+++ b/isofs/Makefile
@@ -21,7 +21,8 @@ target = iso9660fs
SRCS = inode.c main.c lookup.c pager.c rr.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = diskfs iohelp fshelp store pager threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/isofs/inode.c b/isofs/inode.c
index 99aca957..d848908b 100644
--- a/isofs/inode.c
+++ b/isofs/inode.c
@@ -71,8 +71,8 @@ inode_cache_find (off_t id, struct node **npp)
{
*npp = node_cache[i].np;
(*npp)->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&(*npp)->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&(*npp)->lock);
return;
}
*npp = 0;
@@ -154,7 +154,7 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
to avoid presenting zero cache ID's. */
id--;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
assert (id < node_cache_size);
np = node_cache[id].np;
@@ -173,7 +173,7 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
dn = malloc (sizeof (struct disknode));
if (!dn)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
release_rrip (&rr);
return ENOMEM;
}
@@ -184,14 +184,14 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
if (!np)
{
free (dn);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
release_rrip (&rr);
return ENOMEM;
}
np->cache_id = id + 1; /* see above for rationale for increment */
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
c->np = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = read_disknode (np, node_cache[id].dr, &rr);
if (!err)
@@ -204,8 +204,8 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -314,7 +314,7 @@ load_inode (struct node **npp, struct dirrect *record,
if (rr->valid & VALID_CL)
record = rr->realdirent;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
/* First check the cache */
if (use_file_start_id (record, rr))
@@ -324,7 +324,7 @@ load_inode (struct node **npp, struct dirrect *record,
if (*npp)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return 0;
}
@@ -332,7 +332,7 @@ load_inode (struct node **npp, struct dirrect *record,
dn = malloc (sizeof (struct disknode));
if (!dn)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return ENOMEM;
}
dn->fileinfo = 0;
@@ -343,14 +343,14 @@ load_inode (struct node **npp, struct dirrect *record,
if (!np)
{
free (dn);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return ENOMEM;
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
cache_inode (np, record, rr);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = read_disknode (np, record, rr);
*npp = np;
diff --git a/isofs/lookup.c b/isofs/lookup.c
index 8daa5464..2ff30496 100644
--- a/isofs/lookup.c
+++ b/isofs/lookup.c
@@ -132,9 +132,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* We don't have to do the normal rigamarole, because
we are permanently read-only, so things are necessarily
quiescent. Just be careful to honor the locking order. */
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = load_inode (npp, record, &rr);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
}
}
else if (namelen == 1 && name[0] == '.')
diff --git a/isofs/main.c b/isofs/main.c
index 4f6ea8fa..5d002aff 100644
--- a/isofs/main.c
+++ b/isofs/main.c
@@ -60,7 +60,7 @@ fetch_root ()
err = load_inode (&diskfs_root_node, dr, &rl);
assert_perror (err);
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
}
@@ -144,7 +144,7 @@ main (int argc, char **argv)
diskfs_startup_diskfs (bootstrap, 0);
- cthread_exit (0);
+ pthread_exit (NULL);
return 0;
}
diff --git a/isofs/pager.c b/isofs/pager.c
index 5142cbc8..f93e0c82 100644
--- a/isofs/pager.c
+++ b/isofs/pager.c
@@ -22,7 +22,7 @@
#include <string.h>
#include "isofs.h"
-spin_lock_t node2pagelock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t node2pagelock = PTHREAD_SPINLOCK_INITIALIZER;
struct port_bucket *pager_bucket;
@@ -111,10 +111,10 @@ pager_clear_user_data (struct user_pager_info *upi)
{
if (upi->type == FILE_DATA)
{
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
if (upi->np->dn->fileinfo == upi)
upi->np->dn->fileinfo = 0;
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
diskfs_nrele_light (upi->np);
}
free (upi);
@@ -159,7 +159,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
|| S_ISREG (np->dn_stat.st_mode)
|| S_ISLNK (np->dn_stat.st_mode));
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
do
if (!np->dn->fileinfo)
@@ -173,7 +173,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
{
diskfs_nrele_light (np);
free (upi);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
return MACH_PORT_NULL;
}
np->dn->fileinfo = upi;
@@ -192,7 +192,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
}
while (right == MACH_PORT_NULL);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
mach_port_insert_right (mach_task_self (), right, right,
MACH_MSG_TYPE_MAKE_SEND);
@@ -207,11 +207,11 @@ drop_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -227,11 +227,11 @@ allow_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
diff --git a/libcons/Makefile b/libcons/Makefile
index e0bf62c4..a0df9f63 100644
--- a/libcons/Makefile
+++ b/libcons/Makefile
@@ -30,7 +30,8 @@ fs_notify-MIGSFLAGS = -imacros $(srcdir)/mutations.h
MIGSTUBS = fs_notifyServer.o
OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS))
-HURDLIBS = threads ports
+HURDLIBS = ports
+LDLIBS += -lpthread
MIGCOMSFLAGS = -prefix cons_
diff --git a/libcons/cons-switch.c b/libcons/cons-switch.c
index 752af97e..d8af50af 100644
--- a/libcons/cons-switch.c
+++ b/libcons/cons-switch.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <assert.h>
+#include <pthread.h>
#include "cons.h"
@@ -36,7 +37,7 @@ cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons)
if (!id && !delta)
return 0;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
if (id)
{
vcons_entry = cons->vcons_list;
@@ -67,14 +68,14 @@ cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons)
if (!vcons_entry)
{
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return ESRCH;
}
if (vcons_entry->vcons)
{
*r_vcons = vcons_entry->vcons;
- mutex_lock (&vcons_entry->vcons->lock);
+ pthread_mutex_lock (&vcons_entry->vcons->lock);
}
else
{
@@ -83,6 +84,6 @@ cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons)
vcons_entry->vcons = *r_vcons;
}
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return err;
}
diff --git a/libcons/cons.h b/libcons/cons.h
index e9d01a8c..78675228 100644
--- a/libcons/cons.h
+++ b/libcons/cons.h
@@ -65,7 +65,7 @@ struct vcons
int id;
/* The lock that protects all other members. */
- struct mutex lock;
+ pthread_mutex_t lock;
/* The FD of the input node. */
int input;
@@ -112,7 +112,7 @@ struct cons
{
/* Protects the cons structure and the linked list in
VCONS_LIST. */
- struct mutex lock;
+ pthread_mutex_t lock;
vcons_list_t vcons_list;
vcons_list_t vcons_last;
diff --git a/libcons/dir-changed.c b/libcons/dir-changed.c
index e1997d0f..8498649c 100644
--- a/libcons/dir-changed.c
+++ b/libcons/dir-changed.c
@@ -22,7 +22,7 @@
#include <dirent.h>
#include <assert.h>
#include <mach.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "cons.h"
#include "fs_notify_S.h"
@@ -69,7 +69,7 @@ cons_S_dir_changed (cons_notify_t notify, natural_t tickno,
return EOPNOTSUPP;
cons = notify->cons;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
switch (change)
{
@@ -121,9 +121,9 @@ cons_S_dir_changed (cons_notify_t notify, natural_t tickno,
case DIR_CHANGED_RENUMBER:
default:
assert ("Unexpected dir-changed type.");
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return EINVAL;
}
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
return 0;
}
diff --git a/libcons/file-changed.c b/libcons/file-changed.c
index b12a6f10..fa5cebd7 100644
--- a/libcons/file-changed.c
+++ b/libcons/file-changed.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <assert.h>
+#include <pthread.h>
#include <mach.h>
@@ -37,7 +38,7 @@ cons_S_file_changed (cons_notify_t notify, natural_t tickno,
if (!notify || notify->cons)
return EOPNOTSUPP;
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
switch (change)
{
case FILE_CHANGED_NULL:
@@ -361,6 +362,6 @@ cons_S_file_changed (cons_notify_t notify, natural_t tickno,
err = EINVAL;
};
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
return err;
}
diff --git a/libcons/init-init.c b/libcons/init-init.c
index eda292f5..ea3b37f7 100644
--- a/libcons/init-init.c
+++ b/libcons/init-init.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <malloc.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/ports.h>
@@ -53,7 +54,7 @@ cons_init (void)
cons = malloc (sizeof (*cons));
if (!cons)
return errno;
- mutex_init (&cons->lock);
+ pthread_mutex_init (&cons->lock, NULL);
cons->vcons_list = NULL;
cons->vcons_last = NULL;
cons->dir = opendir (cons_file);
diff --git a/libcons/vcons-close.c b/libcons/vcons-close.c
index 33a38982..554bfa80 100644
--- a/libcons/vcons-close.c
+++ b/libcons/vcons-close.c
@@ -22,7 +22,7 @@
#include <hurd.h>
#include <hurd/ports.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "cons.h"
@@ -33,11 +33,11 @@ cons_vcons_close (vcons_t vcons)
cons_t cons = vcons->cons;
vcons_list_t vcons_entry = vcons->vcons_entry;
- mutex_lock (&cons->lock);
+ pthread_mutex_lock (&cons->lock);
/* The same virtual console should never be opened twice. */
assert (vcons_entry->vcons == vcons);
vcons_entry->vcons = NULL;
- mutex_unlock (&cons->lock);
+ pthread_mutex_unlock (&cons->lock);
/* Destroy the port. */
ports_port_deref (vcons);
diff --git a/libcons/vcons-input.c b/libcons/vcons-input.c
index e008b9c9..ccc7532b 100644
--- a/libcons/vcons-input.c
+++ b/libcons/vcons-input.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <unistd.h>
+#include <pthread.h>
#include "cons.h"
#include "priv.h"
@@ -50,7 +51,7 @@ _cons_vcons_input (vcons_t vcons, char *buf, size_t size)
error_t
cons_vcons_input (vcons_t vcons, char *buf, size_t size)
{
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
_cons_vcons_console_event (vcons, CONS_EVT_KEYPRESS);
@@ -59,6 +60,6 @@ cons_vcons_input (vcons_t vcons, char *buf, size_t size)
_cons_vcons_input (vcons, buf, size);
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
return 0;
}
diff --git a/libcons/vcons-move-mouse.c b/libcons/vcons-move-mouse.c
index 1e5f7b9f..6c74d9fc 100644
--- a/libcons/vcons-move-mouse.c
+++ b/libcons/vcons-move-mouse.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <unistd.h>
+#include <pthread.h>
#include "cons.h"
#include "priv.h"
@@ -33,7 +34,7 @@ cons_vcons_move_mouse (vcons_t vcons, mouse_event_t ev)
char event[CONS_MOUSE_EVENT_LENGTH];
uint32_t report_events;
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
report_events = vcons->display->flags & CONS_FLAGS_TRACK_MOUSE;
switch (ev->mouse_movement)
@@ -98,6 +99,6 @@ cons_vcons_move_mouse (vcons_t vcons, mouse_event_t ev)
}
}
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
return 0;
}
diff --git a/libcons/vcons-open.c b/libcons/vcons-open.c
index 8c34fc5e..22d64303 100644
--- a/libcons/vcons-open.c
+++ b/libcons/vcons-open.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
+#include <pthread.h>
#include <hurd.h>
#include <mach.h>
@@ -55,7 +56,7 @@ cons_vcons_open (cons_t cons, vcons_list_t vcons_entry, vcons_t *r_vcons)
vcons->cons = cons;
vcons->vcons_entry = vcons_entry;
vcons->id = vcons_entry->id;
- mutex_init (&vcons->lock);
+ pthread_mutex_init (&vcons->lock, NULL);
vcons->input = -1;
vcons->display = MAP_FAILED;
vcons->scrolling = 0;
@@ -138,7 +139,7 @@ cons_vcons_open (cons_t cons, vcons_list_t vcons_entry, vcons_t *r_vcons)
/* When this succeeds, we will immediately receive notification
messages for this virtual console. */
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
err = file_notice_changes (file, notify, MACH_MSG_TYPE_MAKE_SEND);
if (!err)
{
diff --git a/libcons/vcons-scrollback.c b/libcons/vcons-scrollback.c
index 77c8c211..625fc4b5 100644
--- a/libcons/vcons-scrollback.c
+++ b/libcons/vcons-scrollback.c
@@ -20,7 +20,7 @@
#include <stdint.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "cons.h"
#include "priv.h"
@@ -154,11 +154,11 @@ cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value)
{
int ret;
- mutex_lock (&vcons->lock);
+ pthread_mutex_lock (&vcons->lock);
ret = _cons_vcons_scrollback (vcons, type, value);
_cons_vcons_console_event (vcons, CONS_EVT_OUTPUT);
cons_vcons_update (vcons);
- mutex_unlock (&vcons->lock);
+ pthread_mutex_unlock (&vcons->lock);
return ret;
}
diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index 606ed954..3c8de4c8 100644
--- a/libdiskfs/Makefile
+++ b/libdiskfs/Makefile
@@ -60,7 +60,8 @@ MIGSTUBS = fsServer.o ioServer.o fsysServer.o exec_startupServer.o \
startup_notifyServer.o
OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS))
-HURDLIBS = fshelp iohelp store threads ports shouldbeinlibc pager
+HURDLIBS = fshelp iohelp store ports shouldbeinlibc pager
+LDLIBS += -lpthread
fsys-MIGSFLAGS = -imacros $(srcdir)/fsmutations.h -DREPLY_PORTS
fs-MIGSFLAGS = -imacros $(srcdir)/fsmutations.h
diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index 15563bdb..1e4a1c64 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -40,8 +40,8 @@ static mach_port_t diskfs_exec_ctl;
extern task_t diskfs_exec_server_task;
static task_t parent_task = MACH_PORT_NULL;
-static struct mutex execstartlock;
-static struct condition execstarted;
+static pthread_mutex_t execstartlock;
+static pthread_cond_t execstarted;
const char *diskfs_boot_init_program = _HURD_INIT;
@@ -155,12 +155,12 @@ diskfs_start_bootstrap ()
fflush (stdout);
/* Get the execserver going and wait for its fsys_startup */
- mutex_init (&execstartlock);
- condition_init (&execstarted);
- mutex_lock (&execstartlock);
+ pthread_mutex_init (&execstartlock, NULL);
+ pthread_cond_init (&execstarted, NULL);
+ pthread_mutex_lock (&execstartlock);
start_execserver ();
- condition_wait (&execstarted, &execstartlock);
- mutex_unlock (&execstartlock);
+ pthread_cond_wait (&execstarted, &execstartlock);
+ pthread_mutex_unlock (&execstartlock);
assert (diskfs_exec_ctl != MACH_PORT_NULL);
/* Contact the exec server. */
@@ -414,9 +414,9 @@ diskfs_execboot_fsys_startup (mach_port_t port, int flags,
diskfs_exec_ctl = ctl;
- mutex_lock (&execstartlock);
- condition_signal (&execstarted);
- mutex_unlock (&execstartlock);
+ pthread_mutex_lock (&execstartlock);
+ pthread_cond_signal (&execstarted);
+ pthread_mutex_unlock (&execstartlock);
ports_port_deref (pt);
return 0;
}
diff --git a/libdiskfs/dead-name.c b/libdiskfs/dead-name.c
index f5b641d2..760b36ff 100644
--- a/libdiskfs/dead-name.c
+++ b/libdiskfs/dead-name.c
@@ -30,7 +30,7 @@ ports_dead_name (void *notify, mach_port_t dead_name)
if (pi)
{
np = pi->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (dead_name == np->sockaddr)
{
mach_port_deallocate (mach_task_self (), np->sockaddr);
@@ -38,7 +38,7 @@ ports_dead_name (void *notify, mach_port_t dead_name)
diskfs_nput (np);
}
else
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
ports_interrupt_notified_rpcs (notify, dead_name, MACH_NOTIFY_DEAD_NAME);
diff --git a/libdiskfs/dir-chg.c b/libdiskfs/dir-chg.c
index 7ca34447..ed8f40c1 100644
--- a/libdiskfs/dir-chg.c
+++ b/libdiskfs/dir-chg.c
@@ -31,28 +31,28 @@ diskfs_S_dir_notice_changes (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (!S_ISDIR (np->dn_stat.st_mode))
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return ENOTDIR;
}
err = dir_changed (notify, np->dirmod_tick, DIR_CHANGED_NULL, "");
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
req = malloc (sizeof (struct modreq));
if (! req)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return ENOMEM;
}
req->port = notify;
req->next = np->dirmod_reqs;
np->dirmod_reqs = req;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/dir-link.c b/libdiskfs/dir-link.c
index 82f8aeec..45d88948 100644
--- a/libdiskfs/dir-link.c
+++ b/libdiskfs/dir-link.c
@@ -41,16 +41,16 @@ diskfs_S_dir_link (struct protid *dircred,
return EXDEV;
np = filecred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (S_ISDIR (np->dn_stat.st_mode))
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EPERM;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
dnp = dircred->po->np;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
/* Lookup new location */
error = diskfs_lookup (dnp, name, RENAME, &tnp, ds, dircred);
@@ -64,15 +64,15 @@ diskfs_S_dir_link (struct protid *dircred,
if (error == EAGAIN)
error = EINVAL;
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
if (np == tnp)
{
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
- mutex_unlock (&tnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&tnp->lock);
mach_port_deallocate (mach_task_self (), filecred->pi.port_right);
return 0;
}
@@ -80,8 +80,8 @@ diskfs_S_dir_link (struct protid *dircred,
if (tnp && S_ISDIR (tnp->dn_stat.st_mode))
{
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
- mutex_unlock (&tnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&tnp->lock);
return EISDIR;
}
@@ -89,14 +89,14 @@ diskfs_S_dir_link (struct protid *dircred,
/* This is safe because NP is not a directory (thus not DNP) and
not TNP and is a leaf. */
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* Increment link count */
if (np->dn_stat.st_nlink == diskfs_link_max - 1)
{
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&np->lock);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&dnp->lock);
return EMLINK;
}
np->dn_stat.st_nlink++;
@@ -124,8 +124,8 @@ diskfs_S_dir_link (struct protid *dircred,
if (diskfs_synchronous)
diskfs_node_update (dnp, 1);
- mutex_unlock (&dnp->lock);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error)
/* MiG won't do this for us, which it ought to. */
mach_port_deallocate (mach_task_self (), filecred->pi.port_right);
diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 7e092908..1efdf75c 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -77,14 +77,14 @@ diskfs_S_dir_lookup (struct protid *dircred,
/* Set things up in the state expected by the code from gotit: on. */
dnp = 0;
np = dircred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
diskfs_nref (np);
goto gotit;
}
dnp = dircred->po->np;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
np = 0;
diskfs_nref (dnp); /* acquire a reference for later diskfs_nput */
@@ -271,7 +271,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
ports_port_deref (newpi);
newpi = 0;
if (np != dnp)
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
error = fshelp_fetch_root (&np->transbox, dircred->po,
dirport, dircred->user,
@@ -307,12 +307,12 @@ diskfs_S_dir_lookup (struct protid *dircred,
if (np != dnp)
{
if (!strcmp (path, ".."))
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
else
{
- mutex_unlock (&np->lock);
- mutex_lock (&dnp->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
+ pthread_mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&np->lock);
}
}
}
diff --git a/libdiskfs/dir-mkdir.c b/libdiskfs/dir-mkdir.c
index 30d7a3b4..1ddb8087 100644
--- a/libdiskfs/dir-mkdir.c
+++ b/libdiskfs/dir-mkdir.c
@@ -36,7 +36,7 @@ diskfs_S_dir_mkdir (struct protid *dircred,
if (diskfs_check_readonly ())
return EROFS;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
error = diskfs_lookup (dnp, name, CREATE, 0, ds, dircred);
if (error == EAGAIN)
@@ -47,7 +47,7 @@ diskfs_S_dir_mkdir (struct protid *dircred,
if (error != ENOENT)
{
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
@@ -65,6 +65,6 @@ diskfs_S_dir_mkdir (struct protid *dircred,
if (!error)
diskfs_nput (np);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
diff --git a/libdiskfs/dir-mkfile.c b/libdiskfs/dir-mkfile.c
index 914b18fe..a38d89a5 100644
--- a/libdiskfs/dir-mkfile.c
+++ b/libdiskfs/dir-mkfile.c
@@ -41,23 +41,23 @@ diskfs_S_dir_mkfile (struct protid *cred,
if (diskfs_check_readonly ())
return EROFS;
dnp = cred->po->np;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
if (!S_ISDIR (dnp->dn_stat.st_mode))
{
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return ENOTDIR;
}
err = fshelp_access (&dnp->dn_stat, S_IWRITE, cred->user);
if (err)
{
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return err;
}
mode &= ~(S_IFMT | S_ISPARE | S_ISVTX | S_ITRANS);
mode |= S_IFREG;
err = diskfs_create_node (dnp, 0, mode, &np, cred, 0);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
if (diskfs_synchronous)
{
diff --git a/libdiskfs/dir-readdir.c b/libdiskfs/dir-readdir.c
index d2f9d750..1393e26f 100644
--- a/libdiskfs/dir-readdir.c
+++ b/libdiskfs/dir-readdir.c
@@ -40,22 +40,22 @@ diskfs_S_dir_readdir (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if ((cred->po->openstat & O_READ) == 0)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EBADF;
}
if ((np->dn_stat.st_mode & S_IFMT) != S_IFDIR)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return ENOTDIR;
}
err = diskfs_get_directs (np, entry, nentries, data, datacnt, bufsiz, amt);
*data_dealloc = 1; /* XXX */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libdiskfs/dir-rename.c b/libdiskfs/dir-rename.c
index 298669be..ff9dead0 100644
--- a/libdiskfs/dir-rename.c
+++ b/libdiskfs/dir-rename.c
@@ -24,7 +24,7 @@
/* To avoid races in checkpath, and to prevent a directory from being
simultaneously renamed by two processes, we serialize all renames of
directores with this lock */
-static struct mutex renamedirlock = MUTEX_INITIALIZER;
+static pthread_mutex_t renamedirlock = PTHREAD_MUTEX_INITIALIZER;
/* Implement dir_rename as described in <hurd/fs.defs>. */
kern_return_t
@@ -63,9 +63,9 @@ diskfs_S_dir_rename (struct protid *fromcred,
/* Acquire the source; hold a reference to it. This
will prevent anyone from deleting it before we create
the new link. */
- mutex_lock (&fdp->lock);
+ pthread_mutex_lock (&fdp->lock);
err = diskfs_lookup (fdp, fromname, LOOKUP, &fnp, 0, fromcred);
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
if (err == EAGAIN)
err = EINVAL;
if (err)
@@ -73,44 +73,44 @@ diskfs_S_dir_rename (struct protid *fromcred,
if (S_ISDIR (fnp->dn_stat.st_mode))
{
- mutex_unlock (&fnp->lock);
- if (!mutex_try_lock (&renamedirlock))
+ pthread_mutex_unlock (&fnp->lock);
+ if (pthread_mutex_trylock (&renamedirlock))
{
diskfs_nrele (fnp);
- mutex_lock (&renamedirlock);
+ pthread_mutex_lock (&renamedirlock);
goto try_again;
}
err = diskfs_rename_dir (fdp, fnp, fromname, tdp, toname, fromcred,
tocred);
if (diskfs_synchronous)
{
- mutex_lock (&fdp->lock);
+ pthread_mutex_lock (&fdp->lock);
diskfs_file_update (fdp, 1);
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
- mutex_lock (&fnp->lock);
+ pthread_mutex_lock (&fnp->lock);
diskfs_file_update (fnp, 1);
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&fnp->lock);
- mutex_lock (&tdp->lock);
+ pthread_mutex_lock (&tdp->lock);
diskfs_file_update (tdp, 1);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
}
diskfs_nrele (fnp);
- mutex_unlock (&renamedirlock);
+ pthread_mutex_unlock (&renamedirlock);
if (!err)
/* MiG won't do this for us, which it ought to. */
mach_port_deallocate (mach_task_self (), tocred->pi.port_right);
return err;
}
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&fnp->lock);
/* We now hold no locks */
/* Link the node into the new directory. */
- mutex_lock (&tdp->lock);
+ pthread_mutex_lock (&tdp->lock);
err = diskfs_lookup (tdp, toname, RENAME, &tnp, ds, tocred);
if (err == EAGAIN)
@@ -124,7 +124,7 @@ diskfs_S_dir_rename (struct protid *fromcred,
{
diskfs_drop_dirstat (tdp, ds);
diskfs_nrele (fnp);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
return err;
}
@@ -135,7 +135,7 @@ diskfs_S_dir_rename (struct protid *fromcred,
diskfs_drop_dirstat (tdp, ds);
diskfs_nrele (fnp);
diskfs_nput (tnp);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
mach_port_deallocate (mach_task_self (), tocred->pi.port_right);
return 0;
}
@@ -146,11 +146,11 @@ diskfs_S_dir_rename (struct protid *fromcred,
diskfs_drop_dirstat (tdp, ds);
diskfs_nrele (fnp);
diskfs_nput (tnp);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
return EISDIR;
}
- mutex_lock (&fnp->lock);
+ pthread_mutex_lock (&fnp->lock);
/* Increment the link count for the upcoming link */
if (fnp->dn_stat.st_nlink == diskfs_link_max - 1)
@@ -159,7 +159,7 @@ diskfs_S_dir_rename (struct protid *fromcred,
diskfs_nput (fnp);
if (tnp)
diskfs_nput (tnp);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
return EMLINK;
}
fnp->dn_stat.st_nlink++;
@@ -184,8 +184,8 @@ diskfs_S_dir_rename (struct protid *fromcred,
if (diskfs_synchronous)
diskfs_node_update (tdp, 1);
- mutex_unlock (&tdp->lock);
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&fnp->lock);
if (err)
{
diskfs_nrele (fnp);
@@ -197,12 +197,12 @@ diskfs_S_dir_rename (struct protid *fromcred,
/* Now we remove the source. Unfortunately, we haven't held
fdp locked (nor could we), so someone else might have already
removed it. */
- mutex_lock (&fdp->lock);
+ pthread_mutex_lock (&fdp->lock);
err = diskfs_lookup (fdp, fromname, REMOVE, &tmpnp, ds, fromcred);
if (err)
{
diskfs_drop_dirstat (tdp, ds);
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
diskfs_nrele (fnp);
return err;
}
@@ -213,7 +213,7 @@ diskfs_S_dir_rename (struct protid *fromcred,
diskfs_drop_dirstat (tdp, ds);
diskfs_nput (tmpnp);
diskfs_nrele (fnp);
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
mach_port_deallocate (mach_task_self (), tocred->pi.port_right);
return 0;
}
@@ -231,7 +231,7 @@ diskfs_S_dir_rename (struct protid *fromcred,
diskfs_node_update (fnp, 1);
diskfs_nput (fnp);
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
if (!err)
mach_port_deallocate (mach_task_self (), tocred->pi.port_right);
diff --git a/libdiskfs/dir-renamed.c b/libdiskfs/dir-renamed.c
index 3064dbaf..3990b138 100644
--- a/libdiskfs/dir-renamed.c
+++ b/libdiskfs/dir-renamed.c
@@ -76,7 +76,7 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
struct dirstat *ds;
struct dirstat *tmpds;
- mutex_lock (&tdp->lock);
+ pthread_mutex_lock (&tdp->lock);
diskfs_nref (tdp); /* reference and lock will get consumed by
checkpath */
err = checkpath (fnp, tdp, tocred);
@@ -86,9 +86,9 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
/* Now, lock the parent directories. This is legal because tdp is not
a child of fnp (guaranteed by checkpath above). */
- mutex_lock (&fdp->lock);
+ pthread_mutex_lock (&fdp->lock);
if (fdp != tdp)
- mutex_lock (&tdp->lock);
+ pthread_mutex_lock (&tdp->lock);
/* 1: Lookup target; if it exists, make sure it's an empty directory. */
ds = buf;
@@ -99,9 +99,9 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
{
diskfs_drop_dirstat (tdp, ds);
diskfs_nput (tnp);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
if (fdp != tdp)
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
return 0;
}
@@ -167,9 +167,9 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
tdp. */
if (fnp->dn_stat.st_nlink == diskfs_link_max - 1)
{
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&fnp->lock);
diskfs_drop_dirstat (tdp, ds);
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
if (tnp)
diskfs_nput (tnp);
return EMLINK;
@@ -203,7 +203,7 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
/* 4: Remove the entry in fdp. */
ds = buf;
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&fnp->lock);
err = diskfs_lookup (fdp, fromname, REMOVE, &tmpnp, ds, fromcred);
assert (!tmpnp || tmpnp == fnp);
if (tmpnp)
@@ -223,13 +223,13 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname,
out:
if (tdp)
- mutex_unlock (&tdp->lock);
+ pthread_mutex_unlock (&tdp->lock);
if (tnp)
diskfs_nput (tnp);
if (fdp && fdp != tdp)
- mutex_unlock (&fdp->lock);
+ pthread_mutex_unlock (&fdp->lock);
if (fnp)
- mutex_unlock (&fnp->lock);
+ pthread_mutex_unlock (&fnp->lock);
if (ds)
diskfs_drop_dirstat (tdp, ds);
return err;
diff --git a/libdiskfs/dir-rmdir.c b/libdiskfs/dir-rmdir.c
index a90ff07b..83ec37b3 100644
--- a/libdiskfs/dir-rmdir.c
+++ b/libdiskfs/dir-rmdir.c
@@ -38,7 +38,7 @@ diskfs_S_dir_rmdir (struct protid *dircred,
if (ds)
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
@@ -50,7 +50,7 @@ diskfs_S_dir_rmdir (struct protid *dircred,
if (diskfs_check_readonly ())
return EROFS;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
error = diskfs_lookup (dnp, name, REMOVE, &np, ds, dircred);
if (error)
@@ -61,7 +61,7 @@ diskfs_S_dir_rmdir (struct protid *dircred,
/* Attempt to rmdir(".") */
diskfs_nrele (np);
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return EINVAL;
}
diff --git a/libdiskfs/dir-unlink.c b/libdiskfs/dir-unlink.c
index e40aead5..f687a16e 100644
--- a/libdiskfs/dir-unlink.c
+++ b/libdiskfs/dir-unlink.c
@@ -37,7 +37,7 @@ diskfs_S_dir_unlink (struct protid *dircred,
if (diskfs_check_readonly ())
return EROFS;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
error = diskfs_lookup (dnp, name, REMOVE, &np, ds, dircred);
if (error == EAGAIN)
@@ -45,7 +45,7 @@ diskfs_S_dir_unlink (struct protid *dircred,
if (error)
{
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
@@ -58,7 +58,7 @@ diskfs_S_dir_unlink (struct protid *dircred,
else
diskfs_nput (np);
diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return EPERM; /* 1003.1-1996 5.5.1.4 */
}
@@ -68,7 +68,7 @@ diskfs_S_dir_unlink (struct protid *dircred,
if (error)
{
diskfs_nput (np);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
return error;
}
@@ -86,7 +86,7 @@ diskfs_S_dir_unlink (struct protid *dircred,
diskfs_nrele (np);
else
diskfs_nput (np);
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
if (control)
{
diff --git a/libdiskfs/disk-pager.c b/libdiskfs/disk-pager.c
index fefd2ef4..5795a281 100644
--- a/libdiskfs/disk-pager.c
+++ b/libdiskfs/disk-pager.c
@@ -21,6 +21,8 @@
#include <hurd/sigpreempt.h>
#include <error.h>
+__thread struct disk_image_user *diskfs_exception_diu;
+
struct pager *diskfs_disk_pager;
static void fault_handler (int sig, long int sigcode, struct sigcontext *scp);
@@ -33,8 +35,8 @@ static struct hurd_signal_preemptor preemptor =
/* A top-level function for the paging thread that just services paging
requests. */
-static void
-service_paging_requests (any_t arg)
+static void *
+service_paging_requests (void *arg)
{
struct port_bucket *pager_bucket = arg;
for (;;)
@@ -42,6 +44,7 @@ service_paging_requests (any_t arg)
pager_demuxer,
1000 * 60 * 2,
1000 * 60 * 10, 0);
+ return NULL;
}
void
@@ -49,12 +52,19 @@ diskfs_start_disk_pager (struct user_pager_info *upi,
struct port_bucket *pager_bucket, int may_cache,
size_t size, void **image)
{
+ pthread_t thread;
error_t err;
mach_port_t disk_pager_port;
/* Make a thread to service paging requests. */
- cthread_detach (cthread_fork ((cthread_fn_t) service_paging_requests,
- (any_t)pager_bucket));
+ err = pthread_create (&thread, NULL, service_paging_requests, pager_bucket);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
/* Create the pager. */
diskfs_disk_pager = pager_create (upi, pager_bucket,
@@ -87,11 +97,10 @@ diskfs_start_disk_pager (struct user_pager_info *upi,
static void
fault_handler (int sig, long int sigcode, struct sigcontext *scp)
{
- jmp_buf *env = cthread_data (cthread_self ());
error_t err;
#ifndef NDEBUG
- if (!env)
+ if (diskfs_exception_diu == NULL)
{
error (0, 0,
"BUG: unexpected fault on disk image (%d, %#lx) in [%#lx,%#lx)"
@@ -107,7 +116,7 @@ fault_handler (int sig, long int sigcode, struct sigcontext *scp)
#endif
/* Clear the record, since the faulting thread will not. */
- cthread_set_data (cthread_self (), 0);
+ diskfs_exception_diu = NULL;
/* Fetch the error code from the pager. */
assert (scp->sc_error == EKERN_MEMORY_ERROR);
@@ -115,5 +124,5 @@ fault_handler (int sig, long int sigcode, struct sigcontext *scp)
assert (err);
/* Make `diskfault_catch' return the error code. */
- longjmp (*env, err);
+ longjmp (diskfs_exception_diu->env, err);
}
diff --git a/libdiskfs/diskfs-pager.h b/libdiskfs/diskfs-pager.h
index 4ec0b27b..bd0a050c 100644
--- a/libdiskfs/diskfs-pager.h
+++ b/libdiskfs/diskfs-pager.h
@@ -22,11 +22,13 @@
#include <hurd/pager.h>
#include <hurd/ports.h>
#include <setjmp.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
+extern __thread struct disk_image_user *diskfs_exception_diu;
+
/* Start a pager for the whole disk, and store it in DISKFS_DISK_PAGER,
preparing a signal preemptor so that the `diskfs_catch_exception' macro
below works. SIZE should be the size of the image to map, and the address
@@ -51,10 +53,10 @@ struct disk_image_user
({ \
struct disk_image_user *diu = alloca (sizeof *diu); \
error_t err; \
- diu->next = (void *) cthread_data (cthread_self ()); \
+ diu->next = diskfs_exception_diu; \
err = setjmp (diu->env); \
if (err == 0) \
- cthread_set_data (cthread_self (), diu); \
+ diskfs_exception_diu = diu; \
err; \
})
@@ -62,8 +64,8 @@ struct disk_image_user
Any unexpected fault hereafter will crash the program. */
#define diskfs_end_catch_exception() \
({ \
- struct disk_image_user *diu = (void *) cthread_data (cthread_self ()); \
- cthread_set_data (cthread_self (), diu->next); \
+ struct disk_image_user *diu = diskfs_exception_diu; \
+ diskfs_exception_diu = diu->next; \
})
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 2051e41d..0f9c1d39 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -22,7 +22,7 @@
#include <assert.h>
#include <unistd.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <hurd/ports.h>
#include <hurd/fshelp.h>
#include <hurd/iohelp.h>
@@ -90,7 +90,7 @@ struct node
int dn_set_mtime;
int dn_stat_dirty;
- struct mutex lock;
+ pthread_mutex_t lock;
int references; /* hard references */
int light_references; /* light references */
@@ -174,7 +174,7 @@ extern const char *diskfs_boot_init_program;
/* Hold this lock while do fsys level operations. Innocuous users can just
hold a reader lock, and anyone who's going to do nasty things that would
screw anyone else should hold a writer lock. */
-extern struct rwlock diskfs_fsys_lock;
+extern pthread_rwlock_t diskfs_fsys_lock;
extern volatile struct mapped_time_value *diskfs_mtime;
@@ -184,7 +184,7 @@ extern volatile struct mapped_time_value *diskfs_mtime;
be done by format independent code. */
extern int diskfs_synchronous;
-extern spin_lock_t diskfs_node_refcnt_lock;
+extern pthread_spinlock_t diskfs_node_refcnt_lock;
extern int pager_port_type;
diff --git a/libdiskfs/file-access.c b/libdiskfs/file-access.c
index 4a5eb17d..f7e129aa 100644
--- a/libdiskfs/file-access.c
+++ b/libdiskfs/file-access.c
@@ -29,7 +29,7 @@ diskfs_S_file_check_access (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
*type = 0;
if (fshelp_access (&np->dn_stat, S_IREAD, cred->user) == 0)
*type |= O_READ;
@@ -38,7 +38,7 @@ diskfs_S_file_check_access (struct protid *cred,
if (fshelp_access (&np->dn_stat, S_IEXEC, cred->user) == 0)
*type |= O_EXEC;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/file-chg.c b/libdiskfs/file-chg.c
index 22edc69c..2674398f 100644
--- a/libdiskfs/file-chg.c
+++ b/libdiskfs/file-chg.c
@@ -30,18 +30,18 @@ diskfs_S_file_notice_changes (struct protid *cred, mach_port_t notify)
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = file_changed (notify, np->filemod_tick, FILE_CHANGED_NULL, 0, 0);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
req = malloc (sizeof (struct modreq));
req->port = notify;
req->next = np->filemod_reqs;
np->filemod_reqs = req;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/file-exec.c b/libdiskfs/file-exec.c
index 452240c0..9572dbed 100644
--- a/libdiskfs/file-exec.c
+++ b/libdiskfs/file-exec.c
@@ -85,11 +85,11 @@ diskfs_S_file_exec (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
mode = np->dn_stat.st_mode;
uid = np->dn_stat.st_uid;
gid = np->dn_stat.st_gid;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (_diskfs_noexec)
RETURN (EACCES);
diff --git a/libdiskfs/file-get-fs-opts.c b/libdiskfs/file-get-fs-opts.c
index b3bca821..1e70da23 100644
--- a/libdiskfs/file-get-fs-opts.c
+++ b/libdiskfs/file-get-fs-opts.c
@@ -39,9 +39,9 @@ diskfs_S_file_get_fs_options (struct protid *cred,
if (err)
return err;
- rwlock_reader_lock (&diskfs_fsys_lock);
+ pthread_rwlock_rdlock (&diskfs_fsys_lock);
err = diskfs_append_args (&argz, &argz_len);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
if (! err)
/* Move ARGZ from a malloced buffer into a vm_alloced one. */
diff --git a/libdiskfs/file-get-trans.c b/libdiskfs/file-get-trans.c
index e77dba82..11ed439e 100644
--- a/libdiskfs/file-get-trans.c
+++ b/libdiskfs/file-get-trans.c
@@ -35,7 +35,7 @@ diskfs_S_file_get_translator (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* First look for short-circuited translators. */
if (S_ISLNK (np->dn_stat.st_mode))
@@ -132,7 +132,7 @@ diskfs_S_file_get_translator (struct protid *cred,
}
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
diff --git a/libdiskfs/file-get-transcntl.c b/libdiskfs/file-get-transcntl.c
index 528529fb..c7fad91a 100644
--- a/libdiskfs/file-get-transcntl.c
+++ b/libdiskfs/file-get-transcntl.c
@@ -32,7 +32,7 @@ diskfs_S_file_get_translator_cntl (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
error = fshelp_isowner (&np->dn_stat, cred->user);
if (!error)
@@ -42,7 +42,7 @@ diskfs_S_file_get_translator_cntl (struct protid *cred,
if (!error)
*ctltype = MACH_MSG_TYPE_MOVE_SEND;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
diff --git a/libdiskfs/file-getcontrol.c b/libdiskfs/file-getcontrol.c
index 23afb7cb..fc6f777e 100644
--- a/libdiskfs/file-getcontrol.c
+++ b/libdiskfs/file-getcontrol.c
@@ -40,9 +40,9 @@ diskfs_S_file_getcontrol (struct protid *cred,
if (error)
return error;
- spin_lock (&_diskfs_control_lock);
+ pthread_spin_lock (&_diskfs_control_lock);
_diskfs_ncontrol_ports++;
- spin_unlock (&_diskfs_control_lock);
+ pthread_spin_unlock (&_diskfs_control_lock);
*control = ports_get_right (newpi);
*controltype = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
diff --git a/libdiskfs/file-getfh.c b/libdiskfs/file-getfh.c
index 2dcf68e5..035705b5 100644
--- a/libdiskfs/file-getfh.c
+++ b/libdiskfs/file-getfh.c
@@ -41,7 +41,7 @@ diskfs_S_file_getfh (struct protid *cred, char **fh, size_t *fh_len)
node = cred->po->np;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
if (*fh_len < sizeof (union diskfs_fhandle))
*fh = mmap (0, sizeof (union diskfs_fhandle), PROT_READ|PROT_WRITE,
@@ -54,7 +54,7 @@ diskfs_S_file_getfh (struct protid *cred, char **fh, size_t *fh_len)
f->data.cache_id = node->cache_id;
f->data.gen = node->dn_stat.st_gen;
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
return 0;
}
diff --git a/libdiskfs/file-lock-stat.c b/libdiskfs/file-lock-stat.c
index 75341617..4c371e29 100644
--- a/libdiskfs/file-lock-stat.c
+++ b/libdiskfs/file-lock-stat.c
@@ -30,9 +30,9 @@ diskfs_S_file_lock_stat (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
*mystatus = cred->po->lock_status;
*otherstatus = cred->po->np->userlock.type;
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/file-lock.c b/libdiskfs/file-lock.c
index 4a348546..441daeb1 100644
--- a/libdiskfs/file-lock.c
+++ b/libdiskfs/file-lock.c
@@ -28,10 +28,10 @@ diskfs_S_file_lock (struct protid *cred, int flags)
error_t err;
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
err = fshelp_acquire_lock (&cred->po->np->userlock, &cred->po->lock_status,
&cred->po->np->lock, flags);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return err;
}
diff --git a/libdiskfs/file-reparent.c b/libdiskfs/file-reparent.c
index e659bcf0..da6a51d2 100644
--- a/libdiskfs/file-reparent.c
+++ b/libdiskfs/file-reparent.c
@@ -37,7 +37,7 @@ diskfs_S_file_reparent (struct protid *cred, mach_port_t parent,
node = cred->po->np;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
err = diskfs_make_peropen (node, cred->po->openstat, cred->po, &new_po);
if (! err)
{
@@ -45,7 +45,7 @@ diskfs_S_file_reparent (struct protid *cred, mach_port_t parent,
if (err)
diskfs_release_peropen (new_po);
}
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
if (! err)
{
diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c
index c9b2c613..37980015 100644
--- a/libdiskfs/file-set-trans.c
+++ b/libdiskfs/file-set-trans.c
@@ -48,12 +48,12 @@ diskfs_S_file_set_translator (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
error = fshelp_isowner (&np->dn_stat, cred->user);
if (error)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
@@ -63,20 +63,20 @@ diskfs_S_file_set_translator (struct protid *cred,
error = fshelp_fetch_control (&np->transbox, &control);
if (error)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
if ((control != MACH_PORT_NULL) && ((active_flags & FS_TRANS_EXCL) == 0))
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
error = fsys_goaway (control, killtrans_flags);
mach_port_deallocate (mach_task_self (), control);
if (error && (error != MIG_SERVER_DIED)
&& (error != MACH_SEND_INVALID_DEST))
return error;
error = 0;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
}
else if (control != MACH_PORT_NULL)
mach_port_deallocate (mach_task_self (), control);
@@ -87,7 +87,7 @@ diskfs_S_file_set_translator (struct protid *cred,
&& (passive_flags & FS_TRANS_EXCL)
&& (np->dn_stat.st_mode & S_IPTRANS))
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EBUSY;
}
@@ -97,7 +97,7 @@ diskfs_S_file_set_translator (struct protid *cred,
active_flags & FS_TRANS_EXCL);
if (error)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
}
@@ -129,7 +129,7 @@ diskfs_S_file_set_translator (struct protid *cred,
changes, the links will be lost. Perhaps it might be
allowed for empty directories, but that's too much of a
pain. */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EISDIR;
}
if (newmode == S_IFBLK || newmode == S_IFCHR)
@@ -143,7 +143,7 @@ diskfs_S_file_set_translator (struct protid *cred,
assert (arg <= passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
major = strtol (arg, 0, 0);
@@ -152,7 +152,7 @@ diskfs_S_file_set_translator (struct protid *cred,
assert (arg < passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
minor = strtol (arg, 0, 0);
@@ -161,7 +161,7 @@ diskfs_S_file_set_translator (struct protid *cred,
makedev (major, minor));
if (error)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
np->dn_stat.st_rdev = makedev (major, minor);
@@ -174,7 +174,7 @@ diskfs_S_file_set_translator (struct protid *cred,
assert (arg <= passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -187,7 +187,7 @@ diskfs_S_file_set_translator (struct protid *cred,
1, cred, 0);
if (error)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
}
@@ -198,13 +198,13 @@ diskfs_S_file_set_translator (struct protid *cred,
np->dn_stat.st_mode = newmode;
diskfs_node_update (np, diskfs_synchronous);
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
}
error = diskfs_set_translator (np, passive, passivelen, cred);
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return error;
}
diff --git a/libdiskfs/file-sync.c b/libdiskfs/file-sync.c
index 94ffa9ac..20fa005c 100644
--- a/libdiskfs/file-sync.c
+++ b/libdiskfs/file-sync.c
@@ -34,9 +34,9 @@ diskfs_S_file_sync (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
iohelp_get_conch (&np->conch);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
diskfs_file_update (np, wait);
return 0;
}
diff --git a/libdiskfs/file-syncfs.c b/libdiskfs/file-syncfs.c
index a3b7622e..b7d20a88 100644
--- a/libdiskfs/file-syncfs.c
+++ b/libdiskfs/file-syncfs.c
@@ -32,13 +32,13 @@ diskfs_S_file_syncfs (struct protid *cred,
mach_port_t control;
error = fshelp_fetch_control (&np->transbox, &control);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error && (control != MACH_PORT_NULL))
{
fsys_syncfs (control, wait, 1);
mach_port_deallocate (mach_task_self (), control);
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
return 0;
}
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index e083032e..2e11da4c 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -65,8 +65,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
idvec_set_ids (user.gids, gids, ngids);
#define drop_idvec() idvec_free (user.gids); idvec_free (user.uids)
- rwlock_reader_lock (&diskfs_fsys_lock);
- mutex_lock (&diskfs_root_node->lock);
+ pthread_rwlock_rdlock (&diskfs_fsys_lock);
+ pthread_mutex_lock (&diskfs_root_node->lock);
/* This code is similar (but not the same as) the code in
dir-lookup.c that does the same thing. Perhaps a way should
@@ -85,8 +85,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
retry, retryname, returned_port);
if (error != ENOENT)
{
- mutex_unlock (&diskfs_root_node->lock);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
drop_idvec ();
if (!error)
*returned_port_poly = MACH_MSG_TYPE_MOVE_SEND;
@@ -111,8 +111,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
0, &amt);
pathbuf[amt] = '\0';
- mutex_unlock (&diskfs_root_node->lock);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
if (error)
{
drop_idvec ();
@@ -164,8 +164,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
if (error)
{
- mutex_unlock (&diskfs_root_node->lock);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
drop_idvec ();
return error;
}
@@ -196,8 +196,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
ports_port_deref (newpi);
}
- mutex_unlock (&diskfs_root_node->lock);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
ports_port_deref (pt);
diff --git a/libdiskfs/fsys-options.c b/libdiskfs/fsys-options.c
index ea5ee8c5..bb183198 100644
--- a/libdiskfs/fsys-options.c
+++ b/libdiskfs/fsys-options.c
@@ -45,7 +45,7 @@ diskfs_S_fsys_set_options (fsys_t fsys,
mach_port_t control;
error = fshelp_fetch_control (&np->transbox, &control);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error && (control != MACH_PORT_NULL))
{
error = fsys_set_options (control, data, len, do_children);
@@ -53,7 +53,7 @@ diskfs_S_fsys_set_options (fsys_t fsys,
}
else
error = 0;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if ((error == MIG_SERVER_DIED) || (error == MACH_SEND_INVALID_DEST))
error = 0;
@@ -65,16 +65,16 @@ diskfs_S_fsys_set_options (fsys_t fsys,
if (do_children)
{
- rwlock_writer_lock (&diskfs_fsys_lock);
+ pthread_rwlock_wrlock (&diskfs_fsys_lock);
err = diskfs_node_iterate (helper);
- rwlock_writer_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
}
if (!err)
{
- rwlock_writer_lock (&diskfs_fsys_lock);
+ pthread_rwlock_wrlock (&diskfs_fsys_lock);
err = diskfs_set_options (data, len);
- rwlock_writer_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
}
ports_port_deref (pt);
@@ -101,9 +101,9 @@ diskfs_S_fsys_get_options (fsys_t fsys,
if (err)
return err;
- rwlock_reader_lock (&diskfs_fsys_lock);
+ pthread_rwlock_rdlock (&diskfs_fsys_lock);
err = diskfs_append_args (&argz, &argz_len);
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
if (! err)
/* Move ARGZ from a malloced buffer into a vm_alloced one. */
diff --git a/libdiskfs/fsys-syncfs.c b/libdiskfs/fsys-syncfs.c
index 503eea4c..7d0c4849 100644
--- a/libdiskfs/fsys-syncfs.c
+++ b/libdiskfs/fsys-syncfs.c
@@ -39,20 +39,20 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
mach_port_t control;
error = fshelp_fetch_control (&np->transbox, &control);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error && (control != MACH_PORT_NULL))
{
fsys_syncfs (control, wait, 1);
mach_port_deallocate (mach_task_self (), control);
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
return 0;
}
if (!pi)
return EOPNOTSUPP;
- rwlock_reader_lock (&diskfs_fsys_lock);
+ pthread_rwlock_rdlock (&diskfs_fsys_lock);
if (children)
diskfs_node_iterate (helper);
@@ -66,7 +66,7 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
diskfs_set_hypermetadata (wait, 0);
}
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
ports_port_deref (pi);
diff --git a/libdiskfs/ifsock.c b/libdiskfs/ifsock.c
index 3e9b8325..1da81b85 100644
--- a/libdiskfs/ifsock.c
+++ b/libdiskfs/ifsock.c
@@ -22,7 +22,7 @@
#include <stdio.h>
#include <hurd/socket.h>
-static spin_lock_t pflocalserverlock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t pflocalserverlock = PTHREAD_SPINLOCK_INITIALIZER;
static mach_port_t pflocalserver = MACH_PORT_NULL;
kern_return_t
@@ -39,16 +39,16 @@ diskfs_S_ifsock_getsockaddr (struct protid *cred,
np = cred->po->np;
retry:
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if ((np->dn_stat.st_mode & S_IFMT) != S_IFSOCK)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EOPNOTSUPP;
}
err = fshelp_access (&np->dn_stat, S_IWRITE, cred->user);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
@@ -58,17 +58,17 @@ diskfs_S_ifsock_getsockaddr (struct protid *cred,
mach_port_t sockaddr;
mach_port_t old;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
/* Fetch a port to the PF_LOCAL server, caching it. */
- spin_lock (&pflocalserverlock);
+ pthread_spin_lock (&pflocalserverlock);
if (pflocalserver == MACH_PORT_NULL)
{
/* Find out who the PF_LOCAL server is. */
char buf[100];
- spin_unlock (&pflocalserverlock);
+ pthread_spin_unlock (&pflocalserverlock);
/* Look it up */
sprintf (buf, "%s/%d", _SERVERS_SOCKET, PF_LOCAL);
@@ -77,17 +77,17 @@ diskfs_S_ifsock_getsockaddr (struct protid *cred,
return EIEIO;
/* Set it unless someone is already here */
- spin_lock (&pflocalserverlock);
+ pthread_spin_lock (&pflocalserverlock);
if (pflocalserver != MACH_PORT_NULL)
mach_port_deallocate (mach_task_self (), server);
else
pflocalserver = server;
- spin_unlock (&pflocalserverlock);
+ pthread_spin_unlock (&pflocalserverlock);
goto retry;
}
server = pflocalserver;
- spin_unlock (&pflocalserverlock);
+ pthread_spin_unlock (&pflocalserverlock);
/* Create an address for the node */
err = socket_fabricate_address (server, AF_LOCAL, &sockaddr);
@@ -95,19 +95,19 @@ diskfs_S_ifsock_getsockaddr (struct protid *cred,
&& restart_tries++ == 0)
/* The PF_LOCAL server died; try to restart it. */
{
- spin_lock (&pflocalserverlock);
+ pthread_spin_lock (&pflocalserverlock);
if (pflocalserver == server)
pflocalserver = MACH_PORT_NULL;
- spin_unlock (&pflocalserverlock);
+ pthread_spin_unlock (&pflocalserverlock);
goto retry;
}
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EIEIO;
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (np->sockaddr != MACH_PORT_NULL)
/* Someone beat us */
mach_port_deallocate (mach_task_self (), sockaddr);
@@ -129,7 +129,7 @@ diskfs_S_ifsock_getsockaddr (struct protid *cred,
}
*address = np->sockaddr;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/init-first.c b/libdiskfs/init-first.c
index d91345be..6dd5fc4f 100644
--- a/libdiskfs/init-first.c
+++ b/libdiskfs/init-first.c
@@ -27,8 +27,8 @@ static int thread_timeout = 1000 * 60 * 2; /* two minutes */
static int server_timeout = 1000 * 60 * 10; /* ten minutes */
-static any_t
-master_thread_function (any_t demuxer)
+static void *
+master_thread_function (void *demuxer)
{
error_t err;
@@ -45,12 +45,21 @@ master_thread_function (any_t demuxer)
exit (0);
/* NOTREACHED */
- return (any_t) 0;
+ return NULL;
}
void
diskfs_spawn_first_thread (ports_demuxer_type demuxer)
{
- cthread_detach (cthread_fork ((cthread_fn_t) master_thread_function,
- (any_t) demuxer));
+ pthread_t thread;
+ error_t err;
+
+ err = pthread_create (&thread, NULL, master_thread_function, demuxer);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
diff --git a/libdiskfs/init-init.c b/libdiskfs/init-init.c
index cd0c1b29..35be7edd 100644
--- a/libdiskfs/init-init.c
+++ b/libdiskfs/init-init.c
@@ -29,7 +29,7 @@ mach_port_t diskfs_default_pager;
mach_port_t diskfs_auth_server_port;
volatile struct mapped_time_value *diskfs_mtime;
-struct rwlock diskfs_fsys_lock = RWLOCK_INITIALIZER;
+pthread_rwlock_t diskfs_fsys_lock = PTHREAD_RWLOCK_INITIALIZER;
mach_port_t diskfs_fsys_identity;
int _diskfs_nosuid, _diskfs_noexec;
@@ -37,9 +37,9 @@ int _diskfs_noatime;
struct hurd_port _diskfs_exec_portcell;
-spin_lock_t diskfs_node_refcnt_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t diskfs_node_refcnt_lock = PTHREAD_SPINLOCK_INITIALIZER;
-spin_lock_t _diskfs_control_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t _diskfs_control_lock = PTHREAD_SPINLOCK_INITIALIZER;
int _diskfs_ncontrol_ports;
struct port_class *diskfs_protid_class;
@@ -101,7 +101,7 @@ diskfs_init_diskfs (void)
void
_diskfs_control_clean (void *arg __attribute__ ((unused)))
{
- spin_lock (&_diskfs_control_lock);
+ pthread_spin_lock (&_diskfs_control_lock);
_diskfs_ncontrol_ports--;
- spin_unlock (&_diskfs_control_lock);
+ pthread_spin_unlock (&_diskfs_control_lock);
}
diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c
index ff57db38..2c0814fd 100644
--- a/libdiskfs/init-startup.c
+++ b/libdiskfs/init-startup.c
@@ -48,7 +48,7 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags)
while (*_diskfs_chroot_directory == '/')
++_diskfs_chroot_directory;
- mutex_lock (&diskfs_root_node->lock);
+ pthread_mutex_lock (&diskfs_root_node->lock);
/* Create a protid we can use in diskfs_lookup. */
err = diskfs_make_peropen (diskfs_root_node, O_READ|O_EXEC,
@@ -60,7 +60,7 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags)
/* Look up the directory name. */
err = diskfs_lookup (diskfs_root_node, _diskfs_chroot_directory,
LOOKUP, &np, NULL, rootpi);
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
ports_port_deref (rootpi);
if (err == EAGAIN)
@@ -71,7 +71,7 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags)
if (!S_ISDIR (np->dn_stat.st_mode))
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
error (1, ENOTDIR, "%s", _diskfs_chroot_directory);
}
@@ -81,7 +81,7 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags)
if _diskfs_chroot_directory is non-null. */
old = diskfs_root_node;
diskfs_root_node = np;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
diskfs_nput (old);
}
@@ -138,7 +138,7 @@ diskfs_S_startup_dosync (mach_port_t handle)
diskfs_sync_everything (0);
diskfs_set_hypermetadata (0, 0);
- rwlock_writer_lock (&diskfs_fsys_lock);
+ pthread_rwlock_wrlock (&diskfs_fsys_lock);
/* Permit all the current RPC's to finish, and then suspend new ones */
err = ports_inhibit_class_rpcs (diskfs_protid_class);
@@ -158,7 +158,7 @@ diskfs_S_startup_dosync (mach_port_t handle)
ports_resume_class_rpcs (diskfs_protid_class);
}
- rwlock_writer_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
}
ports_port_deref (pi);
diff --git a/libdiskfs/io-duplicate.c b/libdiskfs/io-duplicate.c
index 3cbf8f7b..45c4df5d 100644
--- a/libdiskfs/io-duplicate.c
+++ b/libdiskfs/io-duplicate.c
@@ -30,7 +30,7 @@ diskfs_S_io_duplicate (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
err = diskfs_create_protid (cred->po, cred->user, &newpi);
if (! err)
@@ -40,7 +40,7 @@ diskfs_S_io_duplicate (struct protid *cred,
ports_port_deref (newpi);
}
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return err;
}
diff --git a/libdiskfs/io-get-conch.c b/libdiskfs/io-get-conch.c
index 6be35f0b..fa63a398 100644
--- a/libdiskfs/io-get-conch.c
+++ b/libdiskfs/io-get-conch.c
@@ -29,16 +29,16 @@ diskfs_S_io_get_conch (struct protid *cred)
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (!cred->mapped)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
iohelp_handle_io_get_conch (&np->conch, cred, cred->mapped);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-identity.c b/libdiskfs/io-identity.c
index 6f4e7546..0f3fce0f 100644
--- a/libdiskfs/io-identity.c
+++ b/libdiskfs/io-identity.c
@@ -38,9 +38,9 @@ diskfs_S_io_identity (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
inum = np->dn_stat.st_ino;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
err = fshelp_get_identity (diskfs_port_bucket, inum, id);
if (! err)
diff --git a/libdiskfs/io-map-cntl.c b/libdiskfs/io-map-cntl.c
index d615b046..2e9b9e98 100644
--- a/libdiskfs/io-map-cntl.c
+++ b/libdiskfs/io-map-cntl.c
@@ -29,7 +29,7 @@ diskfs_S_io_map_cntl (struct protid *cred,
return EOPNOTSUPP;
assert (__vm_page_size >= sizeof (struct shared_io));
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
if (!cred->mapped)
{
default_pager_object_create (diskfs_default_pager, &cred->shared_object,
@@ -39,15 +39,15 @@ diskfs_S_io_map_cntl (struct protid *cred,
VM_PROT_READ|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE, 0);
cred->mapped->shared_page_magic = SHARED_PAGE_MAGIC;
cred->mapped->conch_status = USER_HAS_NOT_CONCH;
- spin_lock_init (&cred->mapped->lock);
+ pthread_spin_init (&cred->mapped->lock, PTHREAD_PROCESS_PRIVATE);
*ctlobj = cred->shared_object;
*ctlobj_type = MACH_MSG_TYPE_COPY_SEND;
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
else
{
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return EBUSY;
}
}
diff --git a/libdiskfs/io-map.c b/libdiskfs/io-map.c
index 6268f2c5..3c1966dd 100644
--- a/libdiskfs/io-map.c
+++ b/libdiskfs/io-map.c
@@ -39,7 +39,7 @@ diskfs_S_io_map (struct protid *cred,
node = cred->po->np;
flags = cred->po->openstat & (O_READ | O_WRITE);
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
switch (flags)
{
case O_READ | O_WRITE:
@@ -59,7 +59,7 @@ diskfs_S_io_map (struct protid *cred,
goto error;
break;
}
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
*rdtype = MACH_MSG_TYPE_MOVE_SEND;
*wrtype = MACH_MSG_TYPE_MOVE_SEND;
@@ -67,7 +67,7 @@ diskfs_S_io_map (struct protid *cred,
return 0;
error:
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
return errno;
}
diff --git a/libdiskfs/io-modes-get.c b/libdiskfs/io-modes-get.c
index a959881b..6bed408b 100644
--- a/libdiskfs/io-modes-get.c
+++ b/libdiskfs/io-modes-get.c
@@ -26,9 +26,9 @@ diskfs_S_io_get_openmodes (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
*bits = cred->po->openstat;
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/io-modes-off.c b/libdiskfs/io-modes-off.c
index 25efcf22..b1e8f978 100644
--- a/libdiskfs/io-modes-off.c
+++ b/libdiskfs/io-modes-off.c
@@ -27,9 +27,9 @@ diskfs_S_io_clear_some_openmodes (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
iohelp_get_conch (&cred->po->np->conch);
cred->po->openstat &= ~(offbits & HONORED_STATE_MODES);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/io-modes-on.c b/libdiskfs/io-modes-on.c
index 3b7ff40c..c6ac3b12 100644
--- a/libdiskfs/io-modes-on.c
+++ b/libdiskfs/io-modes-on.c
@@ -27,9 +27,9 @@ diskfs_S_io_set_some_openmodes (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
iohelp_get_conch (&cred->po->np->conch);
cred->po->openstat |= (newbits & HONORED_STATE_MODES);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/io-modes-set.c b/libdiskfs/io-modes-set.c
index 2744a8f7..a8e2d7fa 100644
--- a/libdiskfs/io-modes-set.c
+++ b/libdiskfs/io-modes-set.c
@@ -27,10 +27,10 @@ diskfs_S_io_set_all_openmodes (struct protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
iohelp_get_conch (&cred->po->np->conch);
cred->po->openstat &= ~HONORED_STATE_MODES;
cred->po->openstat |= (newbits & HONORED_STATE_MODES);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/io-owner-get.c b/libdiskfs/io-owner-get.c
index 057aa6e2..2f3e7e33 100644
--- a/libdiskfs/io-owner-get.c
+++ b/libdiskfs/io-owner-get.c
@@ -29,8 +29,8 @@ diskfs_S_io_get_owner (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
*owner = np->owner;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-owner-mod.c b/libdiskfs/io-owner-mod.c
index c0977785..938c3d0d 100644
--- a/libdiskfs/io-owner-mod.c
+++ b/libdiskfs/io-owner-mod.c
@@ -29,8 +29,8 @@ diskfs_S_io_mod_owner (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
np->owner = owner;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-prenotify.c b/libdiskfs/io-prenotify.c
index f193f52b..4eb1c657 100644
--- a/libdiskfs/io-prenotify.c
+++ b/libdiskfs/io-prenotify.c
@@ -37,7 +37,7 @@ diskfs_S_io_prenotify (struct protid *cred,
np = cred->po->np;
/* Clamp it down */
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (!cred->mapped)
{
@@ -55,9 +55,9 @@ diskfs_S_io_prenotify (struct protid *cred,
{
/* The user didn't need to do this, so we'll make sure they
have the right shared page info. */
- spin_lock (&cred->mapped->lock);
+ pthread_spin_lock (&cred->mapped->lock);
iohelp_put_shared_data (cred);
- spin_unlock (&cred->mapped->lock);
+ pthread_spin_unlock (&cred->mapped->lock);
goto out;
}
@@ -67,6 +67,6 @@ diskfs_S_io_prenotify (struct protid *cred,
if (!err && np->filemod_reqs)
diskfs_notice_filechange (np, FILE_CHANGED_EXTEND, 0, end);
out:
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libdiskfs/io-read.c b/libdiskfs/io-read.c
index 787c0eae..c849434b 100644
--- a/libdiskfs/io-read.c
+++ b/libdiskfs/io-read.c
@@ -40,7 +40,7 @@ diskfs_S_io_read (struct protid *cred,
if (!(cred->po->openstat & O_READ))
return EBADF;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
iohelp_get_conch (&np->conch);
@@ -48,7 +48,7 @@ diskfs_S_io_read (struct protid *cred,
off = cred->po->filepointer;
if (off < 0)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -104,6 +104,6 @@ diskfs_S_io_read (struct protid *cred,
if (err && ourbuf)
munmap (buf, maxread);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libdiskfs/io-readable.c b/libdiskfs/io-readable.c
index ccc241ef..c3debac3 100644
--- a/libdiskfs/io-readable.c
+++ b/libdiskfs/io-readable.c
@@ -34,13 +34,13 @@ diskfs_S_io_readable (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
iohelp_get_conch (&np->conch);
if (np->dn_stat.st_size > cred->po->filepointer)
*amount = np->dn_stat.st_size - cred->po->filepointer;
else
*amount = 0;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-reauthenticate.c b/libdiskfs/io-reauthenticate.c
index 3c5da52d..69d78bc5 100644
--- a/libdiskfs/io-reauthenticate.c
+++ b/libdiskfs/io-reauthenticate.c
@@ -34,13 +34,13 @@ diskfs_S_io_reauthenticate (struct protid *cred,
/* This routine must carefully ignore EINTR because we
are a simpleroutine, so callers won't know to restart. */
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
do
err = diskfs_start_protid (cred->po, &newcred);
while (err == EINTR);
if (err)
{
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return err;
}
@@ -58,7 +58,7 @@ diskfs_S_io_reauthenticate (struct protid *cred,
mach_port_deallocate (mach_task_self (), newright);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
ports_port_deref (newcred);
diff --git a/libdiskfs/io-rel-conch.c b/libdiskfs/io-rel-conch.c
index c0257650..a42d1ba5 100644
--- a/libdiskfs/io-rel-conch.c
+++ b/libdiskfs/io-rel-conch.c
@@ -28,10 +28,10 @@ diskfs_S_io_release_conch (struct protid *cred)
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (!cred->mapped)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -39,6 +39,6 @@ diskfs_S_io_release_conch (struct protid *cred)
iohelp_handle_io_release_conch (&np->conch, cred);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-restrict-auth.c b/libdiskfs/io-restrict-auth.c
index c1560ac1..011aa19e 100644
--- a/libdiskfs/io-restrict-auth.c
+++ b/libdiskfs/io-restrict-auth.c
@@ -40,7 +40,7 @@ diskfs_S_io_restrict_auth (struct protid *cred,
if (err)
return err;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
err = diskfs_create_protid (cred->po, user, &newpi);
if (! err)
{
@@ -48,7 +48,7 @@ diskfs_S_io_restrict_auth (struct protid *cred,
*newportpoly = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
}
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
iohelp_free_iouser (user);
return err;
diff --git a/libdiskfs/io-revoke.c b/libdiskfs/io-revoke.c
index d42fb6c1..a07777e2 100644
--- a/libdiskfs/io-revoke.c
+++ b/libdiskfs/io-revoke.c
@@ -42,11 +42,11 @@ diskfs_S_io_revoke (struct protid *cred)
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = fshelp_isowner (&np->dn_stat, cred->user);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (err)
return err;
diff --git a/libdiskfs/io-seek.c b/libdiskfs/io-seek.c
index 71179816..9e3ff093 100644
--- a/libdiskfs/io-seek.c
+++ b/libdiskfs/io-seek.c
@@ -34,7 +34,7 @@ diskfs_S_io_seek (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
iohelp_get_conch (&np->conch);
switch (whence)
@@ -56,6 +56,6 @@ diskfs_S_io_seek (struct protid *cred,
break;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libdiskfs/io-sigio.c b/libdiskfs/io-sigio.c
index 229129bc..1e4c461b 100644
--- a/libdiskfs/io-sigio.c
+++ b/libdiskfs/io-sigio.c
@@ -28,9 +28,9 @@ diskfs_S_io_sigio (struct protid *cred)
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&cred->po->np->lock);
+ pthread_mutex_lock (&cred->po->np->lock);
if ((cred->po->openstat & O_FSYNC) || diskfs_synchronous)
diskfs_file_update (cred->po->np, 1);
- mutex_unlock (&cred->po->np->lock);
+ pthread_mutex_unlock (&cred->po->np->lock);
return 0;
}
diff --git a/libdiskfs/io-stat.c b/libdiskfs/io-stat.c
index 59f3187e..211b53a8 100644
--- a/libdiskfs/io-stat.c
+++ b/libdiskfs/io-stat.c
@@ -30,7 +30,7 @@ diskfs_S_io_stat (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
iohelp_get_conch (&np->conch);
if (diskfs_synchronous)
@@ -45,7 +45,7 @@ diskfs_S_io_stat (struct protid *cred,
if (cred->po->shadow_root == np || np == diskfs_root_node)
statbuf->st_mode |= S_IROOT;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libdiskfs/io-write.c b/libdiskfs/io-write.c
index a3c4199e..26e0be43 100644
--- a/libdiskfs/io-write.c
+++ b/libdiskfs/io-write.c
@@ -38,7 +38,7 @@ diskfs_S_io_write (struct protid *cred,
if (!(cred->po->openstat & O_WRITE))
return EBADF;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
assert (!S_ISDIR(np->dn_stat.st_mode));
@@ -89,6 +89,6 @@ diskfs_S_io_write (struct protid *cred,
if (!err && np->filemod_reqs)
diskfs_notice_filechange (np, FILE_CHANGED_WRITE, off, off + *amt);
out:
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libdiskfs/lookup.c b/libdiskfs/lookup.c
index 1f2a2588..bc2ad01e 100644
--- a/libdiskfs/lookup.c
+++ b/libdiskfs/lookup.c
@@ -29,7 +29,7 @@ static struct
int dot;
int dotdot;
} cache_misses;
-static spin_lock_t cm_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t cm_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Lookup in directory DP (which is locked) the name NAME. TYPE will
@@ -176,7 +176,7 @@ diskfs_lookup (struct node *dp, const char *name, enum lookup_type type,
{
err = diskfs_lookup_hard (dp, name, type, np, ds, cred);
- spin_lock (&cm_lock);
+ pthread_spin_lock (&cm_lock);
if (type == LOOKUP)
{
if (err == ENOENT)
@@ -193,7 +193,7 @@ diskfs_lookup (struct node *dp, const char *name, enum lookup_type type,
cache_misses.dotdot++;
}
}
- spin_unlock (&cm_lock);
+ pthread_spin_unlock (&cm_lock);
if (err && err != ENOENT)
return err;
diff --git a/libdiskfs/name-cache.c b/libdiskfs/name-cache.c
index f31482d4..8424ffee 100644
--- a/libdiskfs/name-cache.c
+++ b/libdiskfs/name-cache.c
@@ -53,7 +53,7 @@ struct lookup_cache
/* The contents of the cache in no particular order */
static struct cacheq lookup_cache = { sizeof (struct lookup_cache) };
-static spin_lock_t cache_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t cache_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Buffer to hold statistics */
static struct stats
@@ -104,7 +104,7 @@ diskfs_enter_lookup_cache (struct node *dir, struct node *np, const char *name)
if (name_len > CACHE_NAME_LEN - 1)
return;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
if (lookup_cache.length == 0)
/* There should always be an lru_cache; this being zero means that the
@@ -124,7 +124,7 @@ diskfs_enter_lookup_cache (struct node *dir, struct node *np, const char *name)
/* Now C becomes the MRU entry! */
cacheq_make_mru (&lookup_cache, c);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
}
/* Purge all references in the cache to NP as a node inside
@@ -134,7 +134,7 @@ diskfs_purge_lookup_cache (struct node *dp, struct node *np)
{
struct lookup_cache *c, *next;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
for (c = lookup_cache.mru; c; c = next)
{
/* Save C->hdr.next, since we may move C from this position. */
@@ -149,7 +149,7 @@ diskfs_purge_lookup_cache (struct node *dp, struct node *np)
entry. */
}
}
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
}
/* Register a negative hit for an entry in the Nth stat class */
@@ -202,7 +202,7 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
{
struct lookup_cache *c;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
c = find_cache (dir, name, strlen (name));
if (c)
@@ -215,14 +215,14 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
/* A negative cache entry. */
{
register_neg_hit (c->stati);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
return (struct node *)-1;
}
else if (id == dir->cache_id)
/* The cached node is the same as DIR. */
{
register_pos_hit (c->stati);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
diskfs_nref (dir);
return dir;
}
@@ -233,13 +233,13 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
error_t err;
register_pos_hit (c->stati);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
err = diskfs_cached_lookup (id, &np);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
/* In the window where DP was unlocked, we might
have lost. So check the cache again, and see
@@ -248,7 +248,7 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
if (!c || c->node_cache_id != id)
{
/* Lose */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
}
@@ -259,7 +259,7 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
}
register_miss ();
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
return 0;
}
diff --git a/libdiskfs/node-drop.c b/libdiskfs/node-drop.c
index c3d32c96..8a097da5 100644
--- a/libdiskfs/node-drop.c
+++ b/libdiskfs/node-drop.c
@@ -61,7 +61,7 @@ diskfs_drop_node (struct node *np)
will notice that the size is zero, and not have to
do anything. */
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
diskfs_truncate (np, 0);
/* Force allocsize to zero; if truncate consistently fails this
@@ -94,7 +94,7 @@ diskfs_drop_node (struct node *np)
assert (!np->sockaddr);
diskfs_node_norefs (np);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
}
diff --git a/libdiskfs/node-make.c b/libdiskfs/node-make.c
index 74fdda19..2b6ef2af 100644
--- a/libdiskfs/node-make.c
+++ b/libdiskfs/node-make.c
@@ -35,7 +35,7 @@ diskfs_make_node (struct disknode *dn)
np->dn_set_mtime = 0;
np->dn_stat_dirty = 0;
- mutex_init (&np->lock);
+ pthread_mutex_init (&np->lock, NULL);
np->references = 1;
np->light_references = 0;
np->owner = 0;
diff --git a/libdiskfs/node-nput.c b/libdiskfs/node-nput.c
index 2aad1b66..35f05b5d 100644
--- a/libdiskfs/node-nput.c
+++ b/libdiskfs/node-nput.c
@@ -29,14 +29,14 @@ diskfs_nput (struct node *np)
int tried_drop_softrefs = 0;
loop:
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
assert (np->references);
np->references--;
if (np->references + np->light_references == 0)
diskfs_drop_node (np);
else if (np->references == 0 && !tried_drop_softrefs)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
/* This is our cue that something akin to "last process closes file"
in the POSIX.1 sense happened, so make sure any pending node time
@@ -52,9 +52,9 @@ diskfs_nput (struct node *np)
routine, which might result in further recursive calls to
the ref-counting system. So we have to reacquire our
reference around the call to forestall disaster. */
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
diskfs_try_dropping_softrefs (np);
@@ -65,11 +65,11 @@ diskfs_nput (struct node *np)
/* Now we can drop the reference back... */
goto loop;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
else
{
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_unlock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_unlock (&np->lock);
}
}
diff --git a/libdiskfs/node-nputl.c b/libdiskfs/node-nputl.c
index 45b109ea..19596654 100644
--- a/libdiskfs/node-nputl.c
+++ b/libdiskfs/node-nputl.c
@@ -25,14 +25,14 @@
void
diskfs_nput_light (struct node *np)
{
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
assert (np->light_references);
np->light_references--;
if (np->references + np->light_references == 0)
diskfs_drop_node (np);
else
{
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_unlock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_unlock (&np->lock);
}
}
diff --git a/libdiskfs/node-nref.c b/libdiskfs/node-nref.c
index 753de65f..13cea056 100644
--- a/libdiskfs/node-nref.c
+++ b/libdiskfs/node-nref.c
@@ -27,14 +27,14 @@ void
diskfs_nref (struct node *np)
{
int new_hardref;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
np->references++;
new_hardref = (np->references == 1);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
if (new_hardref)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
diskfs_new_hardrefs (np);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
}
diff --git a/libdiskfs/node-nrefl.c b/libdiskfs/node-nrefl.c
index ce3b39dd..96922471 100644
--- a/libdiskfs/node-nrefl.c
+++ b/libdiskfs/node-nrefl.c
@@ -24,7 +24,7 @@
void
diskfs_nref_light (struct node *np)
{
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
np->light_references++;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
}
diff --git a/libdiskfs/node-nrele.c b/libdiskfs/node-nrele.c
index 9dbc5d8c..cc680893 100644
--- a/libdiskfs/node-nrele.c
+++ b/libdiskfs/node-nrele.c
@@ -31,35 +31,35 @@ diskfs_nrele (struct node *np)
int tried_drop_softrefs = 0;
loop:
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
assert (np->references);
np->references--;
if (np->references + np->light_references == 0)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
diskfs_drop_node (np);
}
else if (np->references == 0)
{
- mutex_lock (&np->lock);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
diskfs_lost_hardrefs (np);
if (!np->dn_stat.st_nlink && !tried_drop_softrefs)
{
/* Same issue here as in nput; see that for explanation */
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
diskfs_try_dropping_softrefs (np);
tried_drop_softrefs = 1;
/* Now we can drop the reference back... */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
goto loop;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
else
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
}
diff --git a/libdiskfs/node-nrelel.c b/libdiskfs/node-nrelel.c
index e61f6378..ee53b227 100644
--- a/libdiskfs/node-nrelel.c
+++ b/libdiskfs/node-nrelel.c
@@ -26,14 +26,14 @@
void
diskfs_nrele_light (struct node *np)
{
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
assert (np->light_references);
np->light_references--;
if (np->references + np->light_references == 0)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
diskfs_drop_node (np);
}
else
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
}
diff --git a/libdiskfs/peropen-rele.c b/libdiskfs/peropen-rele.c
index 6974e86a..08276ec3 100644
--- a/libdiskfs/peropen-rele.c
+++ b/libdiskfs/peropen-rele.c
@@ -22,11 +22,11 @@
void
diskfs_release_peropen (struct peropen *po)
{
- mutex_lock (&po->np->lock);
+ pthread_mutex_lock (&po->np->lock);
if (--po->refcnt)
{
- mutex_unlock (&po->np->lock);
+ pthread_mutex_unlock (&po->np->lock);
return;
}
diff --git a/libdiskfs/priv.h b/libdiskfs/priv.h
index 07464d56..bd23ab90 100644
--- a/libdiskfs/priv.h
+++ b/libdiskfs/priv.h
@@ -98,7 +98,7 @@ void _diskfs_control_clean (void *);
extern int _diskfs_ncontrol_ports;
/* Lock for _diskfs_ncontrol_ports. */
-extern spin_lock_t _diskfs_control_lock;
+extern pthread_spinlock_t _diskfs_control_lock;
/* Callback routines for active translator startup */
extern fshelp_fetch_root_callback1_t _diskfs_translator_callback1;
@@ -121,11 +121,11 @@ extern fshelp_fetch_root_callback2_t _diskfs_translator_callback2;
\
np = (PROTID)->po->np; \
\
- mutex_lock (&np->lock); \
+ pthread_mutex_lock (&np->lock); \
(OPERATION); \
if (diskfs_synchronous) \
diskfs_node_update (np, 1); \
- mutex_unlock (&np->lock); \
+ pthread_mutex_unlock (&np->lock); \
return err; \
})
diff --git a/libdiskfs/shutdown.c b/libdiskfs/shutdown.c
index f9bc4b57..66deb59a 100644
--- a/libdiskfs/shutdown.c
+++ b/libdiskfs/shutdown.c
@@ -36,7 +36,7 @@ diskfs_shutdown (int flags)
mach_port_t control;
error = fshelp_fetch_control (&np->transbox, &control);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error && (control != MACH_PORT_NULL))
{
error = fsys_goaway (control, flags);
@@ -44,7 +44,7 @@ diskfs_shutdown (int flags)
}
else
error = 0;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if ((error == MIG_SERVER_DIED) || (error == MACH_SEND_INVALID_DEST))
error = 0;
@@ -63,14 +63,14 @@ diskfs_shutdown (int flags)
return err;
}
- rwlock_writer_lock (&diskfs_fsys_lock);
+ pthread_rwlock_wrlock (&diskfs_fsys_lock);
/* Permit all the current RPC's to finish, and then
suspend new ones. */
err = ports_inhibit_class_rpcs (diskfs_protid_class);
if (err)
{
- rwlock_writer_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
return err;
}
@@ -88,7 +88,7 @@ diskfs_shutdown (int flags)
{
ports_enable_class (diskfs_protid_class);
ports_resume_class_rpcs (diskfs_protid_class);
- rwlock_writer_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
return EBUSY;
}
diff --git a/libdiskfs/sync-interval.c b/libdiskfs/sync-interval.c
index 20b9fbb4..14405f29 100644
--- a/libdiskfs/sync-interval.c
+++ b/libdiskfs/sync-interval.c
@@ -18,7 +18,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <errno.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <unistd.h>
#include <hurd/fsys.h>
@@ -29,14 +29,14 @@
int diskfs_sync_interval = 0;
/* The thread that's doing the syncing. */
-static cthread_t periodic_sync_thread;
+static pthread_t periodic_sync_thread;
/* This port represents the periodic sync service as if it were
an RPC. We can use ports_inhibit_port_rpcs on this port to guarantee
that the periodic_sync_thread is quiescent. */
static struct port_info *pi;
-static void periodic_sync ();
+static void * periodic_sync (void *);
/* Establish a thread to sync the filesystem every INTERVAL seconds, or
never, if INTERVAL is zero. If an error occurs creating the thread, it is
@@ -66,12 +66,15 @@ diskfs_set_sync_interval (int interval)
periodic_sync_thread = 0;
else
{
- periodic_sync_thread =
- cthread_fork ((cthread_fn_t)periodic_sync, (any_t)(intptr_t)interval);
- if (periodic_sync_thread)
- cthread_detach (periodic_sync_thread);
+ err = pthread_create (&periodic_sync_thread, NULL, periodic_sync,
+ (void *)(intptr_t) interval);
+ if (!err)
+ pthread_detach (periodic_sync_thread);
else
- err = ENOMEM;
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
if (!err)
@@ -87,9 +90,10 @@ diskfs_set_sync_interval (int interval)
/* Sync the filesystem (pointed to by the variable CONTROL_PORT above) every
INTERVAL seconds, as long as it's in the thread pointed to by the global
variable PERIODIC_SYNC_THREAD. */
-static void
-periodic_sync (int interval)
+static void *
+periodic_sync (void * arg)
{
+ int interval = (int) arg;
for (;;)
{
error_t err;
@@ -99,18 +103,18 @@ periodic_sync (int interval)
while we are in the process of syncing. */
err = ports_begin_rpc (pi, 0, &link);
- if (periodic_sync_thread != cthread_self ())
+ if (periodic_sync_thread != pthread_self ())
{
/* We've been superseded as the sync thread. Just die silently. */
ports_end_rpc (pi, &link);
- return;
+ return NULL;
}
if (! err)
{
if (! diskfs_readonly)
{
- rwlock_reader_lock (&diskfs_fsys_lock);
+ pthread_rwlock_rdlock (&diskfs_fsys_lock);
/* Only sync if we need to, to avoid clearing the clean flag
when it's just been set. Any other thread doing a sync
will have held the lock while it did its work. */
@@ -119,7 +123,7 @@ periodic_sync (int interval)
diskfs_sync_everything (0);
diskfs_set_hypermetadata (0, 0);
}
- rwlock_reader_unlock (&diskfs_fsys_lock);
+ pthread_rwlock_unlock (&diskfs_fsys_lock);
}
ports_end_rpc (pi, &link);
}
@@ -127,4 +131,6 @@ periodic_sync (int interval)
/* Wait until next time. */
sleep (interval);
}
+
+ return NULL;
}
diff --git a/libfshelp/Makefile b/libfshelp/Makefile
index bbc079c7..4de38372 100644
--- a/libfshelp/Makefile
+++ b/libfshelp/Makefile
@@ -32,7 +32,8 @@ SRCS = lock-acquire.c lock-init.c \
touch.c
installhdrs = fshelp.h
-HURDLIBS = shouldbeinlibc threads iohelp ports
+HURDLIBS = shouldbeinlibc iohelp ports
+LDLIBS += -lpthread
OBJS = $(subst .c,.o,$(SRCS))
include ../Makeconf
diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c
index eb569896..45c7dd09 100644
--- a/libfshelp/fetch-root.c
+++ b/libfshelp/fetch-root.c
@@ -95,13 +95,13 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
if (box->flags & TRANSBOX_STARTING)
{
box->flags |= TRANSBOX_WANTED;
- cancel = hurd_condition_wait (&box->wakeup, box->lock);
+ cancel = pthread_hurd_cond_wait_np (&box->wakeup, box->lock);
if (cancel)
return EINTR;
goto start_over;
}
box->flags |= TRANSBOX_STARTING;
- mutex_unlock (box->lock);
+ pthread_mutex_unlock (box->lock);
err = (*callback1) (box->cookie, cookie, &uid, &gid, &argz, &argz_len);
if (err)
@@ -147,7 +147,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
if (i != INIT_PORT_CWDIR)
mach_port_deallocate (mach_task_self (), ports[i]);
- mutex_lock (box->lock);
+ pthread_mutex_lock (box->lock);
free (argz);
@@ -157,7 +157,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
if (box->flags & TRANSBOX_WANTED)
{
box->flags &= ~TRANSBOX_WANTED;
- condition_broadcast (&box->wakeup);
+ pthread_cond_broadcast (&box->wakeup);
}
if (err)
@@ -173,7 +173,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
control = box->active;
mach_port_mod_refs (mach_task_self (), control,
MACH_PORT_RIGHT_SEND, 1);
- mutex_unlock (box->lock);
+ pthread_mutex_unlock (box->lock);
/* Cancellation point XXX */
err = fsys_getroot (control, dotdot, MACH_MSG_TYPE_COPY_SEND,
@@ -181,7 +181,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
user->gids->ids, user->gids->num,
flags, retry, retryname, root);
- mutex_lock (box->lock);
+ pthread_mutex_lock (box->lock);
if ((err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED)
&& control == box->active)
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index 9f4fa677..cf39fbc4 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -26,7 +26,7 @@
#include <errno.h>
#include <mach.h>
#include <hurd/hurd_types.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/iohelp.h>
#include <sys/stat.h>
#include <maptime.h>
@@ -78,16 +78,16 @@ fshelp_start_translator (fshelp_open_fn_t underlying_open_fn, void *cookie,
/* Active translator linkage */
/* These routines implement the linkage to active translators needed
- by any filesystem which supports them. They require cthreads and
+ by any filesystem which supports them. They require pthreads and
use the passive translator routines above, but they don't require
the ports library at all. */
struct transbox
{
fsys_t active;
- struct mutex *lock;
+ pthread_mutex_t *lock;
int flags;
- struct condition wakeup;
+ pthread_cond_t wakeup;
void *cookie;
};
#define TRANSBOX_STARTING 1
@@ -137,7 +137,7 @@ fshelp_fetch_root (struct transbox *transbox, void *cookie,
void
fshelp_transbox_init (struct transbox *transbox,
- struct mutex *lock,
+ pthread_mutex_t *lock,
void *cookie);
/* Return true iff there is an active translator on this box */
@@ -163,7 +163,7 @@ void fshelp_drop_transbox (struct transbox *box);
struct lock_box
{
int type;
- struct condition wait;
+ pthread_cond_t wait;
int waiting;
int shcount;
};
@@ -174,7 +174,7 @@ struct lock_box
per file_lock. MUT is a mutex which will be held whenever this
routine is called, to lock BOX->wait. */
error_t fshelp_acquire_lock (struct lock_box *box, int *user,
- struct mutex *mut, int flags);
+ pthread_mutex_t *mut, int flags);
/* Initialize lock_box BOX. (The user int passed to fshelp_acquire_lock
diff --git a/libfshelp/get-identity.c b/libfshelp/get-identity.c
index 51c5fb29..946b7e8e 100644
--- a/libfshelp/get-identity.c
+++ b/libfshelp/get-identity.c
@@ -24,7 +24,7 @@
#include <assert.h>
static struct port_class *idclass = 0;
-static struct mutex idlock = MUTEX_INITIALIZER;
+static pthread_mutex_t idlock = PTHREAD_MUTEX_INITIALIZER;
struct idspec
{
@@ -59,7 +59,7 @@ fshelp_get_identity (struct port_bucket *bucket,
return 0;
}
- mutex_lock (&idlock);
+ pthread_mutex_lock (&idlock);
if (!idclass)
id_initialize ();
@@ -69,20 +69,20 @@ fshelp_get_identity (struct port_bucket *bucket,
if (*pt != MACH_PORT_NULL)
{
- mutex_unlock (&idlock);
+ pthread_mutex_unlock (&idlock);
return 0;
}
err = ports_create_port (idclass, bucket, sizeof (struct idspec), &i);
if (err)
{
- mutex_unlock (&idlock);
+ pthread_mutex_unlock (&idlock);
return err;
}
i->fileno = fileno;
*pt = ports_get_right (i);
ports_port_deref (i);
- mutex_unlock (&idlock);
+ pthread_mutex_unlock (&idlock);
return 0;
}
diff --git a/libfshelp/lock-acquire.c b/libfshelp/lock-acquire.c
index bad1114d..cdc6185c 100644
--- a/libfshelp/lock-acquire.c
+++ b/libfshelp/lock-acquire.c
@@ -24,7 +24,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define EWOULDBLOCK EAGAIN /* XXX */
error_t
-fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
+fshelp_acquire_lock (struct lock_box *box, int *user, pthread_mutex_t *mut,
int flags)
{
if (!(flags & (LOCK_UN | LOCK_EX | LOCK_SH)))
@@ -58,7 +58,7 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (box->type == LOCK_UN && box->waiting)
{
box->waiting = 0;
- condition_broadcast (&box->wait);
+ pthread_cond_broadcast (&box->wait);
}
*user = LOCK_UN;
}
@@ -72,7 +72,7 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (box->waiting)
{
box->waiting = 0;
- condition_broadcast (&box->wait);
+ pthread_cond_broadcast (&box->wait);
}
}
@@ -82,7 +82,7 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (flags & LOCK_NB)
return EWOULDBLOCK;
box->waiting = 1;
- if (hurd_condition_wait (&box->wait, mut))
+ if (pthread_hurd_cond_wait_np (&box->wait, mut))
return EINTR;
}
@@ -96,7 +96,7 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
if (box->waiting)
{
box->waiting = 0;
- condition_broadcast (&box->wait);
+ pthread_cond_broadcast (&box->wait);
}
}
}
@@ -119,7 +119,7 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut,
else
{
box->waiting = 1;
- if (hurd_condition_wait (&box->wait, mut))
+ if (pthread_hurd_cond_wait_np (&box->wait, mut))
return EINTR;
}
}
diff --git a/libfshelp/lock-init.c b/libfshelp/lock-init.c
index 4b1da97e..66046aaa 100644
--- a/libfshelp/lock-init.c
+++ b/libfshelp/lock-init.c
@@ -26,7 +26,7 @@ void
fshelp_lock_init (struct lock_box *box)
{
box->type = LOCK_UN;
- condition_init (&box->wait);
+ pthread_cond_init (&box->wait, NULL);
box->waiting = 0;
box->shcount = 0;
}
diff --git a/libfshelp/locks.h b/libfshelp/locks.h
index dcecf5d9..a950f610 100644
--- a/libfshelp/locks.h
+++ b/libfshelp/locks.h
@@ -21,7 +21,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mach.h>
#include <hurd.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/ports.h>
#include "fshelp.h"
#include <sys/file.h>
diff --git a/libfshelp/set-active.c b/libfshelp/set-active.c
index 4f25a50e..9776a529 100644
--- a/libfshelp/set-active.c
+++ b/libfshelp/set-active.c
@@ -49,7 +49,7 @@ fshelp_set_active (struct transbox *box,
while (box->flags & TRANSBOX_STARTING)
{
box->flags |= TRANSBOX_WANTED;
- cancel = hurd_condition_wait (&box->wakeup, box->lock);
+ cancel = pthread_hurd_cond_wait_np (&box->wakeup, box->lock);
if (cancel)
return EINTR;
}
diff --git a/libfshelp/trans.h b/libfshelp/trans.h
index b2416453..a9ea6487 100644
--- a/libfshelp/trans.h
+++ b/libfshelp/trans.h
@@ -17,7 +17,7 @@
#include <mach.h>
#include <hurd.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/ports.h>
#include "fshelp.h"
@@ -28,5 +28,5 @@ struct transboot
struct trans_link *link;
};
-spin_lock_t _fshelp_translistlock;
+pthread_spinlock_t _fshelp_translistlock;
struct trans_link *_fshelp_translist;
diff --git a/libfshelp/transbox-init.c b/libfshelp/transbox-init.c
index 1945a57d..42d953e8 100644
--- a/libfshelp/transbox-init.c
+++ b/libfshelp/transbox-init.c
@@ -19,17 +19,17 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "fshelp.h"
-#include <cthreads.h>
+#include <pthread.h>
void
fshelp_transbox_init (struct transbox *transbox,
- struct mutex *lock,
+ pthread_mutex_t *lock,
void *cookie)
{
transbox->active = MACH_PORT_NULL;
transbox->flags = 0;
transbox->lock = lock;
- condition_init (&transbox->wakeup);
+ pthread_cond_init (&transbox->wakeup, NULL);
transbox->cookie = cookie;
}
diff --git a/libiohelp/Makefile b/libiohelp/Makefile
index 56815c49..f0dd48f0 100644
--- a/libiohelp/Makefile
+++ b/libiohelp/Makefile
@@ -23,7 +23,8 @@ SRCS = get_conch.c handle_io_get_conch.c handle_io_release_conch.c \
iouser-dup.c iouser-reauth.c iouser-free.c iouser-restrict.c \
shared.c return-buffer.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = threads shouldbeinlibc
+HURDLIBS = shouldbeinlibc
+LDLIBS += -lpthread
libname = libiohelp
installhdrs = iohelp.h
diff --git a/libiohelp/get_conch.c b/libiohelp/get_conch.c
index 64d347ab..e3af6939 100644
--- a/libiohelp/get_conch.c
+++ b/libiohelp/get_conch.c
@@ -29,26 +29,26 @@ iohelp_get_conch (struct conch *c)
if (user_sh)
{
- spin_lock (&user_sh->lock);
+ pthread_spin_lock (&user_sh->lock);
switch (user_sh->conch_status)
{
case USER_HAS_CONCH:
user_sh->conch_status = USER_RELEASE_CONCH;
/* fall through ... */
case USER_RELEASE_CONCH:
- spin_unlock (&user_sh->lock);
- condition_wait (&c->wait, c->lock);
+ pthread_spin_unlock (&user_sh->lock);
+ pthread_cond_wait (&c->wait, c->lock);
/* Anything can have happened */
goto again;
case USER_COULD_HAVE_CONCH:
user_sh->conch_status = USER_HAS_NOT_CONCH;
- spin_unlock (&user_sh->lock);
+ pthread_spin_unlock (&user_sh->lock);
iohelp_fetch_shared_data (c->holder);
break;
case USER_HAS_NOT_CONCH:
- spin_unlock (&user_sh->lock);
+ pthread_spin_unlock (&user_sh->lock);
break;
}
}
diff --git a/libiohelp/handle_io_release_conch.c b/libiohelp/handle_io_release_conch.c
index 8a6bd32d..5be30a66 100644
--- a/libiohelp/handle_io_release_conch.c
+++ b/libiohelp/handle_io_release_conch.c
@@ -25,13 +25,13 @@ iohelp_handle_io_release_conch (struct conch *c, void *user)
{
struct shared_io *user_sh = c->holder_shared_page;
- spin_lock (&user_sh->lock);
+ pthread_spin_lock (&user_sh->lock);
if (c->holder_shared_page->conch_status != USER_HAS_NOT_CONCH)
{
c->holder_shared_page->conch_status = USER_HAS_NOT_CONCH;
iohelp_fetch_shared_data (c->holder);
}
- spin_unlock (&user_sh->lock);
+ pthread_spin_unlock (&user_sh->lock);
if (c->holder == user)
{
@@ -39,6 +39,6 @@ iohelp_handle_io_release_conch (struct conch *c, void *user)
c->holder_shared_page = 0;
}
- condition_broadcast (&c->wait);
+ pthread_cond_broadcast (&c->wait);
}
diff --git a/libiohelp/initialize_conch.c b/libiohelp/initialize_conch.c
index a5d5b76e..2ded2418 100644
--- a/libiohelp/initialize_conch.c
+++ b/libiohelp/initialize_conch.c
@@ -20,10 +20,10 @@
/* Called by an I/O server to initialize a conch structure C;
M will be used to lock conch data structures. */
void
-iohelp_initialize_conch (struct conch *c, struct mutex *m)
+iohelp_initialize_conch (struct conch *c, pthread_mutex_t *m)
{
c->lock = m;
- condition_init (&c->wait);
+ pthread_cond_init (&c->wait, NULL);
c->holder = 0;
c->holder_shared_page = 0;
}
diff --git a/libiohelp/iohelp.h b/libiohelp/iohelp.h
index a52d5985..0597d6c7 100644
--- a/libiohelp/iohelp.h
+++ b/libiohelp/iohelp.h
@@ -20,20 +20,20 @@
#include <mach.h>
#include <hurd/hurd_types.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/shared.h>
/* Conch manipulation. */
struct conch
{
- struct mutex *lock;
- struct condition wait;
+ pthread_mutex_t *lock;
+ pthread_cond_t wait;
void *holder;
struct shared_io *holder_shared_page;
};
/* Initialize a conch box */
-void iohelp_initialize_conch (struct conch *, struct mutex *);
+void iohelp_initialize_conch (struct conch *, pthread_mutex_t *);
/* These routines are not reentrant. The server is responsible
for ensuring that all calls to these routines are serialized
diff --git a/libiohelp/verify_user_conch.c b/libiohelp/verify_user_conch.c
index c7e3e62e..e975cc88 100644
--- a/libiohelp/verify_user_conch.c
+++ b/libiohelp/verify_user_conch.c
@@ -28,13 +28,13 @@ iohelp_verify_user_conch (struct conch *c, void *user)
if (user != c->holder)
return EPERM;
user_sh = c->holder_shared_page;
- spin_lock (&user_sh->lock);
+ pthread_spin_lock (&user_sh->lock);
if (user_sh->conch_status != USER_HAS_CONCH
&& user_sh->conch_status != USER_RELEASE_CONCH)
{
- spin_unlock (&user_sh->lock);
+ pthread_spin_unlock (&user_sh->lock);
return EPERM;
}
- spin_unlock (&user_sh->lock);
+ pthread_spin_unlock (&user_sh->lock);
return 0;
}
diff --git a/libnetfs/Makefile b/libnetfs/Makefile
index 33ee2fb2..24b5acae 100644
--- a/libnetfs/Makefile
+++ b/libnetfs/Makefile
@@ -23,7 +23,8 @@ dir := libnetfs
makemode := library
libname = libnetfs
-HURDLIBS = fshelp iohelp threads ports shouldbeinlibc
+HURDLIBS = fshelp iohelp ports shouldbeinlibc
+LDLIBS += -lpthread
FSSRCS= dir-link.c dir-lookup.c dir-mkdir.c dir-mkfile.c \
dir-notice-changes.c dir-readdir.c dir-rename.c \
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index 17d9e23e..f1b6438f 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -69,13 +69,13 @@ netfs_S_dir_lookup (struct protid *diruser,
/* Set things up in the state expected by the code from gotit: on. */
dnp = 0;
np = diruser->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
netfs_nref (np);
goto gotit;
}
dnp = diruser->po->np;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
netfs_nref (dnp); /* acquire a reference for later netfs_nput */
@@ -120,7 +120,7 @@ netfs_S_dir_lookup (struct protid *diruser,
if (! lastcomp)
strcpy (retry_name, nextname);
error = 0;
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
goto out;
}
else if (diruser->po->root_parent != MACH_PORT_NULL)
@@ -134,7 +134,7 @@ netfs_S_dir_lookup (struct protid *diruser,
if (!lastcomp)
strcpy (retry_name, nextname);
error = 0;
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
goto out;
}
else
@@ -159,7 +159,7 @@ netfs_S_dir_lookup (struct protid *diruser,
{
mode &= ~(S_IFMT | S_ISPARE | S_ISVTX);
mode |= S_IFREG;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
error = netfs_attempt_create_file (diruser->user, dnp,
filename, mode, &np);
@@ -168,7 +168,7 @@ netfs_S_dir_lookup (struct protid *diruser,
EXCL, that's fine; otherwise, we have to retry the lookup. */
if (error == EEXIST && !excl)
{
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
goto retry_lookup;
}
@@ -338,7 +338,7 @@ netfs_S_dir_lookup (struct protid *diruser,
create = 0;
}
netfs_nput (np);
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
np = 0;
}
else
diff --git a/libnetfs/dir-mkdir.c b/libnetfs/dir-mkdir.c
index 33feb25f..c8bebac8 100644
--- a/libnetfs/dir-mkdir.c
+++ b/libnetfs/dir-mkdir.c
@@ -32,8 +32,8 @@ netfs_S_dir_mkdir (struct protid *user, char *name, mode_t mode)
mode &= ~(S_IFMT|S_ISPARE|S_ISVTX);
mode |= S_IFDIR;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_mkdir (user->user, user->po->np, name, mode);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/dir-mkfile.c b/libnetfs/dir-mkfile.c
index 7d388737..9e5847af 100644
--- a/libnetfs/dir-mkfile.c
+++ b/libnetfs/dir-mkfile.c
@@ -31,7 +31,7 @@ netfs_S_dir_mkfile (struct protid *diruser, int flags, mode_t mode,
struct iouser *user;
struct protid *newpi;
- mutex_lock (&diruser->po->np->lock);
+ pthread_mutex_lock (&diruser->po->np->lock);
err = netfs_attempt_mkfile (diruser->user, diruser->po->np, mode, &np);
if (!err)
diff --git a/libnetfs/dir-readdir.c b/libnetfs/dir-readdir.c
index 7f896ac1..4ab03d8a 100644
--- a/libnetfs/dir-readdir.c
+++ b/libnetfs/dir-readdir.c
@@ -40,7 +40,7 @@ netfs_S_dir_readdir (struct protid *user,
return EOPNOTSUPP;
np = user->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = 0;
if ((user->po->openstat & O_READ) == 0)
@@ -53,6 +53,6 @@ netfs_S_dir_readdir (struct protid *user,
err = netfs_get_dirents (user->user, np, entry, nentries, data,
datacnt, bufsiz, amt);
*data_dealloc = 1; /* XXX */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libnetfs/dir-rmdir.c b/libnetfs/dir-rmdir.c
index 9a5941d3..96196fd4 100644
--- a/libnetfs/dir-rmdir.c
+++ b/libnetfs/dir-rmdir.c
@@ -29,8 +29,8 @@ netfs_S_dir_rmdir (struct protid *diruser, char *name)
if (!diruser)
return EOPNOTSUPP;
- mutex_lock (&diruser->po->np->lock);
+ pthread_mutex_lock (&diruser->po->np->lock);
err = netfs_attempt_rmdir (diruser->user, diruser->po->np, name);
- mutex_unlock (&diruser->po->np->lock);
+ pthread_mutex_unlock (&diruser->po->np->lock);
return err;
}
diff --git a/libnetfs/dir-unlink.c b/libnetfs/dir-unlink.c
index 8077514a..6f1eaca6 100644
--- a/libnetfs/dir-unlink.c
+++ b/libnetfs/dir-unlink.c
@@ -26,8 +26,8 @@ netfs_S_dir_unlink (struct protid *user, char *name)
{
error_t err;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_unlink (user->user, user->po->np, name);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/drop-node.c b/libnetfs/drop-node.c
index b2ec95e3..5460149a 100644
--- a/libnetfs/drop-node.c
+++ b/libnetfs/drop-node.c
@@ -25,7 +25,7 @@ netfs_drop_node (struct node *np)
{
fshelp_drop_transbox (&np->transbox);
netfs_node_norefs (np);
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
}
diff --git a/libnetfs/file-chauthor.c b/libnetfs/file-chauthor.c
index ec7f6177..4f0aad0b 100644
--- a/libnetfs/file-chauthor.c
+++ b/libnetfs/file-chauthor.c
@@ -30,9 +30,9 @@ netfs_S_file_chauthor (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_chauthor (user->user, user->po->np, author);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-check-access.c b/libnetfs/file-check-access.c
index 8e36ede1..d8773ff2 100644
--- a/libnetfs/file-check-access.c
+++ b/libnetfs/file-check-access.c
@@ -30,8 +30,8 @@ netfs_S_file_check_access (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_report_access (user->user, user->po->np, types);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-chflags.c b/libnetfs/file-chflags.c
index 068a1cea..a5c132d4 100644
--- a/libnetfs/file-chflags.c
+++ b/libnetfs/file-chflags.c
@@ -30,8 +30,8 @@ netfs_S_file_chflags (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_chflags (user->user, user->po->np, flags);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-chmod.c b/libnetfs/file-chmod.c
index 0f082f18..413261ca 100644
--- a/libnetfs/file-chmod.c
+++ b/libnetfs/file-chmod.c
@@ -32,8 +32,8 @@ netfs_S_file_chmod (struct protid *user,
mode &= ~(S_IFMT | S_ISPARE | S_ITRANS);
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_chmod (user->user, user->po->np, mode);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-chown.c b/libnetfs/file-chown.c
index 4b724048..d02876c7 100644
--- a/libnetfs/file-chown.c
+++ b/libnetfs/file-chown.c
@@ -31,9 +31,9 @@ netfs_S_file_chown (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_chown (user->user, user->po->np,
owner, group);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-exec.c b/libnetfs/file-exec.c
index 73c125ba..638f0ae8 100644
--- a/libnetfs/file-exec.c
+++ b/libnetfs/file-exec.c
@@ -70,12 +70,12 @@ netfs_S_file_exec (struct protid *cred,
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
mode = np->nn_stat.st_mode;
uid = np->nn_stat.st_uid;
gid = np->nn_stat.st_gid;
err = netfs_validate_stat (np, cred->user);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (err)
return err;
diff --git a/libnetfs/file-get-storage-info.c b/libnetfs/file-get-storage-info.c
index ac977be3..d2c9d8fc 100644
--- a/libnetfs/file-get-storage-info.c
+++ b/libnetfs/file-get-storage-info.c
@@ -36,12 +36,12 @@ netfs_S_file_get_storage_info (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_file_get_storage_info (user->user, user->po->np, ports,
ports_type, num_ports, ints,
num_ints, offsets, num_offsets,
data, data_len);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-get-translator.c b/libnetfs/file-get-translator.c
index 7edc8fd0..59e61020 100644
--- a/libnetfs/file-get-translator.c
+++ b/libnetfs/file-get-translator.c
@@ -37,12 +37,12 @@ netfs_S_file_get_translator (struct protid *user,
return EOPNOTSUPP;
np = user->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, user->user);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
@@ -112,7 +112,7 @@ netfs_S_file_get_translator (struct protid *user,
else
err = EINVAL;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libnetfs/file-lock-stat.c b/libnetfs/file-lock-stat.c
index 12f5eccf..49529cf4 100644
--- a/libnetfs/file-lock-stat.c
+++ b/libnetfs/file-lock-stat.c
@@ -29,9 +29,9 @@ netfs_S_file_lock_stat (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
*mystatus = user->po->lock_status;
*otherstatus = user->po->np->userlock.type;
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/file-lock.c b/libnetfs/file-lock.c
index cedc9c1d..0010d4be 100644
--- a/libnetfs/file-lock.c
+++ b/libnetfs/file-lock.c
@@ -28,9 +28,9 @@ netfs_S_file_lock (struct protid *user,
error_t err;
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = fshelp_acquire_lock (&user->po->np->userlock, &user->po->lock_status,
&user->po->np->lock, flags);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-reparent.c b/libnetfs/file-reparent.c
index 396a0a6b..61b7e37f 100644
--- a/libnetfs/file-reparent.c
+++ b/libnetfs/file-reparent.c
@@ -40,19 +40,19 @@ netfs_S_file_reparent (struct protid *cred, mach_port_t parent,
node = cred->po->np;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
new_cred =
netfs_make_protid (netfs_make_peropen (node, cred->po->openstat, cred->po),
user);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
if (new_cred)
{
/* Remove old shadow root state. */
if (new_cred->po->shadow_root && new_cred->po->shadow_root != node)
{
- mutex_lock (&new_cred->po->shadow_root->lock);
+ pthread_mutex_lock (&new_cred->po->shadow_root->lock);
netfs_nput (new_cred->po->shadow_root);
}
if (new_cred->po->shadow_root_parent)
diff --git a/libnetfs/file-set-size.c b/libnetfs/file-set-size.c
index 7b253e04..72f31db7 100644
--- a/libnetfs/file-set-size.c
+++ b/libnetfs/file-set-size.c
@@ -30,9 +30,9 @@ netfs_S_file_set_size (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_set_size (user->user, user->po->np, size);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-set-translator.c b/libnetfs/file-set-translator.c
index a0a70dba..4c29d952 100644
--- a/libnetfs/file-set-translator.c
+++ b/libnetfs/file-set-translator.c
@@ -43,7 +43,7 @@ netfs_S_file_set_translator (struct protid *user,
return EINVAL;
np = user->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (active_flags & FS_TRANS_SET
&& ! (active_flags & FS_TRANS_ORPHAN))
@@ -64,12 +64,12 @@ netfs_S_file_set_translator (struct protid *user,
if (control != MACH_PORT_NULL
&& (active_flags & FS_TRANS_EXCL) == 0)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
err = fsys_goaway (control, killtrans_flags);
if (err && err != MIG_SERVER_DIED && err != MACH_SEND_INVALID_DEST)
return err;
err = 0;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
}
}
@@ -123,7 +123,7 @@ netfs_S_file_set_translator (struct protid *user,
assert (arg <= passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
major = strtol (arg, 0, 0);
@@ -132,7 +132,7 @@ netfs_S_file_set_translator (struct protid *user,
assert (arg < passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
minor = strtol (arg, 0, 0);
@@ -148,7 +148,7 @@ netfs_S_file_set_translator (struct protid *user,
assert (arg <= passive + passivelen);
if (arg == passive + passivelen)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -176,6 +176,6 @@ netfs_S_file_set_translator (struct protid *user,
}
out:
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libnetfs/file-statfs.c b/libnetfs/file-statfs.c
index 180d29fc..13ae7d94 100644
--- a/libnetfs/file-statfs.c
+++ b/libnetfs/file-statfs.c
@@ -30,8 +30,8 @@ netfs_S_file_statfs (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_statfs (user->user, user->po->np, st);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-sync.c b/libnetfs/file-sync.c
index 99492ed8..4f6b4db8 100644
--- a/libnetfs/file-sync.c
+++ b/libnetfs/file-sync.c
@@ -31,8 +31,8 @@ netfs_S_file_sync (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_sync (user->user, user->po->np, wait);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-syncfs.c b/libnetfs/file-syncfs.c
index 28e34a3a..2302e926 100644
--- a/libnetfs/file-syncfs.c
+++ b/libnetfs/file-syncfs.c
@@ -33,8 +33,8 @@ netfs_S_file_syncfs (struct protid *user,
/* Translators not yet supported by netfs. XXX */
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_syncfs (user->user, wait);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/file-utimes.c b/libnetfs/file-utimes.c
index 45adf825..19156094 100644
--- a/libnetfs/file-utimes.c
+++ b/libnetfs/file-utimes.c
@@ -44,10 +44,10 @@ netfs_S_file_utimes (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_attempt_utimes (user->user, user->po->np,
atimein.microseconds != -1 ? &atime : 0,
mtimein.microseconds != -1 ? &mtime : 0);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/fsys-getroot.c b/libnetfs/fsys-getroot.c
index d3e78332..a1dd5e54 100644
--- a/libnetfs/fsys-getroot.c
+++ b/libnetfs/fsys-getroot.c
@@ -55,7 +55,7 @@ netfs_S_fsys_getroot (mach_port_t cntl,
flags &= O_HURD;
- mutex_lock (&netfs_root_node->lock);
+ pthread_mutex_lock (&netfs_root_node->lock);
err = netfs_validate_stat (netfs_root_node, cred);
if (err)
goto out;
@@ -73,7 +73,7 @@ netfs_S_fsys_getroot (mach_port_t cntl,
do_retry, retry_name, retry_port);
if (err != ENOENT)
{
- mutex_unlock (&netfs_root_node->lock);
+ pthread_mutex_unlock (&netfs_root_node->lock);
iohelp_free_iouser (cred);
if (!err)
*retry_port_type = MACH_MSG_TYPE_MOVE_SEND;
@@ -92,7 +92,7 @@ netfs_S_fsys_getroot (mach_port_t cntl,
if (err)
goto out;
- mutex_unlock (&netfs_root_node->lock);
+ pthread_mutex_unlock (&netfs_root_node->lock);
iohelp_free_iouser (cred);
if (pathbuf[0] == '/')
@@ -141,6 +141,6 @@ netfs_S_fsys_getroot (mach_port_t cntl,
out:
if (err)
iohelp_free_iouser (cred);
- mutex_unlock (&netfs_root_node->lock);
+ pthread_mutex_unlock (&netfs_root_node->lock);
return err;
}
diff --git a/libnetfs/fsys-set-options.c b/libnetfs/fsys-set-options.c
index 38f06c16..9dd8b007 100644
--- a/libnetfs/fsys-set-options.c
+++ b/libnetfs/fsys-set-options.c
@@ -48,7 +48,7 @@ netfs_S_fsys_set_options (fsys_t fsys,
mach_port_t control;
error = fshelp_fetch_control (&np->transbox, &control);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!error && (control != MACH_PORT_NULL))
{
error = fsys_set_options (control, data, data_len, do_children);
@@ -56,7 +56,7 @@ netfs_S_fsys_set_options (fsys_t fsys,
}
else
error = 0;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if ((error == MIG_SERVER_DIED) || (error == MACH_SEND_INVALID_DEST))
error = 0;
diff --git a/libnetfs/init-init.c b/libnetfs/init-init.c
index 411430f0..e98b6562 100644
--- a/libnetfs/init-init.c
+++ b/libnetfs/init-init.c
@@ -21,7 +21,7 @@
#include "netfs.h"
-spin_lock_t netfs_node_refcnt_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t netfs_node_refcnt_lock = PTHREAD_SPINLOCK_INITIALIZER;
struct node *netfs_root_node = 0;
struct port_bucket *netfs_port_bucket = 0;
diff --git a/libnetfs/io-clear-some-openmodes.c b/libnetfs/io-clear-some-openmodes.c
index 27bbfac8..1da5e476 100644
--- a/libnetfs/io-clear-some-openmodes.c
+++ b/libnetfs/io-clear-some-openmodes.c
@@ -28,8 +28,8 @@ netfs_S_io_clear_some_openmodes (struct protid *user, int bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
user->po->openstat &= ~(bits & HONORED_STATE_MODES);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-duplicate.c b/libnetfs/io-duplicate.c
index ad374fc9..b2c3a3a1 100644
--- a/libnetfs/io-duplicate.c
+++ b/libnetfs/io-duplicate.c
@@ -34,10 +34,10 @@ netfs_S_io_duplicate (struct protid *user,
if (err)
return err;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
newpi = netfs_make_protid (user->po, clone);
*newport = ports_get_right (newpi);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
*newporttp = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
return 0;
diff --git a/libnetfs/io-get-openmodes.c b/libnetfs/io-get-openmodes.c
index e197fdc9..698c2937 100644
--- a/libnetfs/io-get-openmodes.c
+++ b/libnetfs/io-get-openmodes.c
@@ -27,8 +27,8 @@ netfs_S_io_get_openmodes (struct protid *user, int *bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
*bits = user->po->openstat;
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-get-owner.c b/libnetfs/io-get-owner.c
index c86207f7..9bbf41de 100644
--- a/libnetfs/io-get-owner.c
+++ b/libnetfs/io-get-owner.c
@@ -27,8 +27,8 @@ netfs_S_io_get_owner (struct protid *user, pid_t *owner)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
*owner = user->po->np->owner;
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-identity.c b/libnetfs/io-identity.c
index e62a01e4..0c6a191c 100644
--- a/libnetfs/io-identity.c
+++ b/libnetfs/io-identity.c
@@ -36,19 +36,19 @@ netfs_S_io_identity (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, cred->user);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
err = fshelp_get_identity (netfs_port_bucket, np->nn_stat.st_ino, id);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
*idtype = MACH_MSG_TYPE_MAKE_SEND;
@@ -56,6 +56,6 @@ netfs_S_io_identity (struct protid *cred,
*fsystype = MACH_MSG_TYPE_MAKE_SEND;
*fileno = np->nn_stat.st_ino;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
diff --git a/libnetfs/io-mod-owner.c b/libnetfs/io-mod-owner.c
index 16c61060..91cbdb03 100644
--- a/libnetfs/io-mod-owner.c
+++ b/libnetfs/io-mod-owner.c
@@ -27,8 +27,8 @@ netfs_S_io_mod_owner (struct protid *user, pid_t owner)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
user->po->np->owner = owner;
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-read.c b/libnetfs/io-read.c
index ff8fbcff..0ce75db1 100644
--- a/libnetfs/io-read.c
+++ b/libnetfs/io-read.c
@@ -39,11 +39,11 @@ netfs_S_io_read (struct protid *user,
return EOPNOTSUPP;
node = user->po->np;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
if ((user->po->openstat & O_READ) == 0)
{
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
return EBADF;
}
@@ -96,7 +96,7 @@ netfs_S_io_read (struct protid *user,
if (offset == -1 && !err)
user->po->filepointer += *datalen;
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
if (err && alloced)
munmap (*data, amount);
diff --git a/libnetfs/io-readable.c b/libnetfs/io-readable.c
index ad6bf3c1..07becf66 100644
--- a/libnetfs/io-readable.c
+++ b/libnetfs/io-readable.c
@@ -35,7 +35,7 @@ netfs_S_io_readable (struct protid *user,
if (!(user->po->openstat & O_READ))
return EINVAL;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = netfs_validate_stat (user->po->np, user->user);
if (!err)
{
@@ -44,6 +44,6 @@ netfs_S_io_readable (struct protid *user,
else
*amount = 0;
}
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/libnetfs/io-reauthenticate.c b/libnetfs/io-reauthenticate.c
index 3140499c..1d2d935a 100644
--- a/libnetfs/io-reauthenticate.c
+++ b/libnetfs/io-reauthenticate.c
@@ -31,7 +31,7 @@ netfs_S_io_reauthenticate (struct protid *user, mach_port_t rend_port)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
newpi = netfs_make_protid (user->po, 0);
newright = ports_get_send_right (newpi);
@@ -46,7 +46,7 @@ netfs_S_io_reauthenticate (struct protid *user, mach_port_t rend_port)
mach_port_move_member (mach_task_self (), newpi->pi.port_right,
netfs_port_bucket->portset);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
ports_port_deref (newpi);
return err;
diff --git a/libnetfs/io-restrict-auth.c b/libnetfs/io-restrict-auth.c
index bddc8fea..0c3403d8 100644
--- a/libnetfs/io-restrict-auth.c
+++ b/libnetfs/io-restrict-auth.c
@@ -42,17 +42,17 @@ netfs_S_io_restrict_auth (struct protid *user,
if (err)
return err;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
newpi = netfs_make_protid (user->po, new_user);
if (newpi)
{
*newport = ports_get_right (newpi);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
*newporttype = MACH_MSG_TYPE_MAKE_SEND;
}
else
{
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
iohelp_free_iouser (new_user);
err = ENOMEM;
}
diff --git a/libnetfs/io-revoke.c b/libnetfs/io-revoke.c
index 5b32622a..7877eabe 100644
--- a/libnetfs/io-revoke.c
+++ b/libnetfs/io-revoke.c
@@ -41,13 +41,13 @@ netfs_S_io_revoke (struct protid *cred)
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, cred->user);
if (!err)
err = fshelp_isowner (&np->nn_stat, cred->user);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (err)
return err;
diff --git a/libnetfs/io-seek.c b/libnetfs/io-seek.c
index 85408a4d..cd2b3e4b 100644
--- a/libnetfs/io-seek.c
+++ b/libnetfs/io-seek.c
@@ -43,13 +43,13 @@ netfs_S_io_seek (struct protid *user,
struct node *np;
np = user->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, user->user);
if (!err)
offset += np->nn_stat.st_size;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
case SEEK_SET:
check:
diff --git a/libnetfs/io-set-all-openmodes.c b/libnetfs/io-set-all-openmodes.c
index 4f431459..2424282e 100644
--- a/libnetfs/io-set-all-openmodes.c
+++ b/libnetfs/io-set-all-openmodes.c
@@ -28,9 +28,9 @@ netfs_S_io_set_all_openmodes (struct protid *user, int newbits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
user->po->openstat &= ~HONORED_STATE_MODES;
user->po->openstat |= (newbits & HONORED_STATE_MODES);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-set-some-openmodes.c b/libnetfs/io-set-some-openmodes.c
index 97bd2b43..48fbeed6 100644
--- a/libnetfs/io-set-some-openmodes.c
+++ b/libnetfs/io-set-some-openmodes.c
@@ -28,8 +28,8 @@ netfs_S_io_set_some_openmodes (struct protid *user, int bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
user->po->openstat |= (bits & HONORED_STATE_MODES);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return 0;
}
diff --git a/libnetfs/io-stat.c b/libnetfs/io-stat.c
index 3826c9d9..cf2c25b3 100644
--- a/libnetfs/io-stat.c
+++ b/libnetfs/io-stat.c
@@ -32,7 +32,7 @@ netfs_S_io_stat (struct protid *user, io_statbuf_t *statbuf)
return EOPNOTSUPP;
node = user->po->np;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
err = netfs_validate_stat (node, user->user);
if (! err)
@@ -47,7 +47,7 @@ netfs_S_io_stat (struct protid *user, io_statbuf_t *statbuf)
statbuf->st_mode |= S_IROOT; /* Is a root node. */
}
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
return err;
}
diff --git a/libnetfs/io-write.c b/libnetfs/io-write.c
index c4423dab..98c2a306 100644
--- a/libnetfs/io-write.c
+++ b/libnetfs/io-write.c
@@ -42,7 +42,7 @@ netfs_S_io_write (struct protid *user,
*amount = datalen;
np = user->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (off == -1)
{
@@ -51,7 +51,7 @@ netfs_S_io_write (struct protid *user,
err = netfs_validate_stat (np, user->user);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
user->po->filepointer = np->nn_stat.st_size;
@@ -62,7 +62,7 @@ netfs_S_io_write (struct protid *user,
err = netfs_attempt_write (user->user, np, off, amount, data);
if (offset == -1 && !err)
user->po->filepointer += *amount;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
diff --git a/libnetfs/make-node.c b/libnetfs/make-node.c
index c547bfcb..f20ada18 100644
--- a/libnetfs/make-node.c
+++ b/libnetfs/make-node.c
@@ -30,7 +30,7 @@ netfs_make_node (struct netnode *nn)
np->nn = nn;
- mutex_init (&np->lock);
+ pthread_mutex_init (&np->lock, NULL);
np->references = 1;
np->sockaddr = MACH_PORT_NULL;
np->owner = 0;
diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
index 1dda718e..d1ebed01 100644
--- a/libnetfs/netfs.h
+++ b/libnetfs/netfs.h
@@ -23,6 +23,7 @@
#include <hurd/fshelp.h>
#include <hurd/iohelp.h>
#include <assert.h>
+#include <pthread.h>
/* This library supports client-side network file system
implementations. It is analogous to the diskfs library provided for
@@ -79,7 +80,7 @@ struct node
are ignored, so you can set this to nn_stat.st_mode if you want that. */
mode_t nn_translated;
- struct mutex lock;
+ pthread_mutex_t lock;
/* The number of references to this node. */
int references;
@@ -359,7 +360,7 @@ struct node *netfs_make_node (struct netnode *);
/* Whenever node->references is to be touched, this lock must be
held. Cf. netfs_nrele, netfs_nput, netfs_nref and netfs_drop_node. */
-extern spin_lock_t netfs_node_refcnt_lock;
+extern pthread_spinlock_t netfs_node_refcnt_lock;
/* Normally called in main. This function sets up some of the netfs
server's internal state. */
diff --git a/libnetfs/nput.c b/libnetfs/nput.c
index c62b7b9f..611b37a0 100644
--- a/libnetfs/nput.c
+++ b/libnetfs/nput.c
@@ -23,7 +23,7 @@
void
netfs_nput (struct node *np)
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
assert (np->references);
np->references--;
if (np->references == 0)
@@ -31,8 +31,8 @@ netfs_nput (struct node *np)
/* netfs_drop_node drops netfs_node_refcnt_lock for us. */
else
{
- spin_unlock (&netfs_node_refcnt_lock);
- mutex_unlock (&np->lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
+ pthread_mutex_unlock (&np->lock);
}
}
diff --git a/libnetfs/nref.c b/libnetfs/nref.c
index 4e26910f..86b49927 100644
--- a/libnetfs/nref.c
+++ b/libnetfs/nref.c
@@ -23,7 +23,7 @@
void
netfs_nref (struct node *np)
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
np->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
}
diff --git a/libnetfs/nrele.c b/libnetfs/nrele.c
index dca9599a..6f9a0144 100644
--- a/libnetfs/nrele.c
+++ b/libnetfs/nrele.c
@@ -23,15 +23,15 @@
void
netfs_nrele (struct node *np)
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
assert (np->references);
np->references--;
if (np->references == 0)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
netfs_drop_node (np);
/* netfs_drop_node drops netfs_node_refcnt_lock for us. */
}
else
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
}
diff --git a/libnetfs/release-peropen.c b/libnetfs/release-peropen.c
index 9a52184b..3e650999 100644
--- a/libnetfs/release-peropen.c
+++ b/libnetfs/release-peropen.c
@@ -23,9 +23,9 @@
void
netfs_release_peropen (struct peropen *po)
{
- mutex_lock (&po->np->lock);
+ pthread_mutex_lock (&po->np->lock);
if (--po->refcnt)
- mutex_unlock (&po->np->lock);
+ pthread_mutex_unlock (&po->np->lock);
else
{
if (po->root_parent)
@@ -33,7 +33,7 @@ netfs_release_peropen (struct peropen *po)
if (po->shadow_root && po->shadow_root != po->np)
{
- mutex_lock (&po->shadow_root->lock);
+ pthread_mutex_lock (&po->shadow_root->lock);
netfs_nput (po->shadow_root);
}
if (po->shadow_root_parent)
diff --git a/libnetfs/shutdown.c b/libnetfs/shutdown.c
index 9ba137d0..b3463bfc 100644
--- a/libnetfs/shutdown.c
+++ b/libnetfs/shutdown.c
@@ -24,7 +24,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <sys/stat.h>
#include <hurd/fsys.h>
#include <hurd/fshelp.h>
-#include <cthreads.h>
+#include <pthread.h>
/* Shutdown the filesystem; flags are as for fsys_goaway. */
error_t
@@ -39,10 +39,10 @@ netfs_shutdown (int flags)
err = fshelp_fetch_control (&node->transbox, &control);
if (!err && (control != MACH_PORT_NULL))
{
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
err = fsys_goaway (control, flags);
mach_port_deallocate (mach_task_self (), control);
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
}
else
err = 0;
diff --git a/libpager/Makefile b/libpager/Makefile
index 40eed16f..4d635b17 100644
--- a/libpager/Makefile
+++ b/libpager/Makefile
@@ -27,7 +27,8 @@ SRCS = data-request.c data-return.c data-unlock.c pager-port.c \
offer-page.c
installhdrs = pager.h
-HURDLIBS= threads ports
+HURDLIBS= ports
+LDLIBS += -lpthread
OBJS = $(SRCS:.c=.o) memory_objectServer.o notifyServer.o
MIGSFLAGS = -DSEQNOS
diff --git a/libpager/chg-compl.c b/libpager/chg-compl.c
index 7d3994b0..890e89b8 100644
--- a/libpager/chg-compl.c
+++ b/libpager/chg-compl.c
@@ -37,19 +37,19 @@ _pager_seqnos_memory_object_change_completed (mach_port_t obj,
return EOPNOTSUPP;
}
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seq);
for (ar = p->attribute_requests; ar; ar = ar->next)
if (ar->may_cache == maycache && ar->copy_strategy == strat)
{
if (ar->attrs_pending && !--ar->attrs_pending)
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
break;
}
_pager_release_seqno (p, seq);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
}
diff --git a/libpager/clean.c b/libpager/clean.c
index e891617f..031f7d1b 100644
--- a/libpager/clean.c
+++ b/libpager/clean.c
@@ -32,7 +32,7 @@ _pager_clean (void *arg)
if (p->pager_state != NOTINIT)
{
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_free_structure (p);
#ifdef KERNEL_INIT_RACE
for (i = p->init_head; i; i = tmp)
@@ -43,7 +43,7 @@ _pager_clean (void *arg)
free (i);
}
#endif
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
}
pager_clear_user_data (p->upi);
diff --git a/libpager/data-request.c b/libpager/data-request.c
index 36725b11..4454facb 100644
--- a/libpager/data-request.c
+++ b/libpager/data-request.c
@@ -41,7 +41,7 @@ _pager_seqnos_memory_object_data_request (mach_port_t object,
return EOPNOTSUPP;
/* Acquire the right to meddle with the pagemap */
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
/* sanity checks -- we don't do multi-page requests yet. */
@@ -107,7 +107,7 @@ _pager_seqnos_memory_object_data_request (mach_port_t object,
/* Let someone else in. */
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
if (!doread)
goto allow_term_out;
@@ -121,10 +121,10 @@ _pager_seqnos_memory_object_data_request (mach_port_t object,
memory_object_data_supply (p->memobjcntl, offset, page, length, 1,
write_lock ? VM_PROT_WRITE : VM_PROT_NONE, 0,
MACH_PORT_NULL);
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_mark_object_error (p, offset, length, 0);
_pager_allow_termination (p);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
@@ -132,9 +132,9 @@ _pager_seqnos_memory_object_data_request (mach_port_t object,
memory_object_data_error (p->memobjcntl, offset, length, EIO);
_pager_mark_object_error (p, offset, length, EIO);
allow_term_out:
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_allow_termination (p);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
@@ -142,7 +142,7 @@ _pager_seqnos_memory_object_data_request (mach_port_t object,
_pager_allow_termination (p);
release_out:
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
}
diff --git a/libpager/data-return.c b/libpager/data-return.c
index a010c6dc..c70f0e8d 100644
--- a/libpager/data-return.c
+++ b/libpager/data-return.c
@@ -51,7 +51,7 @@ _pager_do_write_request (mach_port_t object,
return EOPNOTSUPP;
/* Acquire the right to meddle with the pagemap */
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
/* sanity checks -- we don't do multi-page requests yet. */
@@ -100,7 +100,7 @@ _pager_do_write_request (mach_port_t object,
if (pm_entries[i] & PM_PAGINGOUT)
{
pm_entries[i] |= PM_WRITEWAIT;
- condition_wait (&p->wakeup, &p->interlock);
+ pthread_cond_wait (&p->wakeup, &p->interlock);
goto retry;
}
@@ -143,7 +143,7 @@ _pager_do_write_request (mach_port_t object,
/* Let someone else in. */
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
/* This is inefficient; we should send all the pages to the device at once
but until the pager library interface is changed, this will have to do. */
@@ -155,7 +155,7 @@ _pager_do_write_request (mach_port_t object,
data + (vm_page_size * i));
/* Acquire the right to meddle with the pagemap */
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_pagemap_resize (p, offset + length);
pm_entries = &p->pagemap[offset / __vm_page_size];
@@ -196,18 +196,18 @@ _pager_do_write_request (mach_port_t object,
wakeup = 1;
if (wakeup)
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
_pager_allow_termination (p);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
release_out:
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
}
diff --git a/libpager/data-unlock.c b/libpager/data-unlock.c
index 9692f589..02339abb 100644
--- a/libpager/data-unlock.c
+++ b/libpager/data-unlock.c
@@ -36,10 +36,10 @@ _pager_seqnos_memory_object_data_unlock (mach_port_t object,
if (!p)
return EOPNOTSUPP;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
if (p->pager_state != NORMAL)
{
diff --git a/libpager/inhibit-term.c b/libpager/inhibit-term.c
index 222bad5e..3f1e2ffe 100644
--- a/libpager/inhibit-term.c
+++ b/libpager/inhibit-term.c
@@ -31,5 +31,5 @@ void
_pager_allow_termination (struct pager *p)
{
if (!--p->noterm && p->termwaiting)
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
}
diff --git a/libpager/lock-completed.c b/libpager/lock-completed.c
index 1810959f..9ab640fe 100644
--- a/libpager/lock-completed.c
+++ b/libpager/lock-completed.c
@@ -37,7 +37,7 @@ _pager_seqnos_memory_object_lock_completed (mach_port_t object,
if (!p)
return EOPNOTSUPP;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
if (control != p->memobjcntl)
@@ -55,13 +55,13 @@ _pager_seqnos_memory_object_lock_completed (mach_port_t object,
if (lr->locks_pending)
--lr->locks_pending;
if (!lr->locks_pending && !lr->pending_writes)
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
break;
}
out:
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return err;
diff --git a/libpager/lock-object.c b/libpager/lock-object.c
index d8d4a1b7..93c89f07 100644
--- a/libpager/lock-object.c
+++ b/libpager/lock-object.c
@@ -33,10 +33,10 @@ _pager_lock_object (struct pager *p,
int i;
struct lock_request *lr = 0;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
if (p->pager_state != NORMAL)
{
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
return;
}
@@ -74,7 +74,7 @@ _pager_lock_object (struct pager *p,
if (sync)
{
while (lr->locks_pending || lr->pending_writes)
- condition_wait (&p->wakeup, &p->interlock);
+ pthread_cond_wait (&p->wakeup, &p->interlock);
if (! --lr->threads_waiting)
{
@@ -103,5 +103,5 @@ _pager_lock_object (struct pager *p,
}
}
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
}
diff --git a/libpager/mark-error.c b/libpager/mark-error.c
index 5c4e029d..48ceb950 100644
--- a/libpager/mark-error.c
+++ b/libpager/mark-error.c
@@ -103,7 +103,7 @@ pager_get_error (struct pager *p, vm_address_t addr)
{
error_t err;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
addr /= vm_page_size;
@@ -116,7 +116,7 @@ pager_get_error (struct pager *p, vm_address_t addr)
if (! err)
err = _pager_page_errors[PM_ERROR(p->pagemap[addr])];
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
return err;
}
diff --git a/libpager/no-senders.c b/libpager/no-senders.c
index 3c2400c4..223cadd2 100644
--- a/libpager/no-senders.c
+++ b/libpager/no-senders.c
@@ -29,10 +29,10 @@ _pager_do_seqnos_mach_notify_no_senders (mach_port_t notify,
if (!p)
return EOPNOTSUPP;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_no_senders (p, mscount);
diff --git a/libpager/object-init.c b/libpager/object-init.c
index eeb50993..90ffc016 100644
--- a/libpager/object-init.c
+++ b/libpager/object-init.c
@@ -34,7 +34,7 @@ _pager_seqnos_memory_object_init (mach_port_t object,
if (!p)
return EOPNOTSUPP;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
if (pagesize != __vm_page_size)
@@ -72,7 +72,7 @@ _pager_seqnos_memory_object_init (mach_port_t object,
out:
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
diff --git a/libpager/object-terminate.c b/libpager/object-terminate.c
index dc53541c..896e2c20 100644
--- a/libpager/object-terminate.c
+++ b/libpager/object-terminate.c
@@ -33,7 +33,7 @@ _pager_seqnos_memory_object_terminate (mach_port_t object,
if (!p)
return EOPNOTSUPP;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
if (control != p->memobjcntl)
@@ -50,7 +50,7 @@ _pager_seqnos_memory_object_terminate (mach_port_t object,
while (p->noterm)
{
p->termwaiting = 1;
- condition_wait (&p->wakeup, &p->interlock);
+ pthread_cond_wait (&p->wakeup, &p->interlock);
}
/* Destry the ports we received; mark that in P so that it doesn't bother
@@ -78,7 +78,7 @@ _pager_seqnos_memory_object_terminate (mach_port_t object,
out:
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
return 0;
@@ -108,7 +108,7 @@ _pager_free_structure (struct pager *p)
}
if (wakeup)
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
if (p->memobjcntl != MACH_PORT_NULL)
{
diff --git a/libpager/offer-page.c b/libpager/offer-page.c
index aed22197..ef58c4b0 100644
--- a/libpager/offer-page.c
+++ b/libpager/offer-page.c
@@ -28,7 +28,7 @@ pager_offer_page (struct pager *p,
vm_offset_t offset,
vm_address_t buf)
{
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
if (_pager_pagemap_resize (p, offset + vm_page_size))
{
@@ -36,9 +36,9 @@ pager_offer_page (struct pager *p,
while (*pm_entry & PM_INCORE)
{
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
pager_flush_some (p, offset, vm_page_size, 1);
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
}
*pm_entry |= PM_INCORE;
@@ -47,6 +47,6 @@ pager_offer_page (struct pager *p,
precious, MACH_PORT_NULL);
}
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
}
diff --git a/libpager/pager-attr.c b/libpager/pager-attr.c
index cbc1533f..7629f1dc 100644
--- a/libpager/pager-attr.c
+++ b/libpager/pager-attr.c
@@ -30,7 +30,7 @@ pager_change_attributes (struct pager *p,
{
struct attribute_request *ar = 0;
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
/* If there's nothing to do we might be able to return. However,
if the user asked us to wait, and there are pending changes,
@@ -39,7 +39,7 @@ pager_change_attributes (struct pager *p,
if (p->may_cache == may_cache && p->copy_strategy == copy_strategy
&& ! (p->attribute_requests && wait))
{
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
return;
}
@@ -48,7 +48,7 @@ pager_change_attributes (struct pager *p,
if (p->pager_state == NOTINIT)
{
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
return;
}
@@ -83,7 +83,7 @@ pager_change_attributes (struct pager *p,
if (wait)
{
while (ar->attrs_pending)
- condition_wait (&p->wakeup, &p->interlock);
+ pthread_cond_wait (&p->wakeup, &p->interlock);
if (! --ar->threads_waiting)
{
@@ -94,5 +94,5 @@ pager_change_attributes (struct pager *p,
}
}
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
}
diff --git a/libpager/pager-create.c b/libpager/pager-create.c
index 26d1aad2..318c9f15 100644
--- a/libpager/pager-create.c
+++ b/libpager/pager-create.c
@@ -32,8 +32,8 @@ pager_create (struct user_pager_info *upi,
p->upi = upi;
p->pager_state = NOTINIT;
- mutex_init (&p->interlock);
- condition_init (&p->wakeup);
+ pthread_mutex_init (&p->interlock, NULL);
+ pthread_cond_init (&p->wakeup, NULL);
p->lock_requests = 0;
p->attribute_requests = 0;
p->may_cache = may_cache;
diff --git a/libpager/pager-shutdown.c b/libpager/pager-shutdown.c
index b729b3f2..86c70af0 100644
--- a/libpager/pager-shutdown.c
+++ b/libpager/pager-shutdown.c
@@ -25,9 +25,9 @@ pager_shutdown (struct pager *p)
/* Sync and flush pager */
pager_sync (p, 1);
pager_flush (p, 1);
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
p->pager_state = SHUTDOWN;
ports_destroy_right (p);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
}
diff --git a/libpager/priv.h b/libpager/priv.h
index f68c6092..e6b2546b 100644
--- a/libpager/priv.h
+++ b/libpager/priv.h
@@ -21,6 +21,7 @@
#include <mach.h>
#include <hurd.h>
#include <sys/mman.h>
+#include <pthread.h>
#include "pager.h"
#include <hurd/ports.h>
@@ -40,8 +41,8 @@ struct pager
SHUTDOWN, /* ignore all further requests */
} pager_state;
- struct mutex interlock;
- struct condition wakeup;
+ pthread_mutex_t interlock;
+ pthread_cond_t wakeup;
struct lock_request *lock_requests; /* pending lock requests */
struct attribute_request *attribute_requests; /* pending attr requests */
diff --git a/libpager/seqnos.c b/libpager/seqnos.c
index 7d8bcba7..77bfbf21 100644
--- a/libpager/seqnos.c
+++ b/libpager/seqnos.c
@@ -28,7 +28,7 @@ _pager_wait_for_seqno (struct pager *p,
while (seqno != p->seqno + 1)
{
p->waitingforseqno = 1;
- condition_wait (&p->wakeup, &p->interlock);
+ pthread_cond_wait (&p->wakeup, &p->interlock);
}
}
@@ -44,7 +44,7 @@ _pager_release_seqno (struct pager *p,
if (p->waitingforseqno)
{
p->waitingforseqno = 0;
- condition_broadcast (&p->wakeup);
+ pthread_cond_broadcast (&p->wakeup);
}
}
@@ -59,10 +59,10 @@ _pager_update_seqno (mach_port_t object,
p = ports_lookup_port (0, object, _pager_class);
if (p)
{
- mutex_lock (&p->interlock);
+ pthread_mutex_lock (&p->interlock);
_pager_wait_for_seqno (p, seqno);
_pager_release_seqno (p, seqno);
- mutex_unlock (&p->interlock);
+ pthread_mutex_unlock (&p->interlock);
ports_port_deref (p);
}
diff --git a/libpipe/Makefile b/libpipe/Makefile
index a7625d6c..35e27adf 100644
--- a/libpipe/Makefile
+++ b/libpipe/Makefile
@@ -25,7 +25,8 @@ installhdrs = pipe.h pq.h
SRCS = pq.c dgram.c pipe.c stream.c seqpack.c addr.c pq-funcs.c pipe-funcs.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS=threads ports
+HURDLIBS= ports
+LDLIBS += -lpthread
include ../Makeconf
diff --git a/libpipe/pipe.c b/libpipe/pipe.c
index 85aac0e6..dd306f60 100644
--- a/libpipe/pipe.c
+++ b/libpipe/pipe.c
@@ -35,7 +35,7 @@ timestamp (time_value_t *stamp)
}
/* Hold this lock before attempting to lock multiple pipes. */
-struct mutex pipe_multiple_lock = MUTEX_INITIALIZER;
+pthread_mutex_t pipe_multiple_lock = PTHREAD_MUTEX_INITIALIZER;
/* ---------------------------------------------------------------- */
@@ -60,12 +60,12 @@ pipe_create (struct pipe_class *class, struct pipe **pipe)
bzero (&new->read_time, sizeof (new->read_time));
bzero (&new->write_time, sizeof (new->write_time));
- condition_init (&new->pending_reads);
- condition_init (&new->pending_read_selects);
- condition_init (&new->pending_writes);
- condition_init (&new->pending_write_selects);
+ pthread_cond_init (&new->pending_reads, NULL);
+ pthread_cond_init (&new->pending_read_selects, NULL);
+ pthread_cond_init (&new->pending_writes, NULL);
+ pthread_cond_init (&new->pending_write_selects, NULL);
new->pending_selects = NULL;
- mutex_init (&new->lock);
+ pthread_mutex_init (&new->lock, NULL);
pq_create (&new->queue);
@@ -135,7 +135,7 @@ pipe_select_cond_broadcast (struct pipe *pipe)
do
{
- condition_broadcast (&cond->cond);
+ pthread_cond_broadcast (&cond->cond);
cond = cond->next;
}
while (cond != last);
@@ -169,12 +169,12 @@ void _pipe_no_readers (struct pipe *pipe)
if (pipe->writers)
/* Wake up writers for the bad news... */
{
- condition_broadcast (&pipe->pending_writes);
- condition_broadcast (&pipe->pending_write_selects);
+ pthread_cond_broadcast (&pipe->pending_writes);
+ pthread_cond_broadcast (&pipe->pending_write_selects);
pipe_select_cond_broadcast (pipe);
}
}
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
}
@@ -192,12 +192,12 @@ void _pipe_no_writers (struct pipe *pipe)
if (pipe->readers)
/* Wake up readers for the bad news... */
{
- condition_broadcast (&pipe->pending_reads);
- condition_broadcast (&pipe->pending_read_selects);
+ pthread_cond_broadcast (&pipe->pending_reads);
+ pthread_cond_broadcast (&pipe->pending_read_selects);
pipe_select_cond_broadcast (pipe);
}
}
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
}
@@ -217,15 +217,15 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
if (*select_type == SELECT_READ)
{
- mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
err = pipe_select_readable (rpipe, data_only);
- mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
}
else if (*select_type == SELECT_WRITE)
{
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
err = pipe_select_writable (wpipe);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
else
/* ugh */
@@ -233,18 +233,18 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
int rpipe_blocked, wpipe_blocked;
struct pipe_select_cond pending_select;
size_t wlimit = wpipe->write_limit;
- struct mutex *lock =
+ pthread_mutex_t *lock =
(wpipe == rpipe ? &rpipe->lock : &pipe_multiple_lock);
- condition_init (&pending_select.cond);
+ pthread_cond_init (&pending_select.cond, NULL);
- mutex_lock (lock);
+ pthread_mutex_lock (lock);
if (rpipe == wpipe)
pipe_add_select_cond (rpipe, &pending_select);
else
{
- mutex_lock (&rpipe->lock);
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
pipe_add_select_cond (rpipe, &pending_select);
pipe_add_select_cond (wpipe, &pending_select);
}
@@ -257,15 +257,15 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
{
if (rpipe != wpipe)
{
- mutex_unlock (&rpipe->lock);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
- if (hurd_condition_wait (&pending_select.cond, lock))
+ if (pthread_hurd_cond_wait_np (&pending_select.cond, lock))
err = EINTR;
if (rpipe != wpipe)
{
- mutex_lock (&rpipe->lock);
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
}
rpipe_blocked =
! ((rpipe->flags & PIPE_BROKEN)
@@ -289,10 +289,10 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
{
pipe_remove_select_cond (rpipe, &pending_select);
pipe_remove_select_cond (wpipe, &pending_select);
- mutex_unlock (&rpipe->lock);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
- mutex_unlock (lock);
+ pthread_mutex_unlock (lock);
}
return err;
@@ -357,14 +357,14 @@ pipe_send (struct pipe *pipe, int noblock, void *source,
timestamp (&pipe->write_time);
/* And wakeup anyone that might be interested in it. */
- condition_broadcast (&pipe->pending_reads);
- mutex_unlock (&pipe->lock);
+ pthread_cond_broadcast (&pipe->pending_reads);
+ pthread_mutex_unlock (&pipe->lock);
- mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
+ pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
/* Only wakeup selects if there's still data available. */
if (pipe_is_readable (pipe, 0))
{
- condition_broadcast (&pipe->pending_read_selects);
+ pthread_cond_broadcast (&pipe->pending_read_selects);
pipe_select_cond_broadcast (pipe);
/* We leave PIPE locked here, assuming the caller will soon unlock
it and allow others access. */
@@ -459,14 +459,14 @@ pipe_recv (struct pipe *pipe, int noblock, unsigned *flags, void **source,
timestamp (&pipe->read_time);
/* And wakeup anyone that might be interested in it. */
- condition_broadcast (&pipe->pending_writes);
- mutex_unlock (&pipe->lock);
+ pthread_cond_broadcast (&pipe->pending_writes);
+ pthread_mutex_unlock (&pipe->lock);
- mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
+ pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
/* Only wakeup selects if there's still writing space available. */
if (pipe_readable (pipe, 1) < pipe->write_limit)
{
- condition_broadcast (&pipe->pending_write_selects);
+ pthread_cond_broadcast (&pipe->pending_write_selects);
pipe_select_cond_broadcast (pipe);
/* We leave PIPE locked here, assuming the caller will soon unlock
it and allow others access. */
diff --git a/libpipe/pipe.h b/libpipe/pipe.h
index a3590fc4..b8e70681 100644
--- a/libpipe/pipe.h
+++ b/libpipe/pipe.h
@@ -23,7 +23,7 @@
#define EWOULDBLOCK EAGAIN /* XXX */
-#include <cthreads.h> /* For conditions & mutexes */
+#include <pthread.h> /* For conditions & mutexes */
#include <features.h>
#ifdef PIPE_DEFINE_EI
@@ -66,7 +66,7 @@ struct pipe_select_cond
{
struct pipe_select_cond *next;
struct pipe_select_cond *prev;
- struct condition cond;
+ pthread_cond_t cond;
};
/* A unidirectional data pipe; it transfers data from READER to WRITER. */
@@ -89,11 +89,11 @@ struct pipe
time_value_t read_time;
time_value_t write_time;
- struct condition pending_reads;
- struct condition pending_read_selects;
+ pthread_cond_t pending_reads;
+ pthread_cond_t pending_read_selects;
- struct condition pending_writes;
- struct condition pending_write_selects;
+ pthread_cond_t pending_writes;
+ pthread_cond_t pending_write_selects;
struct pipe_select_cond *pending_selects;
@@ -104,7 +104,7 @@ struct pipe
/* Write requests of less than this much are always done atomically. */
size_t write_atomic;
- struct mutex lock;
+ pthread_mutex_t lock;
/* A queue of incoming packets, of type either PACKET_TYPE_DATA or
PACKET_TYPE_CONTROL. Each data packet represents one datagram for
@@ -177,7 +177,7 @@ pipe_wait_readable (struct pipe *pipe, int noblock, int data_only)
{
if (noblock)
return EWOULDBLOCK;
- if (hurd_condition_wait (&pipe->pending_reads, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_reads, &pipe->lock))
return EINTR;
}
return 0;
@@ -191,7 +191,7 @@ PIPE_EI error_t
pipe_select_readable (struct pipe *pipe, int data_only)
{
while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN))
- if (hurd_condition_wait (&pipe->pending_read_selects, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_read_selects, &pipe->lock))
return EINTR;
return 0;
}
@@ -209,7 +209,7 @@ pipe_wait_writable (struct pipe *pipe, int noblock)
{
if (noblock)
return EWOULDBLOCK;
- if (hurd_condition_wait (&pipe->pending_writes, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_writes, &pipe->lock))
return EINTR;
if (pipe->flags & PIPE_BROKEN)
return EPIPE;
@@ -225,7 +225,7 @@ pipe_select_writable (struct pipe *pipe)
{
size_t limit = pipe->write_limit;
while (! (pipe->flags & PIPE_BROKEN) && pipe_readable (pipe, 1) >= limit)
- if (hurd_condition_wait (&pipe->pending_writes, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_writes, &pipe->lock))
return EINTR;
return 0;
}
@@ -276,7 +276,7 @@ extern void pipe_drain (struct pipe *pipe);
PIPE_EI void
pipe_acquire_reader (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe->readers++ == 0)
_pipe_first_reader (pipe);
}
@@ -285,7 +285,7 @@ pipe_acquire_reader (struct pipe *pipe)
PIPE_EI void
pipe_acquire_writer (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe->writers++ == 0)
_pipe_first_writer (pipe);
}
@@ -298,7 +298,7 @@ pipe_release_reader (struct pipe *pipe)
if (--pipe->readers == 0)
_pipe_no_readers (pipe);
else
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Decrement PIPE's (which should be locked) writer count and unlock it. If
@@ -309,7 +309,7 @@ pipe_release_writer (struct pipe *pipe)
if (--pipe->writers == 0)
_pipe_no_writers (pipe);
else
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Increment PIPE's reader count. PIPE should be unlocked. */
@@ -317,7 +317,7 @@ PIPE_EI void
pipe_add_reader (struct pipe *pipe)
{
pipe_acquire_reader (pipe);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Increment PIPE's writer count. PIPE should be unlocked. */
@@ -325,7 +325,7 @@ PIPE_EI void
pipe_add_writer (struct pipe *pipe)
{
pipe_acquire_writer (pipe);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Decrement PIPE's (which should be unlocked) reader count and unlock it. If
@@ -333,7 +333,7 @@ pipe_add_writer (struct pipe *pipe)
PIPE_EI void
pipe_remove_reader (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
pipe_release_reader (pipe);
}
@@ -342,7 +342,7 @@ pipe_remove_reader (struct pipe *pipe)
PIPE_EI void
pipe_remove_writer (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
pipe_release_writer (pipe);
}
@@ -410,7 +410,7 @@ error_t pipe_recv (struct pipe *pipe, int noblock, unsigned *flags,
pipe_recv (pipe, noblock, 0, source, data, data_len, amount, 0,0,0,0)
/* Hold this lock before attempting to lock multiple pipes. */
-extern struct mutex pipe_multiple_lock;
+extern pthread_mutex_t pipe_multiple_lock;
/* Return when either RPIPE is available for reading (if SELECT_READ is set
in *SELECT_TYPE), or WPIPE is available for writing (if select_write is
diff --git a/libports/Makefile b/libports/Makefile
index 8d7d9bbb..767ee73a 100644
--- a/libports/Makefile
+++ b/libports/Makefile
@@ -41,6 +41,7 @@ SRCS = create-bucket.c create-class.c \
installhdrs = ports.h
HURDLIBS= ihash
+LDLIBS += -lpthread
OBJS = $(SRCS:.c=.o) notifyServer.o interruptServer.o
MIGCOMSFLAGS = -prefix ports_
diff --git a/libports/begin-rpc.c b/libports/begin-rpc.c
index ebe3473c..1e0e8ed6 100644
--- a/libports/begin-rpc.c
+++ b/libports/begin-rpc.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#define INHIBITED (PORTS_INHIBITED | PORTS_INHIBIT_WAIT)
@@ -30,14 +29,14 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info)
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
do
{
/* If our receive right is gone, then abandon the RPC. */
if (pi->port_right == MACH_PORT_NULL)
{
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return EOPNOTSUPP;
}
@@ -76,13 +75,13 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info)
if (block_flags)
{
*block_flags |= PORTS_BLOCKED;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
/* We've been cancelled, just return EINTR. If we were the
only one blocking, PORTS_BLOCKED will still be turned on,
but that's ok, it will just cause a (harmless) extra
- condition_broadcast(). */
+ pthread_cond_broadcast(). */
{
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return EINTR;
}
}
@@ -103,7 +102,7 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info)
pi->bucket->rpcs++;
_ports_total_rpcs++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return 0;
}
diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c
index e439cb19..dc1c7b11 100644
--- a/libports/bucket-iterate.c
+++ b/libports/bucket-iterate.c
@@ -19,7 +19,6 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <hurd/ihash.h>
@@ -40,7 +39,7 @@ _ports_bucket_class_iterate (struct port_bucket *bucket,
struct item *i, *nxt;
error_t err;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
HURD_IHASH_ITERATE (&bucket->htable, arg)
{
struct port_info *const pi = arg;
@@ -55,7 +54,7 @@ _ports_bucket_class_iterate (struct port_bucket *bucket,
pi->refcnt++;
}
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
err = 0;
for (i = list; i; i = nxt)
diff --git a/libports/claim-right.c b/libports/claim-right.c
index aef53bb7..69d378f9 100644
--- a/libports/claim-right.c
+++ b/libports/claim-right.c
@@ -34,7 +34,7 @@ ports_claim_right (void *portstruct)
if (ret == MACH_PORT_NULL)
return ret;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry);
err = mach_port_move_member (mach_task_self (), ret, MACH_PORT_NULL);
assert_perror (err);
@@ -42,11 +42,11 @@ ports_claim_right (void *portstruct)
if (pi->flags & PORT_HAS_SENDRIGHTS)
{
pi->flags &= ~PORT_HAS_SENDRIGHTS;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
ports_port_deref (pi);
}
else
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return ret;
}
diff --git a/libports/class-iterate.c b/libports/class-iterate.c
index e2a15173..1f8878a5 100644
--- a/libports/class-iterate.c
+++ b/libports/class-iterate.c
@@ -18,19 +18,18 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "ports.h"
-#include <cthreads.h>
error_t
ports_class_iterate (struct port_class *class,
error_t (*fun)(void *))
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (class->ports != 0)
{
struct port_bucket *bucket = class->ports->bucket;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return _ports_bucket_class_iterate (bucket, class, fun);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return 0;
}
diff --git a/libports/complete-deallocate.c b/libports/complete-deallocate.c
index 52e8f17b..e569b461 100644
--- a/libports/complete-deallocate.c
+++ b/libports/complete-deallocate.c
@@ -21,7 +21,6 @@
#include "ports.h"
#include <assert.h>
#include <hurd/ihash.h>
-#include <cthreads.h>
void
_ports_complete_deallocate (struct port_info *pi)
@@ -43,7 +42,7 @@ _ports_complete_deallocate (struct port_info *pi)
pi->bucket->count--;
pi->class->count--;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
if (pi->class->clean_routine)
(*pi->class->clean_routine)(pi);
diff --git a/libports/count-bucket.c b/libports/count-bucket.c
index 9aff58e9..63feb6be 100644
--- a/libports/count-bucket.c
+++ b/libports/count-bucket.c
@@ -19,17 +19,16 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
int
ports_count_bucket (struct port_bucket *bucket)
{
int ret;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
ret = bucket->count;
bucket->flags |= PORT_BUCKET_NO_ALLOC;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return ret;
}
diff --git a/libports/count-class.c b/libports/count-class.c
index 6aa88aa9..986a68bb 100644
--- a/libports/count-class.c
+++ b/libports/count-class.c
@@ -19,17 +19,16 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
int
ports_count_class (struct port_class *class)
{
int ret;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
ret = class->count;
class->flags |= PORT_CLASS_NO_ALLOC;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return ret;
}
diff --git a/libports/create-bucket.c b/libports/create-bucket.c
index 6be4bcad..52d50c35 100644
--- a/libports/create-bucket.c
+++ b/libports/create-bucket.c
@@ -23,7 +23,6 @@
#include <errno.h>
#include <stdlib.h>
#include <hurd/ihash.h>
-#include <cthreads.h>
struct port_bucket *
ports_create_bucket ()
@@ -50,10 +49,10 @@ ports_create_bucket ()
hurd_ihash_init (&ret->htable, offsetof (struct port_info, hentry));
ret->rpcs = ret->flags = ret->count = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
ret->next = _ports_all_buckets;
_ports_all_buckets = ret;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return ret;
}
diff --git a/libports/create-internal.c b/libports/create-internal.c
index 7a9b1cb0..c60f6fd9 100644
--- a/libports/create-internal.c
+++ b/libports/create-internal.c
@@ -19,7 +19,6 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include <assert.h>
-#include <cthreads.h>
#include <hurd/ihash.h>
#include "ports.h"
@@ -64,20 +63,20 @@ _ports_create_port_internal (struct port_class *class,
pi->current_rpcs = 0;
pi->bucket = bucket;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
loop:
if (class->flags & PORT_CLASS_NO_ALLOC)
{
class->flags |= PORT_CLASS_ALLOC_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
goto cancelled;
goto loop;
}
if (bucket->flags & PORT_BUCKET_NO_ALLOC)
{
bucket->flags |= PORT_BUCKET_ALLOC_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
goto cancelled;
goto loop;
}
@@ -93,7 +92,7 @@ _ports_create_port_internal (struct port_class *class,
class->ports = pi;
bucket->count++;
class->count++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
if (install)
{
@@ -109,7 +108,7 @@ _ports_create_port_internal (struct port_class *class,
cancelled:
err = EINTR;
lose:
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
lose_unlocked:
err = mach_port_mod_refs (mach_task_self (), port,
MACH_PORT_RIGHT_RECEIVE, -1);
diff --git a/libports/destroy-right.c b/libports/destroy-right.c
index 327029a8..65e19c78 100644
--- a/libports/destroy-right.c
+++ b/libports/destroy-right.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <hurd/ihash.h>
#include <assert.h>
@@ -31,12 +30,12 @@ ports_destroy_right (void *portstruct)
if (pi->port_right != MACH_PORT_NULL)
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry);
err = mach_port_mod_refs (mach_task_self (), pi->port_right,
MACH_PORT_RIGHT_RECEIVE, -1);
assert_perror (err);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
pi->port_right = MACH_PORT_NULL;
diff --git a/libports/enable-bucket.c b/libports/enable-bucket.c
index 278c5bb5..f9c7b859 100644
--- a/libports/enable-bucket.c
+++ b/libports/enable-bucket.c
@@ -19,17 +19,16 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
void
ports_enable_bucket (struct port_bucket *bucket)
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
bucket->flags &= ~PORT_BUCKET_NO_ALLOC;
if (bucket->flags & PORT_BUCKET_ALLOC_WAIT)
{
bucket->flags &= ~PORT_BUCKET_ALLOC_WAIT;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/enable-class.c b/libports/enable-class.c
index 7aebf685..b3894ebb 100644
--- a/libports/enable-class.c
+++ b/libports/enable-class.c
@@ -19,17 +19,16 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
void
ports_enable_class (struct port_class *class)
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
class->flags &= ~PORT_CLASS_NO_ALLOC;
if (class->flags & PORT_CLASS_ALLOC_WAIT)
{
class->flags &= ~PORT_CLASS_ALLOC_WAIT;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/end-rpc.c b/libports/end-rpc.c
index 47fd1ae7..b5dcb3a2 100644
--- a/libports/end-rpc.c
+++ b/libports/end-rpc.c
@@ -19,14 +19,13 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
void
ports_end_rpc (void *port, struct rpc_info *info)
{
struct port_info *pi = port;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (info->notifies)
_ports_remove_notified_rpc (info);
@@ -42,7 +41,7 @@ ports_end_rpc (void *port, struct rpc_info *info)
|| (pi->bucket->flags & PORT_BUCKET_INHIBIT_WAIT)
|| (pi->class->flags & PORT_CLASS_INHIBIT_WAIT)
|| (_ports_flags & _PORTS_INHIBIT_WAIT))
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
/* This removes the current thread's rpc (which should be INFO) from the
ports interrupted list. */
@@ -52,5 +51,5 @@ ports_end_rpc (void *port, struct rpc_info *info)
RPC is now finished anwhow. */
hurd_check_cancel ();
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/get-right.c b/libports/get-right.c
index 95662f58..89050c6b 100644
--- a/libports/get-right.c
+++ b/libports/get-right.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <mach/notify.h>
#include <assert.h>
@@ -30,11 +29,11 @@ ports_get_right (void *port)
mach_port_t foo;
error_t err;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (pi->port_right == MACH_PORT_NULL)
{
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return MACH_PORT_NULL;
}
@@ -54,6 +53,6 @@ ports_get_right (void *port)
if (foo != MACH_PORT_NULL)
mach_port_deallocate (mach_task_self (), foo);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return pi->port_right;
}
diff --git a/libports/import-port.c b/libports/import-port.c
index d7a62960..226f47e3 100644
--- a/libports/import-port.c
+++ b/libports/import-port.c
@@ -22,7 +22,6 @@
#include "ports.h"
#include <assert.h>
-#include <cthreads.h>
#include <hurd/ihash.h>
#include <mach/notify.h>
@@ -58,20 +57,20 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket,
pi->current_rpcs = 0;
pi->bucket = bucket;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
loop:
if (class->flags & PORT_CLASS_NO_ALLOC)
{
class->flags |= PORT_CLASS_ALLOC_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
goto cancelled;
goto loop;
}
if (bucket->flags & PORT_BUCKET_NO_ALLOC)
{
bucket->flags |= PORT_BUCKET_ALLOC_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
goto cancelled;
goto loop;
}
@@ -87,7 +86,7 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket,
class->ports = pi;
bucket->count++;
class->count++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
mach_port_move_member (mach_task_self (), port, bucket->portset);
@@ -109,7 +108,7 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket,
cancelled:
err = EINTR;
lose:
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
free (pi);
return err;
diff --git a/libports/inhibit-all-rpcs.c b/libports/inhibit-all-rpcs.c
index 9a72f83e..d4a54ba5 100644
--- a/libports/inhibit-all-rpcs.c
+++ b/libports/inhibit-all-rpcs.c
@@ -20,7 +20,6 @@
#include "ports.h"
#include <hurd.h>
-#include <cthreads.h>
#include <hurd/ihash.h>
error_t
@@ -28,7 +27,7 @@ ports_inhibit_all_rpcs ()
{
error_t err = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (_ports_flags & (_PORTS_INHIBITED | _PORTS_INHIBIT_WAIT))
err = EBUSY;
@@ -59,7 +58,7 @@ ports_inhibit_all_rpcs ()
while (_ports_total_rpcs > this_one)
{
_ports_flags |= _PORTS_INHIBIT_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
/* We got cancelled. */
{
err = EINTR;
@@ -72,7 +71,7 @@ ports_inhibit_all_rpcs ()
_ports_flags |= _PORTS_INHIBITED;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return err;
}
diff --git a/libports/inhibit-bucket-rpcs.c b/libports/inhibit-bucket-rpcs.c
index 7fc55d31..965aa036 100644
--- a/libports/inhibit-bucket-rpcs.c
+++ b/libports/inhibit-bucket-rpcs.c
@@ -20,7 +20,6 @@
#include "ports.h"
#include <hurd.h>
-#include <cthreads.h>
#include <hurd/ihash.h>
error_t
@@ -28,7 +27,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket)
{
error_t err = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (bucket->flags & (PORT_BUCKET_INHIBITED | PORT_BUCKET_INHIBIT_WAIT))
err = EBUSY;
@@ -55,7 +54,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket)
while (bucket->rpcs > this_one)
{
bucket->flags |= PORT_BUCKET_INHIBIT_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
/* We got cancelled. */
{
err = EINTR;
@@ -68,7 +67,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket)
bucket->flags |= PORT_BUCKET_INHIBITED;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return err;
}
diff --git a/libports/inhibit-class-rpcs.c b/libports/inhibit-class-rpcs.c
index 951de4bf..7ee86538 100644
--- a/libports/inhibit-class-rpcs.c
+++ b/libports/inhibit-class-rpcs.c
@@ -20,14 +20,13 @@
#include "ports.h"
#include <hurd.h>
-#include <cthreads.h>
error_t
ports_inhibit_class_rpcs (struct port_class *class)
{
error_t err = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (class->flags & (PORT_CLASS_INHIBITED | PORT_CLASS_INHIBIT_WAIT))
err = EBUSY;
@@ -50,7 +49,7 @@ ports_inhibit_class_rpcs (struct port_class *class)
while (class->rpcs > this_one)
{
class->flags |= PORT_CLASS_INHIBIT_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
/* We got cancelled. */
{
err = EINTR;
@@ -63,7 +62,7 @@ ports_inhibit_class_rpcs (struct port_class *class)
class->flags |= PORT_CLASS_INHIBITED;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return err;
}
diff --git a/libports/inhibit-port-rpcs.c b/libports/inhibit-port-rpcs.c
index 02a3b462..b741eeb7 100644
--- a/libports/inhibit-port-rpcs.c
+++ b/libports/inhibit-port-rpcs.c
@@ -20,7 +20,6 @@
#include "ports.h"
#include <hurd.h>
-#include <cthreads.h>
error_t
ports_inhibit_port_rpcs (void *portstruct)
@@ -28,7 +27,7 @@ ports_inhibit_port_rpcs (void *portstruct)
error_t err = 0;
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (pi->flags & (PORT_INHIBITED | PORT_INHIBIT_WAIT))
err = EBUSY;
@@ -51,7 +50,7 @@ ports_inhibit_port_rpcs (void *portstruct)
&& !(pi->current_rpcs == this_rpc && ! this_rpc->next))
{
pi->flags |= PORT_INHIBIT_WAIT;
- if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock))
/* We got cancelled. */
{
err = EINTR;
@@ -64,7 +63,7 @@ ports_inhibit_port_rpcs (void *portstruct)
pi->flags |= PORT_INHIBITED;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return err;
}
diff --git a/libports/init.c b/libports/init.c
index 7d4d16fd..3ef53888 100644
--- a/libports/init.c
+++ b/libports/init.c
@@ -19,10 +19,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
-struct mutex _ports_lock = MUTEX_INITIALIZER;
-struct condition _ports_block = CONDITION_INITIALIZER;
+pthread_mutex_t _ports_lock = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t _ports_block = PTHREAD_COND_INITIALIZER;
struct port_bucket *_ports_all_buckets;
int _ports_total_rpcs;
int _ports_flags;
diff --git a/libports/interrupt-notified-rpcs.c b/libports/interrupt-notified-rpcs.c
index bdfef977..6d6493d3 100644
--- a/libports/interrupt-notified-rpcs.c
+++ b/libports/interrupt-notified-rpcs.c
@@ -36,7 +36,7 @@ ports_interrupt_notified_rpcs (void *object,
{
struct ports_notify *np;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
for (np = _ports_notifications; np; np = np->next)
if (np->port == port && np->what == what)
{
@@ -49,7 +49,7 @@ ports_interrupt_notified_rpcs (void *object,
}
break;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
}
diff --git a/libports/interrupt-on-notify.c b/libports/interrupt-on-notify.c
index 42ae4884..b358e840 100644
--- a/libports/interrupt-on-notify.c
+++ b/libports/interrupt-on-notify.c
@@ -34,13 +34,13 @@ ports_interrupt_rpc_on_notification (void *object,
struct rpc_notify *new_req, *req;
struct port_info *pi = object;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (! MACH_PORT_VALID (port))
/* PORT is already dead or bogus, so interrupt the rpc immediately. */
{
hurd_thread_cancel (rpc->thread);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return 0;
}
@@ -53,11 +53,11 @@ ports_interrupt_rpc_on_notification (void *object,
time we'll add a new structure, so we malloc while we don't have the
lock, and free it if we're wrong. */
{
- mutex_unlock (&_ports_lock); /* Don't hold the lock during malloc. */
+ pthread_mutex_unlock (&_ports_lock); /* Don't hold the lock during malloc. */
new_req = malloc (sizeof (struct rpc_notify));
if (! new_req)
return ENOMEM;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
}
/* Find any existing entry for PORT/WHAT. */
@@ -80,7 +80,7 @@ ports_interrupt_rpc_on_notification (void *object,
{
new_req->next = _ports_free_rpc_notifies;
_ports_free_rpc_notifies = new_req;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return ENOMEM;
}
}
@@ -89,7 +89,7 @@ ports_interrupt_rpc_on_notification (void *object,
pn->port = port;
pn->what = what;
pn->pending = 0;
- mutex_init (&pn->lock);
+ pthread_mutex_init (&pn->lock, NULL);
pn->next = _ports_notifications;
pn->prevp = &_ports_notifications;
@@ -136,9 +136,9 @@ ports_interrupt_rpc_on_notification (void *object,
immediate notification). */
req_notify = !pn->pending;
if (req_notify)
- mutex_lock (&pn->lock);
+ pthread_mutex_lock (&pn->lock);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
if (req_notify)
{
@@ -152,7 +152,7 @@ ports_interrupt_rpc_on_notification (void *object,
mach_port_deallocate (mach_task_self (), old);
pn->pending = 1;
- mutex_unlock (&pn->lock);
+ pthread_mutex_unlock (&pn->lock);
return err;
}
@@ -170,11 +170,11 @@ ports_interrupt_self_on_notification (void *object,
struct port_info *pi = object;
thread_t thread = hurd_thread_self ();
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
for (rpc = pi->current_rpcs; rpc; rpc = rpc->next)
if (rpc->thread == thread)
break;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
assert (rpc);
diff --git a/libports/interrupt-operation.c b/libports/interrupt-operation.c
index 1545f788..19c0edf6 100644
--- a/libports/interrupt-operation.c
+++ b/libports/interrupt-operation.c
@@ -30,10 +30,10 @@ ports_S_interrupt_operation (mach_port_t port,
struct port_info *pi = ports_lookup_port (0, port, 0);
if (!pi)
return EOPNOTSUPP;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (pi->cancel_threshold < seqno)
pi->cancel_threshold = seqno;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
ports_interrupt_rpcs (pi);
ports_port_deref (pi);
return 0;
diff --git a/libports/interrupt-rpcs.c b/libports/interrupt-rpcs.c
index 7c28ff2c..42f51a5e 100644
--- a/libports/interrupt-rpcs.c
+++ b/libports/interrupt-rpcs.c
@@ -20,7 +20,6 @@
#include "ports.h"
#include <hurd.h>
-#include <cthreads.h>
void
ports_interrupt_rpcs (void *portstruct)
@@ -28,7 +27,7 @@ ports_interrupt_rpcs (void *portstruct)
struct port_info *pi = portstruct;
struct rpc_info *rpc;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
for (rpc = pi->current_rpcs; rpc; rpc = rpc->next)
{
@@ -36,5 +35,5 @@ ports_interrupt_rpcs (void *portstruct)
_ports_record_interruption (rpc);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/interrupted.c b/libports/interrupted.c
index e4cb2fc2..88fb9ef0 100644
--- a/libports/interrupted.c
+++ b/libports/interrupted.c
@@ -20,7 +20,7 @@
#include "ports.h"
-static spin_lock_t interrupted_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t interrupted_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* True if some active rpc has been interrupted. */
static struct rpc_info *interrupted = 0;
@@ -33,19 +33,19 @@ ports_self_interrupted ()
struct rpc_info **rpc_p, *rpc;
thread_t self = hurd_thread_self ();
- spin_lock (&interrupted_lock);
+ pthread_spin_lock (&interrupted_lock);
for (rpc_p = &interrupted; *rpc_p; rpc_p = &rpc->interrupted_next)
{
rpc = *rpc_p;
if (rpc->thread == self)
{
*rpc_p = rpc->interrupted_next;
- spin_unlock (&interrupted_lock);
+ pthread_spin_unlock (&interrupted_lock);
rpc->interrupted_next = 0;
return 1;
}
}
- spin_unlock (&interrupted_lock);
+ pthread_spin_unlock (&interrupted_lock);
return 0;
}
@@ -56,14 +56,14 @@ _ports_record_interruption (struct rpc_info *rpc)
{
struct rpc_info *i;
- spin_lock (&interrupted_lock);
+ pthread_spin_lock (&interrupted_lock);
/* See if RPC is already in the interrupted list. */
for (i = interrupted; i; i = i->interrupted_next)
if (i == rpc)
/* Yup, it is, so just leave it there. */
{
- spin_unlock (&interrupted_lock);
+ pthread_spin_unlock (&interrupted_lock);
return;
}
@@ -71,5 +71,5 @@ _ports_record_interruption (struct rpc_info *rpc)
rpc->interrupted_next = interrupted;
interrupted = rpc;
- spin_unlock (&interrupted_lock);
+ pthread_spin_unlock (&interrupted_lock);
}
diff --git a/libports/lookup-port.c b/libports/lookup-port.c
index 8eb98a12..373d929c 100644
--- a/libports/lookup-port.c
+++ b/libports/lookup-port.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <hurd/ihash.h>
void *
@@ -29,7 +28,7 @@ ports_lookup_port (struct port_bucket *bucket,
{
struct port_info *pi = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (bucket)
pi = hurd_ihash_find (&bucket->htable, port);
@@ -47,7 +46,7 @@ ports_lookup_port (struct port_bucket *bucket,
if (pi)
pi->refcnt++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return pi;
}
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index 035cd38d..c46a09fc 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -19,13 +19,18 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <spin-lock.h>
#include <assert.h>
-#include <cthreads.h>
+#include <stdio.h>
#include <mach/message.h>
#include <mach/thread_info.h>
#include <mach/thread_switch.h>
+#define STACK_SIZE (64 * 1024)
+
+/* FIXME Until threadvars are completely replaced with correct TLS, use this
+ hack to set the stack size. */
+size_t __pthread_stack_default_size = STACK_SIZE;
+
#define THREAD_PRI 2
/* XXX To reduce starvation, the priority of new threads is initially
@@ -88,9 +93,14 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
{
volatile unsigned int nreqthreads;
volatile unsigned int totalthreads;
- spin_lock_t lock = SPIN_LOCK_INITIALIZER;
+ pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER;
+ pthread_attr_t attr;
+
+ auto void * thread_function (void *);
- auto int thread_function (int);
+ /* FIXME This is currently a no-op. */
+ pthread_attr_init (&attr);
+ pthread_attr_setstacksize (&attr, STACK_SIZE);
int
internal_demuxer (mach_msg_header_t *inp,
@@ -110,18 +120,32 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
/* msgt_unused = */ 0
};
- spin_lock (&lock);
+ pthread_spin_lock (&lock);
assert (nreqthreads);
nreqthreads--;
if (nreqthreads != 0)
- spin_unlock (&lock);
+ pthread_spin_unlock (&lock);
else
/* No thread would be listening for requests, spawn one. */
{
+ pthread_t pthread_id;
+ error_t err;
+
totalthreads++;
nreqthreads++;
- spin_unlock (&lock);
- cthread_detach (cthread_fork ((cthread_fn_t) thread_function, 0));
+ pthread_spin_unlock (&lock);
+
+ err = pthread_create (&pthread_id, &attr, thread_function, NULL);
+ if (!err)
+ pthread_detach (pthread_id);
+ else
+ {
+ /* XXX The number of threads should be adjusted but the code
+ and design of the Hurd servers just don't handle thread
+ creation failure. */
+ errno = err;
+ perror ("pthread_create");
+ }
}
/* Fill in default response. */
@@ -146,10 +170,10 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
}
else
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (inp->msgh_seqno < pi->cancel_threshold)
hurd_thread_cancel (link.thread);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
status = demuxer (inp, outheadp);
ports_end_rpc (pi, &link);
}
@@ -161,16 +185,17 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
status = 1;
}
- spin_lock (&lock);
+ pthread_spin_lock (&lock);
nreqthreads++;
- spin_unlock (&lock);
+ pthread_spin_unlock (&lock);
return status;
}
- int
- thread_function (int master)
+ void *
+ thread_function (void *arg)
{
+ int master = (int) arg;
int timeout;
error_t err;
@@ -195,32 +220,32 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
if (master)
{
- spin_lock (&lock);
+ pthread_spin_lock (&lock);
if (totalthreads != 1)
{
- spin_unlock (&lock);
+ pthread_spin_unlock (&lock);
goto startover;
}
}
else
{
- spin_lock (&lock);
+ pthread_spin_lock (&lock);
if (nreqthreads == 1)
{
/* No other thread is listening for requests, continue. */
- spin_unlock (&lock);
+ pthread_spin_unlock (&lock);
goto startover;
}
nreqthreads--;
totalthreads--;
- spin_unlock (&lock);
+ pthread_spin_unlock (&lock);
}
- return 0;
+ return NULL;
}
nreqthreads = 1;
totalthreads = 1;
- thread_function (1);
+ thread_function ((void *) 1);
}
diff --git a/libports/no-senders.c b/libports/no-senders.c
index 0e8a5f17..1a6084b1 100644
--- a/libports/no-senders.c
+++ b/libports/no-senders.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <mach/notify.h>
void
@@ -30,10 +29,10 @@ ports_no_senders (void *portstruct,
int dealloc;
mach_port_t old;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if ((pi->flags & PORT_HAS_SENDRIGHTS) == 0)
{
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
return;
}
if (mscount >= pi->mscount)
@@ -54,7 +53,7 @@ ports_no_senders (void *portstruct,
mach_port_deallocate (mach_task_self (), old);
dealloc = 0;
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
if (dealloc)
{
diff --git a/libports/port-deref-weak.c b/libports/port-deref-weak.c
index 2bef3338..91071ffa 100644
--- a/libports/port-deref-weak.c
+++ b/libports/port-deref-weak.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
@@ -27,12 +26,12 @@ ports_port_deref_weak (void *portstruct)
{
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->weakrefcnt);
pi->weakrefcnt--;
if (pi->refcnt == 0 && pi->weakrefcnt == 0)
_ports_complete_deallocate (pi);
else
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/port-deref.c b/libports/port-deref.c
index 1ded45d9..ae10a02c 100644
--- a/libports/port-deref.c
+++ b/libports/port-deref.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
@@ -30,12 +29,12 @@ ports_port_deref (void *portstruct)
retry:
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
if (pi->refcnt == 1 && pi->weakrefcnt
&& pi->class->dropweak_routine && !trieddroppingweakrefs)
{
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
(*pi->class->dropweak_routine) (pi);
trieddroppingweakrefs = 1;
goto retry;
@@ -47,7 +46,7 @@ ports_port_deref (void *portstruct)
if (pi->refcnt == 0 && pi->weakrefcnt == 0)
_ports_complete_deallocate (pi);
else
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/port-ref-weak.c b/libports/port-ref-weak.c
index 6ebd5608..c7d3c690 100644
--- a/libports/port-ref-weak.c
+++ b/libports/port-ref-weak.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
@@ -27,8 +26,8 @@ ports_port_ref_weak (void *portstruct)
{
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->refcnt || pi->weakrefcnt);
pi->weakrefcnt++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/port-ref.c b/libports/port-ref.c
index 7fd15272..864c540e 100644
--- a/libports/port-ref.c
+++ b/libports/port-ref.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
@@ -27,10 +26,10 @@ ports_port_ref (void *portstruct)
{
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->refcnt || pi->weakrefcnt);
pi->refcnt++;
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/ports.h b/libports/ports.h
index 9a5ccbc2..07918412 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -26,6 +26,7 @@
#include <hurd.h>
#include <hurd/ihash.h>
#include <mach/notify.h>
+#include <pthread.h>
/* These are global values for common flags used in the various structures.
Not all of these are meaningful in all flag fields. */
@@ -115,7 +116,7 @@ struct ports_notify
mach_port_t port; /* */
mach_msg_id_t what; /* MACH_NOTIFY_* */
unsigned pending : 1; /* There's a notification outstanding. */
- struct mutex lock;
+ pthread_mutex_t lock;
struct rpc_notify *reqs; /* Which rpcs are notified by this port. */
struct ports_notify *next, **prevp; /* Linked list of all notified ports. */
@@ -396,8 +397,8 @@ extern kern_return_t ports_S_interrupt_operation (mach_port_t,
mach_port_seqno_t);
/* Private data */
-extern struct mutex _ports_lock;
-extern struct condition _ports_block;
+extern pthread_mutex_t _ports_lock;
+extern pthread_cond_t _ports_block;
extern struct port_bucket *_ports_all_buckets;
extern int _ports_total_rpcs;
extern int _ports_flags;
diff --git a/libports/reallocate-from-external.c b/libports/reallocate-from-external.c
index ebddd9f7..cd12143c 100644
--- a/libports/reallocate-from-external.c
+++ b/libports/reallocate-from-external.c
@@ -20,7 +20,6 @@
#include "ports.h"
#include <assert.h>
-#include <cthreads.h>
#include <hurd/ihash.h>
#include <mach/notify.h>
@@ -36,7 +35,7 @@ ports_reallocate_from_external (void *portstruct, mach_port_t receive)
err = mach_port_get_receive_status (mach_task_self (), receive, &stat);
assert_perror (err);
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->port_right);
@@ -62,7 +61,7 @@ ports_reallocate_from_external (void *portstruct, mach_port_t receive)
pi->mscount = stat.mps_mscount;
hurd_ihash_add (&pi->bucket->htable, receive, pi);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
mach_port_move_member (mach_task_self (), receive, pi->bucket->portset);
diff --git a/libports/reallocate-port.c b/libports/reallocate-port.c
index 23898e88..891786cb 100644
--- a/libports/reallocate-port.c
+++ b/libports/reallocate-port.c
@@ -21,7 +21,6 @@
#include "ports.h"
#include <hurd/ihash.h>
#include <assert.h>
-#include <cthreads.h>
void
ports_reallocate_port (void *portstruct)
@@ -30,7 +29,7 @@ ports_reallocate_port (void *portstruct)
error_t err;
int dropref = 0;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->port_right);
err = mach_port_mod_refs (mach_task_self (), pi->port_right,
@@ -50,7 +49,7 @@ ports_reallocate_port (void *portstruct)
pi->cancel_threshold = 0;
pi->mscount = 0;
hurd_ihash_add (&pi->bucket->htable, pi->port_right, pi);
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
err = mach_port_move_member (mach_task_self (), pi->port_right,
pi->bucket->portset);
diff --git a/libports/resume-all-rpcs.c b/libports/resume-all-rpcs.c
index 452da3b2..e9669e0f 100644
--- a/libports/resume-all-rpcs.c
+++ b/libports/resume-all-rpcs.c
@@ -19,21 +19,20 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
ports_resume_all_rpcs ()
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (_ports_flags & _PORTS_INHIBITED);
_ports_flags &= ~_PORTS_INHIBITED;
if (_ports_flags & _PORTS_BLOCKED)
{
_ports_flags &= ~_PORTS_BLOCKED;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/resume-bucket-rpcs.c b/libports/resume-bucket-rpcs.c
index 59cc75a4..cf4db91c 100644
--- a/libports/resume-bucket-rpcs.c
+++ b/libports/resume-bucket-rpcs.c
@@ -19,19 +19,18 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
ports_resume_bucket_rpcs (struct port_bucket *bucket)
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (bucket->flags & PORT_BUCKET_INHIBITED);
bucket->flags &= ~PORT_BUCKET_INHIBITED;
if (bucket->flags & PORT_BUCKET_BLOCKED)
{
bucket->flags &= ~PORT_BUCKET_BLOCKED;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/resume-class-rpcs.c b/libports/resume-class-rpcs.c
index a4191747..a8c701e2 100644
--- a/libports/resume-class-rpcs.c
+++ b/libports/resume-class-rpcs.c
@@ -19,20 +19,19 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
ports_resume_class_rpcs (struct port_class *class)
{
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (class->flags & PORT_CLASS_INHIBITED);
class->flags &= ~PORT_CLASS_INHIBITED;
if (class->flags & PORT_CLASS_BLOCKED)
{
class->flags &= ~PORT_CLASS_BLOCKED;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/resume-port-rpcs.c b/libports/resume-port-rpcs.c
index e9e30fbd..5dc5c70e 100644
--- a/libports/resume-port-rpcs.c
+++ b/libports/resume-port-rpcs.c
@@ -19,7 +19,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "ports.h"
-#include <cthreads.h>
#include <assert.h>
void
@@ -27,16 +26,16 @@ ports_resume_port_rpcs (void *portstruct)
{
struct port_info *pi = portstruct;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
assert (pi->flags & PORT_INHIBITED);
pi->flags &= ~PORT_INHIBITED;
if (pi->flags & PORT_BLOCKED)
{
pi->flags &= ~PORT_BLOCKED;
- condition_broadcast (&_ports_block);
+ pthread_cond_broadcast (&_ports_block);
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
}
diff --git a/libports/stubs.c b/libports/stubs.c
index 23c6a0ea..de4ae4dd 100644
--- a/libports/stubs.c
+++ b/libports/stubs.c
@@ -21,6 +21,7 @@
/* This file contains stubs for some cthreads functions.
It should only get used if the user isn't otherwise using cthreads. */
+#if 0
#include <cthreads.h>
void condition_wait (condition_t c, mutex_t m) __attribute__ ((weak));
@@ -36,3 +37,4 @@ void
cond_broadcast (condition_t c)
{
}
+#endif
diff --git a/libports/transfer-right.c b/libports/transfer-right.c
index e7b0ff55..2a790694 100644
--- a/libports/transfer-right.c
+++ b/libports/transfer-right.c
@@ -35,7 +35,7 @@ ports_transfer_right (void *tostruct,
int hassendrights = 0;
error_t err;
- mutex_lock (&_ports_lock);
+ pthread_mutex_lock (&_ports_lock);
/* Fetch the port in FROMPI and clear its use */
port = frompi->port_right;
@@ -86,7 +86,7 @@ ports_transfer_right (void *tostruct,
}
}
- mutex_unlock (&_ports_lock);
+ pthread_mutex_unlock (&_ports_lock);
/* Take care of any lowered reference counts. */
if (dereffrompi)
diff --git a/libstore/Makefile b/libstore/Makefile
index 9381b95c..eafdd0a7 100644
--- a/libstore/Makefile
+++ b/libstore/Makefile
@@ -53,6 +53,7 @@ libstore.so-LDLIBS += $(PARTED_LIBS) -ldl
installhdrs=store.h
HURDLIBS = shouldbeinlibc
+LDLIBS += -lpthread
GUNZIP_OBJS = unzip.o inflate.o util.o
BUNZIP2_OBJS = do-bunzip2.o
OBJS = $(SRCS:.c=.o) $(GUNZIP_OBJS) $(BUNZIP2_OBJS)
diff --git a/libstore/gunzip.c b/libstore/gunzip.c
index 3bff6ead..7c449403 100644
--- a/libstore/gunzip.c
+++ b/libstore/gunzip.c
@@ -21,7 +21,6 @@
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
-#include <cthreads.h>
#include <sys/mman.h>
#include "store.h"
diff --git a/libstore/part.c b/libstore/part.c
index 439340be..56e904eb 100644
--- a/libstore/part.c
+++ b/libstore/part.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <parted/parted.h>
/*#include <parted/device_gnu.h>*/
@@ -40,8 +40,9 @@ error_t
store_part_create (struct store *source, int index, int flags,
struct store **store)
{
- static struct mutex parted_lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t parted_lock = PTHREAD_MUTEX_INITIALIZER;
static int version_check;
+
error_t err = 0;
PedDevice *dev;
PedDisk *disk;
@@ -54,7 +55,7 @@ store_part_create (struct store *source, int index, int flags,
&& source->block_size % PED_SECTOR_SIZE != 0))
return EINVAL;
- mutex_lock (&parted_lock);
+ pthread_mutex_lock (&parted_lock);
/* Since Parted provides no source-level information about
version compatibility, we have to check at run time. */
@@ -73,7 +74,7 @@ store_part_create (struct store *source, int index, int flags,
if (version_check <= 0)
{
error (0, 0, "the `part' store type is not available");
- mutex_unlock (&parted_lock);
+ pthread_mutex_unlock (&parted_lock);
return ENOTSUP;
}
@@ -149,7 +150,7 @@ out_with_dev:
ped_device_destroy (dev);
out:
ped_exception_leave_all ();
- mutex_unlock (&parted_lock);
+ pthread_mutex_unlock (&parted_lock);
if (! err)
err = store_remap (source, &run, 1, store);
diff --git a/libstore/unzipstore.c b/libstore/unzipstore.c
index 35e9e7af..8d500c1b 100644
--- a/libstore/unzipstore.c
+++ b/libstore/unzipstore.c
@@ -21,7 +21,7 @@
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <sys/mman.h>
#include "store.h"
@@ -29,7 +29,7 @@
#define IN_BUFFERING (256*1024)
#define OUT_BUFFERING (512*1024)
-static struct mutex unzip_lock = MUTEX_INITIALIZER;
+static pthread_mutex_t unzip_lock = PTHREAD_MUTEX_INITIALIZER;
#define STORE_UNZIP(name) STORE_UNZIP_1 (UNZIP, name)
#define STORE_UNZIP_1(unzip,name) STORE_UNZIP_2 (unzip, name)
@@ -182,7 +182,7 @@ unzip_store (struct store *from, void **buf, size_t *buf_len)
if (zerr)
return zerr;
- mutex_lock (&unzip_lock);
+ pthread_mutex_lock (&unzip_lock);
unzip_read = zread;
unzip_write = zwrite;
@@ -195,7 +195,7 @@ unzip_store (struct store *from, void **buf, size_t *buf_len)
zerr = DO_UNZIP ();
}
- mutex_unlock (&unzip_lock);
+ pthread_mutex_unlock (&unzip_lock);
if (in_buf_size > 0)
munmap (in_buf, in_buf_size);
diff --git a/libthreads/Makefile b/libthreads/Makefile
index 3bcff2aa..9c2f9195 100644
--- a/libthreads/Makefile
+++ b/libthreads/Makefile
@@ -19,15 +19,15 @@ makemode := library
# In GNU mig_support.c, sync.c and machine/lock.s are omitted; that work is
# all done in libc.
-SRCS := call.c cprocs.c cthread_data.c cthreads.c stack.c \
- cancel-cond.c rwlock.c lockfile.c
-I386SRCS := i386/csw.S i386/thread.c
+#SRCS := call.c cprocs.c cthread_data.c cthreads.c stack.c \
+# cancel-cond.c rwlock.c lockfile.c
+#I386SRCS := i386/csw.S i386/thread.c
# In GNU machine/cthreads.h is omitted; that work is done in libc headers.
-OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS) $(I386SRCS))))
+#OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS) $(I386SRCS))))
-OTHERTAGS = $(I386SRCS) $(I386HDRS)
+#OTHERTAGS = $(I386SRCS) $(I386HDRS)
libname = libthreads
installhdrs = cthreads.h rwlock.h
@@ -39,10 +39,10 @@ include ../Makeconf
# The threads library was written by CMU. If you've ever experienced
# what that means, you'll understand this line.
-CFLAGS := $(filter-out -Wall,$(CFLAGS))
+#CFLAGS := $(filter-out -Wall,$(CFLAGS))
-ifeq ($(VERSIONING),yes)
+#ifeq ($(VERSIONING),yes)
# Adding this dependency gets it included in the command line,
# where ld will read it as a linker script.
-$(libname).so.$(hurd-version): $(srcdir)/$(libname).map
-endif
+#$(libname).so.$(hurd-version): $(srcdir)/$(libname).map
+#endif
diff --git a/libtreefs/dir-lookup.c b/libtreefs/dir-lookup.c
index 336ce8fd..ce2acafd 100644
--- a/libtreefs/dir-lookup.c
+++ b/libtreefs/dir-lookup.c
@@ -58,13 +58,13 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
/* Set things up in the state expected by the code from gotit: on. */
dir = 0;
node = h->po->node;
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
treefs_node_ref (node);
goto gotit;
}
dir = h->po->node;
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
node = 0;
treefs_node_ref (dir); /* acquire a ref for later node_release */
@@ -147,8 +147,8 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
/* Be very careful not to hold an inode lock while fetching
a translator lock and vice versa. */
- mutex_unlock (&node->lock);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&dir->lock);
do
{
@@ -199,12 +199,12 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
in the right order. */
if (strcmp (path, "..") != 0)
{
- mutex_unlock (&node->lock);
- mutex_lock (&dir->lock);
- mutex_lock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
+ pthread_mutex_lock (&dir->lock);
+ pthread_mutex_lock (&node->lock);
}
else
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
}
if (treefs_node_type (node) == S_IFLNK
diff --git a/libtreefs/fsys-getroot.c b/libtreefs/fsys-getroot.c
index 986938cf..cd735bfe 100644
--- a/libtreefs/fsys-getroot.c
+++ b/libtreefs/fsys-getroot.c
@@ -86,7 +86,7 @@ _treefs_s_fsys_getroot (struct treefs_fsys *fsys,
}
}
- mutex_lock (&root->lock);
+ pthread_mutex_lock (&root->lock);
type = treefs_node_type (root);
if (type == S_IFLNK && !(flags & (O_NOLINK | O_NOTRANS)))
diff --git a/libtreefs/fsys-hooks.c b/libtreefs/fsys-hooks.c
index cb7fcfc6..ecff092b 100644
--- a/libtreefs/fsys-hooks.c
+++ b/libtreefs/fsys-hooks.c
@@ -30,11 +30,11 @@
error_t
_treefs_fsys_get_root (struct treefs_fsys *fsys, struct treefs_node **root)
{
- mutex_lock (&fsys->lock);
+ pthread_mutex_lock (&fsys->lock);
*root = fsys->root;
if (*root != NULL)
treefs_node_ref (*root);
- mutex_unlock (&fsys->lock);
+ pthread_mutex_unlock (&fsys->lock);
return *root ? 0 : EOPNOTSUPP;
}
diff --git a/libtreefs/fsys.c b/libtreefs/fsys.c
index 459d0d3b..d6565bb9 100644
--- a/libtreefs/fsys.c
+++ b/libtreefs/fsys.c
@@ -40,7 +40,7 @@ treefs_create_node (struct treefs_fsys *fsys, struct treefs_node **node)
n->hooks = fsys->hooks;
n->children = NULL;
n->u = NULL;
- mutex_init (&n->lock);
+ pthread_mutex_init (&n->lock, NULL);
fshelp_init_trans_link (&n->active_trans);
fshelp_lock_init (&n->lock_box);
@@ -77,7 +77,7 @@ treefs_create_fsys (struct port_bucket *port_bucket,
if (*fsys == NULL)
return ENOMEM;
- mutex_init (&(*fsys)->lock);
+ pthread_mutex_init (&(*fsys)->lock, NULL);
(*fsys)->root = NULL;
(*fsys)->underlying_port = MACH_PORT_NULL;
diff --git a/libtreefs/trans-help.c b/libtreefs/trans-help.c
index b28e93e1..7d3841c0 100644
--- a/libtreefs/trans-help.c
+++ b/libtreefs/trans-help.c
@@ -40,21 +40,21 @@ treefs_node_get_active_trans (struct treefs_node *node,
/* Fill in dir_port */
void make_dir_port ()
{
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
*dir_port = treefs_node_make_right (dir, 0, parent_port, 0);
mach_port_insert_right (mach_task_self (),
*dir_port, *dir_port, MACH_MSG_TYPE_MAKE_SEND);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
- mutex_lock (&node->active_trans.lock);
+ pthread_mutex_lock (&node->active_trans.lock);
if (node->active_trans.control != MACH_PORT_NULL)
{
mach_port_t control = node->active_trans.control;
mach_port_mod_refs (mach_task_self (), control,
MACH_PORT_RIGHT_SEND, 1);
- mutex_unlock (&node->active_trans.lock);
+ pthread_mutex_unlock (&node->active_trans.lock);
/* Now we have a copy of the translator port that isn't
dependent on the translator lock itself. Relock
@@ -69,12 +69,12 @@ treefs_node_get_active_trans (struct treefs_node *node,
return 0;
}
- mutex_unlock (&node->active_trans.lock);
+ pthread_mutex_unlock (&node->active_trans.lock);
/* If we get here, then we have no active control port.
Check to see if there is a passive translator, and if so
repeat the translator check. */
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
if (!node->istranslated)
{
*control_port = MACH_PORT_NULL;
@@ -89,15 +89,15 @@ treefs_node_get_active_trans (struct treefs_node *node,
}
if (err)
{
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
return err;
}
if (*dir_port == MACH_PORT_NULL)
{
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
make_dir_port ();
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
}
/* Try starting the translator (this unlocks NODE). */
@@ -118,11 +118,11 @@ void
treefs_node_drop_active_trans (struct treefs_node *node,
mach_port_t control_port)
{
- mutex_lock (&node->active_trans.lock);
+ pthread_mutex_lock (&node->active_trans.lock);
/* Only zero the control port if it hasn't changed. */
if (node->active_trans.control == control)
fshelp_translator_drop (&node->active_trans);
- mutex_unlock (&node->active_trans.lock);
+ pthread_mutex_unlock (&node->active_trans.lock);
/* And we're done with this port. */
mach_port_deallocate (mach_task_self (), control_port);
diff --git a/libtreefs/trans-start.c b/libtreefs/trans-start.c
index 2196a8dc..b27c38f4 100644
--- a/libtreefs/trans-start.c
+++ b/libtreefs/trans-start.c
@@ -49,7 +49,7 @@ _treefs_node_start_translator (struct treefs_node *node,
MACH_MSG_TYPE_MAKE_SEND);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
/* XXXX Change libfshelp so that it take more than 1 uid/gid? */
uid = auth->nuids > 0 ? auth->uids[0] : -1;
diff --git a/libtreefs/treefs.h b/libtreefs/treefs.h
index d8f30e4e..0e49ef51 100644
--- a/libtreefs/treefs.h
+++ b/libtreefs/treefs.h
@@ -24,7 +24,7 @@
#define __TREEFS_H__
#include <errno.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <assert.h>
#include <features.h>
@@ -100,7 +100,7 @@ struct treefs_node
char *passive_trans;
struct lock_box user_lock;
- struct mutex lock;
+ pthread_mutex_t lock;
unsigned refs, weak_refs;
/* Node ops */
@@ -123,7 +123,7 @@ struct treefs_node_list
struct treefs_fsys
{
struct port_info pi;
- struct mutex lock;
+ pthread_mutex_t lock;
/* The root node in this filesystem. */
struct treefs_node *root;
@@ -242,7 +242,7 @@ void treefs_hooks_set (treefs_hook_vector_t hooks,
/* ---------------------------------------------------------------- */
/* Reference counting function (largely stolen from diskfs). */
-extern spin_lock_t treefs_node_refcnt_lock;
+extern pthread_spinlock_t treefs_node_refcnt_lock;
extern void treefs_node_ref (struct treefs_node *node);
extern void treefs_node_release (struct treefs_node *node);
@@ -259,15 +259,15 @@ TREEFS_EI void
treefs_node_ref (struct treefs_node *node)
{
int new_ref;
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
node->refs++;
new_ref = (node->refs == 1);
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
if (new_ref)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
treefs_node_new_refs (node);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
}
@@ -280,14 +280,14 @@ treefs_node_release (struct treefs_node *node)
int tried_drop_weak_refs = 0;
loop:
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
assert (node->refs);
node->refs--;
if (node->refs + node->weak_refs == 0)
treefs_node_drop (node);
else if (node->refs == 0 && !tried_drop_weak_refs)
{
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
treefs_node_lost_refs (node);
if (treefs_node_unlinked (node))
{
@@ -297,9 +297,9 @@ treefs_node_release (struct treefs_node *node)
routine, which might result in further recursive calls to
the ref-counting system. So we have to reacquire our
reference around the call to forestall disaster. */
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
node->refs++;
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
treefs_node_try_dropping_weak_refs (node);
@@ -312,8 +312,8 @@ treefs_node_release (struct treefs_node *node)
}
}
else
- spin_unlock (&treefs_node_refcnt_lock);
- mutex_unlock (&node->lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
+ pthread_mutex_unlock (&node->lock);
}
/* Release a hard reference on NODE. If NODE is locked by anyone, then
@@ -327,61 +327,61 @@ treefs_node_unref (struct treefs_node *node)
int tried_drop_weak_refs = 0;
loop:
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
assert (node->refs);
node->refs--;
if (node->refs + node->weak_refs == 0)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
treefs_node_drop (node);
}
else if (node->refs == 0)
{
- mutex_lock (&node->lock);
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_mutex_lock (&node->lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
treefs_node_lost_refs (node);
if (treefs_node_unlinked(node) && !tried_drop_weak_refs)
{
/* Same issue here as in nodeut; see that for explanation */
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
node->refs++;
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
treefs_node_try_dropping_weak_refs (node);
tried_drop_weak_refs = 1;
/* Now we can drop the reference back... */
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
goto loop;
}
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
else
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
}
/* Add a weak reference to a node. */
TREEFS_EI void
treefs_node_ref_weak (struct treefs_node *node)
{
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
node->weak_refs++;
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
}
/* Unlock node NODE and release a weak reference */
TREEFS_EI void
treefs_node_release_weak (struct treefs_node *node)
{
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
assert (node->weak_refs);
node->weak_refs--;
if (node->refs + node->weak_refs == 0)
treefs_node_drop (node);
else
{
- spin_unlock (&treefs_node_refcnt_lock);
- mutex_unlock (&node->lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
+ pthread_mutex_unlock (&node->lock);
}
}
@@ -391,16 +391,16 @@ treefs_node_release_weak (struct treefs_node *node)
TREEFS_EI void
treefs_node_unref_weak (struct treefs_node *node)
{
- spin_lock (&treefs_node_refcnt_lock);
+ pthread_spin_lock (&treefs_node_refcnt_lock);
assert (node->weak_refs);
node->weak_refs--;
if (node->refs + node->weak_refs == 0)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
treefs_node_drop (node);
}
else
- spin_unlock (&treefs_node_refcnt_lock);
+ pthread_spin_unlock (&treefs_node_refcnt_lock);
}
#endif /* Use extern inlines. */
diff --git a/libtrivfs/cntl-create.c b/libtrivfs/cntl-create.c
index f103ed48..910daf3b 100644
--- a/libtrivfs/cntl-create.c
+++ b/libtrivfs/cntl-create.c
@@ -85,7 +85,7 @@ trivfs_create_control (mach_port_t underlying,
}
(*control)->hook = 0;
- mutex_init (&(*control)->lock);
+ pthread_mutex_init (&(*control)->lock, NULL);
}
out:
diff --git a/libtrivfs/dyn-classes.c b/libtrivfs/dyn-classes.c
index 5f73f8f3..a6bb7de1 100644
--- a/libtrivfs/dyn-classes.c
+++ b/libtrivfs/dyn-classes.c
@@ -48,7 +48,8 @@ static struct aux *dynamic_port_buckets_aux = 0;
static size_t dynamic_port_buckets_sz = 0;
/* Lock used to control access to all the above vectors. */
-static struct mutex dyn_lock = MUTEX_INITIALIZER;
+static pthread_mutex_t dyn_lock = PTHREAD_MUTEX_INITIALIZER;
+
/* Add EL to the vector pointed to by VEC_V, which should point to a vector
of pointers of some type, and has a length stored in *SZ; If there's
@@ -74,7 +75,7 @@ add_el (void *el, void (*free_el)(),
if (! el)
return ENOMEM;
- mutex_lock (&dyn_lock);
+ pthread_mutex_lock (&dyn_lock);
vec = vec_v;
@@ -85,13 +86,13 @@ add_el (void *el, void (*free_el)(),
(*aux_vec)[i].free_el = free_el;
(*aux_vec)[i].refs = 1;
(*num)++;
- mutex_unlock (&dyn_lock);
+ pthread_mutex_unlock (&dyn_lock);
return 0;
}
else if ((*vec)[i] == el)
{
(*aux_vec)[i].refs++;
- mutex_unlock (&dyn_lock);
+ pthread_mutex_unlock (&dyn_lock);
return 0;
}
@@ -119,7 +120,7 @@ add_el (void *el, void (*free_el)(),
*aux_vec = new_aux_vec;
*sz = new_sz;
- mutex_unlock (&dyn_lock);
+ pthread_mutex_unlock (&dyn_lock);
return 0;
}
@@ -138,7 +139,7 @@ drop_el (void *el, void *vec_v, struct aux *aux_vec,
if (! el)
return;
- mutex_lock (&dyn_lock);
+ pthread_mutex_lock (&dyn_lock);
vec = vec_v;
@@ -157,7 +158,7 @@ drop_el (void *el, void *vec_v, struct aux *aux_vec,
break;
}
- mutex_unlock (&dyn_lock);
+ pthread_mutex_unlock (&dyn_lock);
}
/* Add the port class *CLASS to the list of control port classes recognized
diff --git a/libtrivfs/io-reauthenticate.c b/libtrivfs/io-reauthenticate.c
index 80ef31c1..6623d947 100644
--- a/libtrivfs/io-reauthenticate.c
+++ b/libtrivfs/io-reauthenticate.c
@@ -62,10 +62,10 @@ trivfs_S_io_reauthenticate (struct trivfs_protid *cred,
newcred->hook = cred->hook;
- mutex_lock (&cred->po->cntl->lock);
+ pthread_mutex_lock (&cred->po->cntl->lock);
newcred->po = cred->po;
newcred->po->refcnt++;
- mutex_unlock (&cred->po->cntl->lock);
+ pthread_mutex_unlock (&cred->po->cntl->lock);
do
err = io_restrict_auth (newcred->po->cntl->underlying, &newcred->realnode,
diff --git a/libtrivfs/io-restrict-auth.c b/libtrivfs/io-restrict-auth.c
index 98a80a13..61c07725 100644
--- a/libtrivfs/io-restrict-auth.c
+++ b/libtrivfs/io-restrict-auth.c
@@ -109,10 +109,10 @@ trivfs_S_io_restrict_auth (struct trivfs_protid *cred,
}
newcred->isroot = 0;
- mutex_lock (&cred->po->cntl->lock);
+ pthread_mutex_lock (&cred->po->cntl->lock);
newcred->po = cred->po;
newcred->po->refcnt++;
- mutex_unlock (&cred->po->cntl->lock);
+ pthread_mutex_unlock (&cred->po->cntl->lock);
if (cred->isroot && idvec_contains (user->uids, 0))
newcred->isroot = 1;
newcred->user = user;
diff --git a/libtrivfs/protid-clean.c b/libtrivfs/protid-clean.c
index b76b202e..856d7af5 100644
--- a/libtrivfs/protid-clean.c
+++ b/libtrivfs/protid-clean.c
@@ -30,19 +30,19 @@ trivfs_clean_protid (void *arg)
(*trivfs_protid_destroy_hook) (cred);
/* If we hold the only reference to the peropen, try to get rid of it. */
- mutex_lock (&cred->po->cntl->lock);
+ pthread_mutex_lock (&cred->po->cntl->lock);
if (cred->po->refcnt == 1 && trivfs_peropen_destroy_hook)
{
- mutex_unlock (&cred->po->cntl->lock);
+ pthread_mutex_unlock (&cred->po->cntl->lock);
(*trivfs_peropen_destroy_hook) (cred->po);
- mutex_lock (&cred->po->cntl->lock);
+ pthread_mutex_lock (&cred->po->cntl->lock);
}
if (--cred->po->refcnt == 0)
{
ports_port_deref (cred->po->cntl);
free (cred->po);
}
- mutex_unlock (&cred->po->cntl->lock);
+ pthread_mutex_unlock (&cred->po->cntl->lock);
iohelp_free_iouser (cred->user);
diff --git a/libtrivfs/protid-dup.c b/libtrivfs/protid-dup.c
index 855cd062..61696032 100644
--- a/libtrivfs/protid-dup.c
+++ b/libtrivfs/protid-dup.c
@@ -35,10 +35,10 @@ trivfs_protid_dup (struct trivfs_protid *cred, struct trivfs_protid **dup)
if (! err)
{
- mutex_lock (&cred->po->cntl->lock);
+ pthread_mutex_lock (&cred->po->cntl->lock);
new->po = cred->po;
new->po->refcnt++;
- mutex_unlock (&cred->po->cntl->lock);
+ pthread_mutex_unlock (&cred->po->cntl->lock);
new->isroot = cred->isroot;
diff --git a/libtrivfs/trivfs.h b/libtrivfs/trivfs.h
index 798e0b38..33b04363 100644
--- a/libtrivfs/trivfs.h
+++ b/libtrivfs/trivfs.h
@@ -19,7 +19,7 @@
#define __TRIVFS_H__
#include <errno.h>
-#include <cthreads.h> /* for mutexes &c */
+#include <pthread.h> /* for mutexes &c */
#include <sys/types.h> /* for uid_t &c */
#include <mach/mach.h>
#include <hurd/ports.h>
@@ -53,7 +53,7 @@ struct trivfs_peropen
struct trivfs_control
{
struct port_info pi;
- struct mutex lock;
+ pthread_mutex_t lock;
struct port_class *protid_class;
struct port_bucket *protid_bucket;
mach_port_t filesys_id;
diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile
index b16aa80d..5a98d690 100644
--- a/mach-defpager/Makefile
+++ b/mach-defpager/Makefile
@@ -29,7 +29,7 @@ OBJS := $(SRCS:.c=.o) \
memory_object default_pager memory_object_default exc) \
default_pager_replyUser.o
-HURDLIBS:= threads
+OTHERLIBS:= -lpthread
LDFLAGS += -static
include ../Makeconf
diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c
index b467cbce..ec875d4f 100644
--- a/mach-defpager/default_pager.c
+++ b/mach-defpager/default_pager.c
@@ -37,7 +37,7 @@
#include <mach/task_info.h>
#include <mach/default_pager_types.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <device/device_types.h>
#include <device/device.h>
@@ -59,18 +59,24 @@
static char my_name[] = "(default pager):";
-static struct mutex printf_lock = MUTEX_INITIALIZER;
+static pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER;
#if 0
-#define dprintf(f, x...) \
- ({ mutex_lock (&printf_lock); printf (f , ##x); fflush (stdout); mutex_unlock (&printf_lock); })
+#define dprintf(f, x...) \
+ ({ pthread_mutex_lock (&printf_lock); \
+ printf (f , ##x); \
+ fflush (stdout); \
+ pthread_mutex_unlock (&printf_lock); })
#else
#define dprintf(f, x...)
#endif
#if 0
-#define ddprintf(f, x...) \
- ({ mutex_lock (&printf_lock); printf (f , ##x); fflush (stdout); mutex_unlock (&printf_lock); })
+#define ddprintf(f, x...) \
+ ({ pthread_mutex_lock (&printf_lock); \
+ printf (f , ##x); \
+ fflush (stdout); \
+ pthread_mutex_unlock (&printf_lock); })
#else
#define ddprintf(f, x...)
#endif
@@ -111,7 +117,7 @@ typedef unsigned int bm_entry_t;
* Controls allocation of blocks within paging area.
*/
struct part {
- struct mutex p_lock; /* for bitmap/free */
+ pthread_mutex_t p_lock; /* for bitmap/free */
vm_size_t total_size; /* total number of blocks */
vm_size_t free; /* number of blocks free */
unsigned int id; /* named lookup */
@@ -122,7 +128,7 @@ struct part {
typedef struct part *partition_t;
struct {
- struct mutex lock;
+ pthread_mutex_t lock;
int n_partitions;
partition_t *partition_list;/* array, for quick mapping */
} all_partitions; /* list of all such */
@@ -172,7 +178,7 @@ part_id(const char *name)
void
partition_init()
{
- mutex_init(&all_partitions.lock);
+ pthread_mutex_init(&all_partitions.lock, NULL);
all_partitions.n_partitions = 0;
}
@@ -187,7 +193,7 @@ new_partition (const char *name, struct file_direct *fdp,
int rc;
unsigned int id = part_id(name);
- mutex_lock(&all_partitions.lock);
+ pthread_mutex_lock(&all_partitions.lock);
{
unsigned int i;
for (i = 0; i < all_partitions.n_partitions; i++)
@@ -197,18 +203,18 @@ new_partition (const char *name, struct file_direct *fdp,
{
printf ("(default pager): Already paging to partition %s!\n",
name);
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
return 0;
}
}
}
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
size = atop(fdp->fd_size * fdp->fd_bsize);
bmsize = howmany(size, NB_BM) * sizeof(bm_entry_t);
part = (partition_t) kalloc(sizeof(struct part));
- mutex_init(&part->p_lock);
+ pthread_mutex_init(&part->p_lock, NULL);
part->total_size = size;
part->free = size;
part->id = id;
@@ -436,7 +442,7 @@ create_paging_partition(const char *name,
if (!part)
return;
- mutex_lock(&all_partitions.lock);
+ pthread_mutex_lock(&all_partitions.lock);
{
register int i;
@@ -462,7 +468,7 @@ create_paging_partition(const char *name,
}
set_partition_of(i, part);
}
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
#if 0
dprintf("%s Added paging %s %s\n", my_name,
@@ -486,7 +492,7 @@ choose_partition(size, cur_part)
register boolean_t found = FALSE;
register int i;
- mutex_lock(&all_partitions.lock);
+ pthread_mutex_lock(&all_partitions.lock);
for (i = 0; i < all_partitions.n_partitions; i++) {
/* the undesirable one ? */
@@ -503,19 +509,19 @@ ddprintf ("choose_partition(%x,%d,%d)\n",size,cur_part,i);
continue;
/* is it big enough ? */
- mutex_lock(&part->p_lock);
+ pthread_mutex_lock(&part->p_lock);
if (ptoa(part->free) >= size) {
if (cur_part != P_INDEX_INVALID) {
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
return (p_index_t)i;
} else
found = TRUE;
}
- mutex_unlock(&part->p_lock);
+ pthread_mutex_unlock(&part->p_lock);
if (found) break;
}
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
return (found) ? (p_index_t)i : P_INDEX_INVALID;
}
@@ -545,11 +551,11 @@ ddprintf ("pager_alloc_page(%d,%d)\n",pindex,lock_it);
return (NO_BLOCK);
if (lock_it)
- mutex_lock(&part->p_lock);
+ pthread_mutex_lock(&part->p_lock);
if (part->free == 0) {
/* out of paging space */
- mutex_unlock(&part->p_lock);
+ pthread_mutex_unlock(&part->p_lock);
return (NO_BLOCK);
}
@@ -579,7 +585,7 @@ ddprintf ("pager_alloc_page(%d,%d)\n",pindex,lock_it);
}
- mutex_unlock(&part->p_lock);
+ pthread_mutex_unlock(&part->p_lock);
return (bm_e*NB_BM+bit);
}
@@ -609,13 +615,13 @@ ddprintf ("pager_dealloc_page(%d,%x,%d)\n",pindex,page,lock_it);
bit = page % NB_BM;
if (lock_it)
- mutex_lock(&part->p_lock);
+ pthread_mutex_lock(&part->p_lock);
part->bitmap[bm_e] &= ~(1<<bit);
part->free++;
if (lock_it)
- mutex_unlock(&part->p_lock);
+ pthread_mutex_unlock(&part->p_lock);
}
/*
@@ -659,7 +665,7 @@ typedef union dp_map *dp_map_t;
#define invalidate_block(e) ((e).indirect = (dp_map_t)NO_BLOCK)
struct dpager {
- struct mutex lock; /* lock for extending block map */
+ pthread_mutex_t lock; /* lock for extending block map */
/* XXX should be read-write lock */
#if DEBUG_READER_CONFLICTS
int readers;
@@ -751,7 +757,7 @@ pager_alloc(pager, part, size)
register int i;
register dp_map_t mapptr, emapptr;
- mutex_init(&pager->lock);
+ pthread_mutex_init(&pager->lock, NULL);
#if DEBUG_READER_CONFLICTS
pager->readers = 0;
pager->writer = FALSE;
@@ -900,7 +906,7 @@ pager_extend(pager, new_size)
register int i;
register vm_size_t old_size;
- mutex_lock(&pager->lock); /* XXX lock_write */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_write */
#if DEBUG_READER_CONFLICTS
pager->writer = TRUE;
#endif
@@ -948,7 +954,7 @@ pager_extend(pager, new_size)
#if DEBUG_READER_CONFLICTS
pager->writer = FALSE;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
#if 0
ddprintf ("pager_extend 1 mapptr %x [3b] = %x\n", new_mapptr,
new_mapptr[0x3b]);
@@ -1023,7 +1029,7 @@ pager_extend(pager, new_size)
#if DEBUG_READER_CONFLICTS
pager->writer = FALSE;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
return;
}
/*
@@ -1052,7 +1058,7 @@ pager_extend(pager, new_size)
#if DEBUG_READER_CONFLICTS
pager->writer = FALSE;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
}
/* Truncate a memory object. First, any pages between the new size
@@ -1091,7 +1097,7 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */
}
}
- mutex_lock(&pager->lock); /* XXX lock_write */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_write */
if (!pager->map)
goto done;
@@ -1152,7 +1158,7 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */
done:
pager->size = new_size;
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
#ifdef CHECKSUM
#error write me
@@ -1180,7 +1186,7 @@ pager_read_offset(pager, offset)
default_pager_read_conflicts++; /* would have proceeded with
read/write lock */
#endif
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
#if DEBUG_READER_CONFLICTS
pager->readers++;
#endif
@@ -1188,7 +1194,7 @@ pager_read_offset(pager, offset)
{
ddprintf ("%spager_read_offset pager %x: bad page %d >= size %d",
my_name, pager, f_page, pager->size);
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
return (union dp_map) (union dp_map *) NO_BLOCK;
#if 0
panic("%spager_read_offset",my_name);
@@ -1213,7 +1219,7 @@ pager_read_offset(pager, offset)
#if DEBUG_READER_CONFLICTS
pager->readers--;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
return (pager_offset);
}
@@ -1229,7 +1235,7 @@ void pager_release_offset(pager, offset)
offset = atop(offset);
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
assert (pager->map);
if (INDIRECT_PAGEMAP(pager->size)) {
@@ -1243,7 +1249,7 @@ void pager_release_offset(pager, offset)
invalidate_block(pager->map[offset]);
}
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
pager_dealloc_page(entry.block.p_index, entry.block.p_offset, TRUE);
}
@@ -1329,7 +1335,7 @@ pager_get_checksum(pager, offset)
f_page = atop(offset);
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
if (f_page >= pager->size)
panic("%spager_get_checksum",my_name);
@@ -1346,7 +1352,7 @@ pager_get_checksum(pager, offset)
checksum = pager->checksum[f_page];
}
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
return (checksum);
}
@@ -1364,7 +1370,7 @@ pager_put_checksum(pager, offset, checksum)
f_page = atop(offset);
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
if (f_page >= pager->size)
panic(here,my_name);
@@ -1380,7 +1386,7 @@ pager_put_checksum(pager, offset, checksum)
else {
pager->checksum[f_page] = checksum;
}
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
}
/*
@@ -1431,7 +1437,7 @@ pager_write_offset(pager, offset)
default_pager_read_conflicts++; /* would have proceeded with
read/write lock */
#endif
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
#if DEBUG_READER_CONFLICTS
pager->readers++;
#endif
@@ -1463,14 +1469,14 @@ pager_write_offset(pager, offset)
#if DEBUG_READER_CONFLICTS
pager->readers--;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
pager_extend(pager, f_page + 1);
#if DEBUG_READER_CONFLICTS
if (pager->readers > 0)
default_pager_read_conflicts++; /* would have proceeded with
read/write lock */
#endif
- mutex_lock(&pager->lock); /* XXX lock_read */
+ pthread_mutex_lock(&pager->lock); /* XXX lock_read */
#if DEBUG_READER_CONFLICTS
pager->readers++;
#endif
@@ -1573,7 +1579,7 @@ out:
#if DEBUG_READER_CONFLICTS
pager->readers--;
#endif
- mutex_unlock(&pager->lock);
+ pthread_mutex_unlock(&pager->lock);
return (block);
}
@@ -1886,8 +1892,8 @@ default_has_page(ds, offset)
struct dstruct {
queue_chain_t links; /* Link in pager-port list */
- struct mutex lock; /* Lock for the structure */
- struct condition
+ pthread_mutex_t lock; /* Lock for the structure */
+ pthread_cond_t
waiting_seqno, /* someone waiting on seqno */
waiting_read, /* someone waiting on readers */
waiting_write, /* someone waiting on writers */
@@ -1915,9 +1921,9 @@ typedef struct dstruct * default_pager_t;
#define DEFAULT_PAGER_NULL ((default_pager_t)0)
#if PARALLEL
-#define dstruct_lock_init(ds) mutex_init(&ds->lock)
-#define dstruct_lock(ds) mutex_lock(&ds->lock)
-#define dstruct_unlock(ds) mutex_unlock(&ds->lock)
+#define dstruct_lock_init(ds) pthread_mutex_init(&ds->lock, NULL)
+#define dstruct_lock(ds) pthread_mutex_lock(&ds->lock)
+#define dstruct_unlock(ds) pthread_mutex_unlock(&ds->lock)
#else /* PARALLEL */
#define dstruct_lock_init(ds)
#define dstruct_lock(ds)
@@ -1932,14 +1938,14 @@ typedef struct dstruct * default_pager_t;
*/
struct pager_port {
queue_head_t queue;
- struct mutex lock;
+ pthread_mutex_t lock;
int count; /* saves code */
queue_head_t leak_queue;
} all_pagers;
#define pager_port_list_init() \
{ \
- mutex_init(&all_pagers.lock); \
+ pthread_mutex_init(&all_pagers.lock, NULL); \
queue_init(&all_pagers.queue); \
queue_init(&all_pagers.leak_queue); \
all_pagers.count = 0; \
@@ -1949,10 +1955,10 @@ void pager_port_list_insert(port, ds)
mach_port_t port;
default_pager_t ds;
{
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_enter(&all_pagers.queue, ds, default_pager_t, links);
all_pagers.count++;
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
}
/* given a data structure return a good port-name to associate it to */
@@ -1969,10 +1975,10 @@ void pager_port_list_insert(port, ds)
void pager_port_list_delete(ds)
default_pager_t ds;
{
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_remove(&all_pagers.queue, ds, default_pager_t, links);
all_pagers.count--;
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
}
/*
@@ -1995,17 +2001,17 @@ destroy_paging_partition(name, pp_private)
* This prevents choose_partition from
* getting in the way.
*/
- mutex_lock(&all_partitions.lock);
+ pthread_mutex_lock(&all_partitions.lock);
for (pindex = 0; pindex < all_partitions.n_partitions; pindex++) {
part = partition_of(pindex);
if (part && (part->id == id)) break;
}
if (pindex == all_partitions.n_partitions) {
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
return KERN_INVALID_ARGUMENT;
}
part->going_away = TRUE;
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
/*
* This might take a while..
@@ -2015,18 +2021,18 @@ all_over_again:
dprintf("Partition x%x (id x%x) for %s, all_ok %d\n", part, id, name, all_ok);
#endif
all_ok = TRUE;
- mutex_lock(&part->p_lock);
+ pthread_mutex_lock(&part->p_lock);
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
dstruct_lock(entry);
- if (!mutex_try_lock(&entry->dpager.lock)) {
+ if (pthread_mutex_trylock(&entry->dpager.lock)) {
dstruct_unlock(entry);
- mutex_unlock(&all_pagers.lock);
- mutex_unlock(&part->p_lock);
+ pthread_mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&part->p_lock);
/* yield the processor */
(void) thread_switch(MACH_PORT_NULL,
@@ -2042,13 +2048,13 @@ dprintf("Partition x%x (id x%x) for %s, all_ok %d\n", part, id, name, all_ok);
*/
all_ok = pager_realloc(&entry->dpager, pindex);
- mutex_unlock(&entry->dpager.lock);
+ pthread_mutex_unlock(&entry->dpager.lock);
dstruct_unlock(entry);
if (!all_ok) break;
}
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
if (all_ok) {
/* No need to unlock partition, there are no refs left */
@@ -2098,7 +2104,7 @@ void pager_port_lock(ds, seqno)
dstruct_lock(ds);
while (ds->seqno != seqno) {
default_pager_wait_seqno++;
- condition_wait(&ds->waiting_seqno, &ds->lock);
+ pthread_cond_wait(&ds->waiting_seqno, &ds->lock);
}
}
@@ -2110,7 +2116,7 @@ void pager_port_unlock(ds)
{
ds->seqno++;
dstruct_unlock(ds);
- condition_broadcast(&ds->waiting_seqno);
+ pthread_cond_broadcast(&ds->waiting_seqno);
}
/*
@@ -2130,7 +2136,7 @@ void pager_port_wait_for_readers(ds)
{
while (ds->readers != 0) {
default_pager_wait_read++;
- condition_wait(&ds->waiting_read, &ds->lock);
+ pthread_cond_wait(&ds->waiting_read, &ds->lock);
}
}
@@ -2143,7 +2149,7 @@ void pager_port_finish_read(ds)
dstruct_lock(ds);
if (--ds->readers == 0) {
dstruct_unlock(ds);
- condition_broadcast(&ds->waiting_read);
+ pthread_cond_broadcast(&ds->waiting_read);
}
else {
dstruct_unlock(ds);
@@ -2167,7 +2173,7 @@ void pager_port_wait_for_writers(ds)
{
while (ds->writers != 0) {
default_pager_wait_write++;
- condition_wait(&ds->waiting_write, &ds->lock);
+ pthread_cond_wait(&ds->waiting_write, &ds->lock);
}
}
@@ -2180,7 +2186,7 @@ void pager_port_finish_write(ds)
dstruct_lock(ds);
if (--ds->writers == 0) {
dstruct_unlock(ds);
- condition_broadcast(&ds->waiting_write);
+ pthread_cond_broadcast(&ds->waiting_write);
}
else {
dstruct_unlock(ds);
@@ -2196,7 +2202,7 @@ void pager_port_wait_for_refs(ds)
{
while (ds->name_refs == 0) {
default_pager_wait_refs++;
- condition_wait(&ds->waiting_refs, &ds->lock);
+ pthread_cond_wait(&ds->waiting_refs, &ds->lock);
}
}
@@ -2206,7 +2212,7 @@ void pager_port_wait_for_refs(ds)
void pager_port_finish_refs(ds)
default_pager_t ds;
{
- condition_broadcast(&ds->waiting_refs);
+ pthread_cond_broadcast(&ds->waiting_refs);
}
#else /* PARALLEL */
@@ -2239,7 +2245,7 @@ mach_port_t default_pager_external_set; /* Port set for external objects. */
mach_port_t default_pager_default_set; /* Port set for "default" thread. */
typedef struct default_pager_thread {
- cthread_t dpt_thread; /* Server thread. */
+ pthread_t dpt_thread; /* Server thread. */
vm_offset_t dpt_buffer; /* Read buffer. */
boolean_t dpt_internal; /* Do we handle internal objects? */
} default_pager_thread_t;
@@ -2410,9 +2416,9 @@ rename_it:
panic("%s m_o_create", my_name);
ds1 = (default_pager_t) kalloc(sizeof *ds1);
*ds1 = *ds;
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_enter(&all_pagers.leak_queue, ds, default_pager_t, links);
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
ds = ds1;
goto rename_it;
}
@@ -2620,7 +2626,7 @@ void default_pager_no_senders(pager, seqno, mscount)
* Recover memory that we might have wasted because
* of name conflicts
*/
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
while (!queue_empty(&all_pagers.leak_queue)) {
@@ -2629,12 +2635,14 @@ void default_pager_no_senders(pager, seqno, mscount)
kfree((char *) ds, sizeof(*ds));
}
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
}
int default_pager_pagein_count = 0;
int default_pager_pageout_count = 0;
+static __thread default_pager_thread_t *dpt;
+
kern_return_t
seqnos_memory_object_data_request(pager, seqno, reply_to, offset,
length, protection_required)
@@ -2645,15 +2653,12 @@ seqnos_memory_object_data_request(pager, seqno, reply_to, offset,
vm_size_t length;
vm_prot_t protection_required;
{
- default_pager_thread_t *dpt;
default_pager_t ds;
vm_offset_t addr;
unsigned int errors;
kern_return_t rc;
static char here[] = "%sdata_request";
- dpt = (default_pager_thread_t *) cthread_data(cthread_self());
-
if (length != vm_page_size)
panic(here,my_name);
@@ -3103,14 +3108,12 @@ default_pager_thread_privileges()
/*
* Set thread privileges.
*/
- cthread_wire(); /* attach kernel thread to cthread */
wire_thread(); /* grab a kernel stack and memory allocation
privileges */
}
-any_t
-default_pager_default_thread (arg)
- any_t arg;
+void *
+default_pager_default_thread(void *arg)
{
kern_return_t kr;
default_pager_thread_privileges ();
@@ -3124,16 +3127,13 @@ default_pager_default_thread (arg)
-any_t
-default_pager_thread(arg)
- any_t arg;
+void *
+default_pager_thread(void *arg)
{
- default_pager_thread_t *dpt = (default_pager_thread_t *) arg;
mach_port_t pset;
kern_return_t kr;
- cthread_set_data(cthread_self(), (any_t) dpt);
-
+ dpt = (default_pager_thread_t *) arg;
/*
* Threads handling external objects cannot have
@@ -3162,23 +3162,31 @@ void
start_default_pager_thread(internal)
boolean_t internal;
{
- default_pager_thread_t *dpt;
+ default_pager_thread_t *ndpt;
kern_return_t kr;
+ error_t err;
- dpt = (default_pager_thread_t *) kalloc(sizeof *dpt);
- if (dpt == 0)
+ ndpt = (default_pager_thread_t *) kalloc(sizeof *ndpt);
+ if (ndpt == 0)
panic(my_name);
- dpt->dpt_internal = internal;
+ ndpt->dpt_internal = internal;
- kr = vm_allocate(default_pager_self, &dpt->dpt_buffer,
+ kr = vm_allocate(default_pager_self, &ndpt->dpt_buffer,
vm_page_size, TRUE);
if (kr != KERN_SUCCESS)
panic(my_name);
- wire_memory(dpt->dpt_buffer, vm_page_size,
+ wire_memory(ndpt->dpt_buffer, vm_page_size,
VM_PROT_READ|VM_PROT_WRITE);
- dpt->dpt_thread = cthread_fork(default_pager_thread, (any_t) dpt);
+ err = pthread_create(&ndpt->dpt_thread, NULL, default_pager_thread,
+ ndpt);
+ if (!err)
+ pthread_detach (ndpt->dpt_thread);
+ else {
+ errno = err;
+ perror ("pthread_create");
+ }
}
void
@@ -3335,9 +3343,9 @@ rename_it:
ds1 = (default_pager_t) kalloc(sizeof *ds1);
*ds1 = *ds;
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_enter(&all_pagers.leak_queue, ds, default_pager_t, links);
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
ds = ds1;
goto rename_it;
}
@@ -3365,9 +3373,9 @@ S_default_pager_info (mach_port_t pager,
if (pager != default_pager_default_port)
return KERN_INVALID_ARGUMENT;
- mutex_lock(&all_partitions.lock);
+ pthread_mutex_lock(&all_partitions.lock);
paging_space_info(&total, &free);
- mutex_unlock(&all_partitions.lock);
+ pthread_mutex_unlock(&all_partitions.lock);
infop->dpi_total_space = ptoa(total);
infop->dpi_free_space = ptoa(free);
@@ -3410,12 +3418,12 @@ S_default_pager_objects (mach_port_t pager,
ports = *portsp;
ppotential = *pcountp;
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
/*
* We will send no more than this many
*/
actual = all_pagers.count;
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
if (opotential < actual) {
vm_offset_t newaddr;
@@ -3453,7 +3461,7 @@ S_default_pager_objects (mach_port_t pager,
* Now scan the list.
*/
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
num_pagers = 0;
queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
@@ -3474,10 +3482,10 @@ S_default_pager_objects (mach_port_t pager,
/*
* Avoid interfering with normal operations
*/
- if (!mutex_try_lock(&entry->dpager.lock))
+ if (pthread_mutex_trylock(&entry->dpager.lock))
goto not_this_one;
size = pager_allocated(&entry->dpager);
- mutex_unlock(&entry->dpager.lock);
+ pthread_mutex_unlock(&entry->dpager.lock);
dstruct_lock(entry);
@@ -3533,7 +3541,7 @@ not_this_one:
}
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
/*
* Deallocate and clear unused memory.
@@ -3633,16 +3641,16 @@ S_default_pager_object_pages (mach_port_t pager,
for (;;) {
default_pager_t entry;
- mutex_lock(&all_pagers.lock);
+ pthread_mutex_lock(&all_pagers.lock);
queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
dstruct_lock(entry);
if (entry->pager_name == object) {
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
goto found_object;
}
dstruct_unlock(entry);
}
- mutex_unlock(&all_pagers.lock);
+ pthread_mutex_unlock(&all_pagers.lock);
/* did not find the object */
@@ -3652,7 +3660,7 @@ S_default_pager_object_pages (mach_port_t pager,
found_object:
- if (!mutex_try_lock(&entry->dpager.lock)) {
+ if (pthread_mutex_trylock(&entry->dpager.lock)) {
/* oh well bad luck */
dstruct_unlock(entry);
@@ -3664,7 +3672,7 @@ S_default_pager_object_pages (mach_port_t pager,
}
actual = pager_pages(&entry->dpager, pages, potential);
- mutex_unlock(&entry->dpager.lock);
+ pthread_mutex_unlock(&entry->dpager.lock);
dstruct_unlock(entry);
if (actual <= potential)
diff --git a/mach-defpager/kalloc.c b/mach-defpager/kalloc.c
index d9b18c02..8efb85f9 100644
--- a/mach-defpager/kalloc.c
+++ b/mach-defpager/kalloc.c
@@ -33,7 +33,7 @@
*/
#include <mach.h>
-#include <cthreads.h> /* for spin locks */
+#include <pthread.h> /* for spin locks */
#include <malloc.h> /* for malloc_hook/free_hook */
#include "wiring.h"
@@ -61,10 +61,10 @@ vm_size_t kalloc_max; /* max before we use vm_allocate */
#define MINSIZE 4 /* minimum allocation size */
struct free_list {
- spin_lock_t lock;
- vm_offset_t head; /* head of free list */
+ pthread_spinlock_t lock;
+ vm_offset_t head; /* head of free list */
#ifdef DEBUG
- int count;
+ int count;
#endif /*DEBUG*/
};
@@ -74,7 +74,7 @@ struct free_list {
2048, 4096, 8192, 16384 */
struct free_list kfree_list[KLIST_MAX];
-spin_lock_t kget_space_lock;
+pthread_spinlock_t kget_space_lock;
vm_offset_t kalloc_next_space = 0;
vm_offset_t kalloc_end_of_space = 0;
@@ -107,10 +107,10 @@ void kalloc_init(void)
kalloc_max = vm_page_size;
for (i = 0; i < KLIST_MAX; i++) {
- spin_lock_init(&kfree_list[i].lock);
+ pthread_spin_init(&kfree_list[i].lock, PTHREAD_PROCESS_PRIVATE);
kfree_list[i].head = 0;
}
- spin_lock_init(&kget_space_lock);
+ pthread_spin_init(&kget_space_lock, PTHREAD_PROCESS_PRIVATE);
/*
* Do not allocate memory at address 0.
@@ -128,7 +128,7 @@ vm_offset_t kget_space(vm_offset_t size)
vm_offset_t new_space = 0;
vm_offset_t addr;
- spin_lock(&kget_space_lock);
+ pthread_spin_lock(&kget_space_lock);
while (kalloc_next_space + size > kalloc_end_of_space) {
/*
* Add at least one page to allocation area.
@@ -141,7 +141,7 @@ vm_offset_t kget_space(vm_offset_t size)
* Try to make it contiguous with the last
* allocation area.
*/
- spin_unlock(&kget_space_lock);
+ pthread_spin_unlock(&kget_space_lock);
new_space = kalloc_end_of_space;
if (vm_map(mach_task_self(),
@@ -152,7 +152,7 @@ vm_offset_t kget_space(vm_offset_t size)
return 0;
wire_memory(new_space, space_to_add,
VM_PROT_READ|VM_PROT_WRITE);
- spin_lock(&kget_space_lock);
+ pthread_spin_lock(&kget_space_lock);
continue;
}
@@ -177,7 +177,7 @@ vm_offset_t kget_space(vm_offset_t size)
addr = kalloc_next_space;
kalloc_next_space += size;
- spin_unlock(&kget_space_lock);
+ pthread_spin_unlock(&kget_space_lock);
if (new_space != 0)
(void) vm_deallocate(mach_task_self(), new_space, space_to_add);
@@ -214,16 +214,16 @@ void *kalloc(vm_size_t size)
*/
if (allocsize < kalloc_max) {
- spin_lock(&fl->lock);
+ pthread_spin_lock(&fl->lock);
if ((addr = fl->head) != 0) {
fl->head = *(vm_offset_t *)addr;
#ifdef DEBUG
fl->count--;
#endif
- spin_unlock(&fl->lock);
+ pthread_spin_unlock(&fl->lock);
}
else {
- spin_unlock(&fl->lock);
+ pthread_spin_unlock(&fl->lock);
addr = kget_space(allocsize);
}
}
@@ -253,13 +253,13 @@ kfree( void *data,
}
if (freesize < kalloc_max) {
- spin_lock(&fl->lock);
+ pthread_spin_lock(&fl->lock);
*(vm_offset_t *)data = fl->head;
fl->head = (vm_offset_t) data;
#ifdef DEBUG
fl->count++;
#endif
- spin_unlock(&fl->lock);
+ pthread_spin_unlock(&fl->lock);
}
else {
(void) vm_deallocate(mach_task_self(), (vm_offset_t)data, freesize);
diff --git a/mach-defpager/main.c b/mach-defpager/main.c
index c44c86cb..3134d6f3 100644
--- a/mach-defpager/main.c
+++ b/mach-defpager/main.c
@@ -21,7 +21,7 @@
#include <mach.h>
#include <hurd.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <device/device.h>
#include <device/device_types.h>
@@ -45,9 +45,6 @@
#include <default_pager.h>
-extern
-vm_size_t cthread_wait_stack_size;
-
mach_port_t bootstrap_master_device_port; /* local name */
mach_port_t bootstrap_master_host_port; /* local name */
@@ -87,11 +84,6 @@ main (int argc, char **argv)
error_t err;
memory_object_t defpager;
- /*
- * Use 4Kbyte cthread wait stacks.
- */
- cthread_wait_stack_size = 4 * 1024;
-
err = get_privileged_ports (&bootstrap_master_host_port,
&bootstrap_master_device_port);
if (err)
diff --git a/nfs/Makefile b/nfs/Makefile
index 86b10899..d814f67d 100644
--- a/nfs/Makefile
+++ b/nfs/Makefile
@@ -26,6 +26,7 @@ target = nfs
SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c \
storage-info.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = netfs fshelp iohelp threads ports ihash shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/nfs/cache.c b/nfs/cache.c
index 8f87f5d0..6e932573 100644
--- a/nfs/cache.c
+++ b/nfs/cache.c
@@ -21,6 +21,7 @@
#include "nfs.h"
#include <string.h>
+#include <stdio.h>
#include <netinet/in.h>
/* Hash table containing all the nodes currently active. XXX Was 512,
@@ -59,7 +60,7 @@ lookup_fhandle (void *p, size_t len, struct node **npp)
h = hash (p, len);
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
for (np = nodehash[h]; np; np = np->nn->hnext)
{
if (np->nn->handle.size != len
@@ -67,8 +68,8 @@ lookup_fhandle (void *p, size_t len, struct node **npp)
continue;
np->references++;
- spin_unlock (&netfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return;
}
@@ -85,14 +86,14 @@ lookup_fhandle (void *p, size_t len, struct node **npp)
nn->dead_name = 0;
np = netfs_make_node (nn);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
nn->hnext = nodehash[h];
if (nn->hnext)
nn->hnext->nn->hprevp = &nn->hnext;
nn->hprevp = &nodehash[h];
nodehash[h] = np;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
*npp = np;
}
@@ -106,12 +107,12 @@ struct fnd
/* Worker function to delete nodes that don't have any more local
references or links. */
-any_t
-forked_node_delete (any_t arg)
+void *
+forked_node_delete (void *arg)
{
struct fnd *args = arg;
- mutex_lock (&args->dir->lock);
+ pthread_mutex_lock (&args->dir->lock);
netfs_attempt_unlink ((struct iouser *)-1, args->dir, args->name);
netfs_nput (args->dir);
free (args->name);
@@ -129,12 +130,14 @@ netfs_node_norefs (struct node *np)
if (np->nn->dead_dir)
{
struct fnd *args;
+ pthread_t thread;
+ error_t err;
args = malloc (sizeof (struct fnd));
assert (args);
np->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
args->dir = np->nn->dead_dir;
args->name = np->nn->dead_name;
@@ -145,10 +148,17 @@ netfs_node_norefs (struct node *np)
/* Do this in a separate thread so that we don't wait for it; it
acquires a lock on the dir, which we are not allowed to
do. */
- cthread_detach (cthread_fork (forked_node_delete, (any_t) args));
+ err = pthread_create (&thread, NULL, forked_node_delete, args);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
/* Caller expects us to leave this locked... */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
}
else
{
@@ -180,7 +190,7 @@ recache_handle (int *p, struct node *np)
}
/* Unlink it */
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
*np->nn->hprevp = np->nn->hnext;
if (np->nn->hnext)
np->nn->hnext->nn->hprevp = np->nn->hprevp;
@@ -196,7 +206,7 @@ recache_handle (int *p, struct node *np)
np->nn->hnext->nn->hprevp = &np->nn->hnext;
np->nn->hprevp = &nodehash[h];
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
return p + len / sizeof (int);
}
diff --git a/nfs/main.c b/nfs/main.c
index 48852062..bb623514 100644
--- a/nfs/main.c
+++ b/nfs/main.c
@@ -351,7 +351,9 @@ parse_startup_opt (int key, char *arg, struct argp_state *state)
int
main (int argc, char **argv)
{
+ pthread_t thread;
error_t err;
+
struct argp common_argp = { common_options, parse_common_opt };
const struct argp_child argp_children[] =
{ {&common_argp}, {&netfs_std_startup_argp}, {0} };
@@ -391,8 +393,22 @@ main (int argc, char **argv)
if (err)
error (2, err, "mapping time");
- cthread_detach (cthread_fork ((cthread_fn_t) timeout_service_thread, 0));
- cthread_detach (cthread_fork ((cthread_fn_t) rpc_receive_thread, 0));
+ err = pthread_create (&thread, NULL, timeout_service_thread, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
+ err = pthread_create (&thread, NULL, rpc_receive_thread, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
hostname = localhost ();
diff --git a/nfs/mount.c b/nfs/mount.c
index 6120f87a..29b203aa 100644
--- a/nfs/mount.c
+++ b/nfs/mount.c
@@ -216,7 +216,7 @@ mount_root (char *name, char *host)
/* Create the node for root */
xdr_decode_fhandle (p, &np);
free (rpcbuf);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (nfs_port_override)
port = nfs_port;
diff --git a/nfs/name-cache.c b/nfs/name-cache.c
index 845cda30..7553d7c0 100644
--- a/nfs/name-cache.c
+++ b/nfs/name-cache.c
@@ -61,7 +61,7 @@ struct lookup_cache
/* The contents of the cache in no particular order */
static struct cacheq lookup_cache = { sizeof (struct lookup_cache) };
-static spin_lock_t cache_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t cache_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* Buffer to hold statistics */
static struct stats
@@ -115,7 +115,7 @@ enter_lookup_cache (char *dir, size_t len, struct node *np, char *name)
if (name_len > CACHE_NAME_LEN - 1)
return;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
if (lookup_cache.length == 0)
/* There should always be an lru_cache; this being zero means that the
@@ -141,7 +141,7 @@ enter_lookup_cache (char *dir, size_t len, struct node *np, char *name)
/* Now C becomes the MRU entry! */
cacheq_make_mru (&lookup_cache, c);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
}
/* Purge all references in the cache to NAME within directory DIR. */
@@ -150,7 +150,7 @@ purge_lookup_cache (struct node *dp, char *name, size_t namelen)
{
struct lookup_cache *c, *next;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
for (c = lookup_cache.mru; c; c = next)
{
/* Save C->hdr.next, since we may move C from this position. */
@@ -170,7 +170,7 @@ purge_lookup_cache (struct node *dp, char *name, size_t namelen)
entry. */
}
}
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
}
/* Purge all references in the cache to node NP. */
@@ -179,7 +179,7 @@ purge_lookup_cache_node (struct node *np)
{
struct lookup_cache *c, *next;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
for (c = lookup_cache.mru; c; c = next)
{
next = c->hdr.next;
@@ -192,7 +192,7 @@ purge_lookup_cache_node (struct node *np)
cacheq_make_lru (&lookup_cache, c);
}
}
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
}
@@ -249,7 +249,7 @@ check_lookup_cache (struct node *dir, char *name)
{
struct lookup_cache *c;
- spin_lock (&cache_lock);
+ pthread_spin_lock (&cache_lock);
c = find_cache (dir->nn->handle.data, dir->nn->handle.size,
name, strlen (name));
@@ -268,7 +268,7 @@ check_lookup_cache (struct node *dir, char *name)
c->name_len = 0;
c->np = 0;
cacheq_make_lru (&lookup_cache, c);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
return 0;
}
@@ -278,8 +278,8 @@ check_lookup_cache (struct node *dir, char *name)
/* A negative cache entry. */
{
register_neg_hit (c->stati);
- spin_unlock (&cache_lock);
- mutex_unlock (&dir->lock);
+ pthread_spin_unlock (&cache_lock);
+ pthread_mutex_unlock (&dir->lock);
return (struct node *)-1;
}
else
@@ -289,17 +289,17 @@ check_lookup_cache (struct node *dir, char *name)
np = c->np;
netfs_nref (np);
register_pos_hit (c->stati);
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
- mutex_unlock (&dir->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_unlock (&dir->lock);
+ pthread_mutex_lock (&np->lock);
return np;
}
}
register_miss ();
- spin_unlock (&cache_lock);
+ pthread_spin_unlock (&cache_lock);
return 0;
}
diff --git a/nfs/nfs.h b/nfs/nfs.h
index 147dc900..18dec001 100644
--- a/nfs/nfs.h
+++ b/nfs/nfs.h
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
+#include <pthread.h>
#include <sys/mman.h>
#include "nfs-spec.h"
#include <hurd/netfs.h>
@@ -187,8 +188,8 @@ int *register_fresh_stat (struct node *, int *);
/* rpc.c */
int *initialize_rpc (int, int, int, size_t, void **, uid_t, gid_t, gid_t);
error_t conduct_rpc (void **, int **);
-void timeout_service_thread (void);
-void rpc_receive_thread (void);
+void *timeout_service_thread (void *);
+void *rpc_receive_thread (void *);
/* cache.c */
void lookup_fhandle (void *, size_t, struct node **);
diff --git a/nfs/ops.c b/nfs/ops.c
index 05cfbe9a..a4d6ac77 100644
--- a/nfs/ops.c
+++ b/nfs/ops.c
@@ -671,7 +671,7 @@ netfs_attempt_lookup (struct iouser *cred, struct node *np,
dirlen = np->nn->handle.size;
memcpy (dirhandle, np->nn->handle.data, dirlen);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
err = conduct_rpc (&rpcbuf, &p);
if (!err)
@@ -688,12 +688,12 @@ netfs_attempt_lookup (struct iouser *cred, struct node *np,
if (protocol_version == 3)
{
if (*newnp)
- mutex_unlock (&(*newnp)->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_unlock (&(*newnp)->lock);
+ pthread_mutex_lock (&np->lock);
p = process_returned_stat (np, p, 0); /* XXX Do we have to lock np? */
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (*newnp)
- mutex_lock (&(*newnp)->lock);
+ pthread_mutex_lock (&(*newnp)->lock);
}
}
else
@@ -815,9 +815,9 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
/* We have no RPC available that will do an atomic replacement,
so we settle for second best; just doing an unlink and ignoring
any errors. */
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
netfs_attempt_unlink (cred, dir, name);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
/* If we have postponed a translator setting on an unlinked node,
@@ -828,22 +828,22 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
{
case POSSIBLE:
case NOT_POSSIBLE:
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
p = nfs_initialize_rpc (NFSPROC_LINK (protocol_version),
cred, 0, &rpcbuf, dir, -1);
if (! p)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return errno;
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
p = xdr_encode_fhandle (p, &np->nn->handle);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
purge_lookup_cache (dir, name, strlen (name));
p = xdr_encode_fhandle (p, &dir->nn->handle);
@@ -855,32 +855,32 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
err = nfs_error_trans (ntohl (*p));
p++;
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
free (rpcbuf);
break;
case SYMLINK:
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
p = nfs_initialize_rpc (NFSPROC_SYMLINK (protocol_version),
cred, 0, &rpcbuf, dir, -1);
if (! p)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return errno;
}
p = xdr_encode_fhandle (p, &dir->nn->handle);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
p = xdr_encode_string (p, name);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, cred);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
free (rpcbuf);
return err;
}
@@ -895,9 +895,9 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
p = xdr_encode_sattr_stat (p, &np->nn_stat);
p = xdr_encode_string (p, np->nn->transarg.name);
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
purge_lookup_cache (dir, name, strlen (name));
err = conduct_rpc (&rpcbuf, &p);
@@ -916,13 +916,13 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
cred, 0, &rpcbuf, dir, -1);
if (! p)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return errno;
}
p = xdr_encode_fhandle (p, &dir->nn->handle);
p = xdr_encode_string (p, name);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
err = conduct_rpc (&rpcbuf, &p);
if (!err)
@@ -932,10 +932,10 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
}
if (!err)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
p = recache_handle (p, np);
p = process_returned_stat (np, p, 1);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
if (err)
err = EGRATUITOUS; /* damn */
@@ -944,21 +944,21 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
{
if (!err)
{
- mutex_unlock (&dir->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_unlock (&dir->lock);
+ pthread_mutex_lock (&np->lock);
p = recache_handle (p, np);
p = process_returned_stat (np, p, 1);
- mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_unlock (&np->lock);
+ pthread_mutex_lock (&dir->lock);
}
p = process_wcc_stat (dir, p, !err);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
else
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
else
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
free (rpcbuf);
break;
@@ -970,7 +970,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
if (protocol_version == 2)
{
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
err = verify_nonexistent (cred, dir, name);
if (err)
return err;
@@ -979,29 +979,29 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
cred, 0, &rpcbuf, dir, -1);
if (! p)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return errno;
}
p = xdr_encode_fhandle (p, &dir->nn->handle);
p = xdr_encode_string (p, name);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, cred);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
free (rpcbuf);
return err;
}
p = xdr_encode_sattr_stat (p, &np->nn_stat);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
purge_lookup_cache (dir, name, strlen (name));
- mutex_unlock (&dir->lock); /* XXX Should this really be after the
+ pthread_mutex_unlock (&dir->lock); /* XXX Should this really be after the
_lengthy_ (blocking) conduct_rpc? */
err = conduct_rpc (&rpcbuf, &p);
if (!err)
@@ -1012,32 +1012,32 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
if (!err)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
p = recache_handle (p, np);
register_fresh_stat (np, p);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
free (rpcbuf);
}
else /* protocol_version != 2 */
{
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
p = nfs_initialize_rpc (NFS3PROC_MKNOD, cred, 0, &rpcbuf, dir, -1);
if (! p)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return errno;
}
p = xdr_encode_fhandle (p, &dir->nn->handle);
p = xdr_encode_string (p, name);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = netfs_validate_stat (np, cred);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
free (rpcbuf);
return err;
}
@@ -1048,7 +1048,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
*(p++) = htonl (major (np->nn_stat.st_rdev));
*(p++) = htonl (minor (np->nn_stat.st_rdev));
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
purge_lookup_cache (dir, name, strlen (name));
err = conduct_rpc (&rpcbuf, &p);
@@ -1059,14 +1059,14 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
if (!err)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
p = recache_handle (p, np);
p = process_returned_stat (np, p, 1);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
}
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
p = process_wcc_stat (dir, p, !err);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
free (rpcbuf);
}
@@ -1076,7 +1076,7 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
if (err)
return err;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (np->nn->dtrans == SYMLINK)
free (np->nn->transarg.name);
@@ -1089,14 +1089,14 @@ netfs_attempt_link (struct iouser *cred, struct node *dir,
char *name = np->nn->dead_name;
np->nn->dead_dir = 0;
np->nn->dead_name = 0;
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
netfs_attempt_unlink ((struct iouser *)-1, dir, name);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
}
else
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return 0;
}
@@ -1122,7 +1122,7 @@ netfs_attempt_mkfile (struct iouser *cred, struct node *dir,
sprintf (name, ".nfstmpgnu.%d", n++);
err = netfs_attempt_create_file (cred, dir, name, mode, newnp);
if (err == EEXIST)
- mutex_lock (&dir->lock); /* XXX is this right? does create need this
+ pthread_mutex_lock (&dir->lock); /* XXX is this right? does create need this
and drop this on error? Doesn't look
like it. */
}
@@ -1172,7 +1172,7 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np,
err = verify_nonexistent (cred, np, name);
if (err)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return err;
}
}
@@ -1201,7 +1201,7 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np,
err = conduct_rpc (&rpcbuf, &p);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (!err)
{
@@ -1217,12 +1217,12 @@ netfs_attempt_create_file (struct iouser *cred, struct node *np,
if (protocol_version == 3)
{
if (*newnp)
- mutex_unlock (&(*newnp)->lock);
- mutex_lock (&np->lock);
+ pthread_mutex_unlock (&(*newnp)->lock);
+ pthread_mutex_lock (&np->lock);
p = process_wcc_stat (np, p, 1);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (*newnp)
- mutex_lock (&(*newnp)->lock);
+ pthread_mutex_lock (&(*newnp)->lock);
}
if (*newnp && !netfs_validate_stat (*newnp, (struct iouser *) -1)
@@ -1251,13 +1251,13 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir,
err = netfs_attempt_lookup (cred, dir, name, &np);
if (err)
{
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
return err;
}
/* Restore the locks to sanity. */
- mutex_unlock (&np->lock);
- mutex_lock (&dir->lock);
+ pthread_mutex_unlock (&np->lock);
+ pthread_mutex_lock (&dir->lock);
/* Purge the cache of entries for this node, so that we don't
regard cache-held references as live. */
@@ -1272,12 +1272,12 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir,
char *newname = 0;
int n = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
newname = malloc (50);
if (! newname)
{
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
netfs_nrele (np); /* XXX Is this the correct thing to do? */
return ENOMEM;
}
@@ -1292,14 +1292,14 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir,
if (err)
{
free (newname);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
netfs_nrele (np);
return err;
}
/* Write down what name we gave it; we'll delete this when all
our uses vanish. */
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
if (np->nn->dead_dir)
netfs_nrele (np->nn->dead_dir);
@@ -1312,7 +1312,7 @@ netfs_attempt_unlink (struct iouser *cred, struct node *dir,
np->nn->dtrans = POSSIBLE;
netfs_nput (np);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
}
else
netfs_nrele (np);
@@ -1356,9 +1356,9 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir,
/* Just do a lookup/link/unlink sequence. */
- mutex_lock (&fromdir->lock);
+ pthread_mutex_lock (&fromdir->lock);
err = netfs_attempt_lookup (cred, fromdir, fromname, &np);
- mutex_unlock (&fromdir->lock);
+ pthread_mutex_unlock (&fromdir->lock);
if (err)
return err;
@@ -1367,41 +1367,41 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir,
if (err)
return err;
- mutex_lock (&fromdir->lock);
+ pthread_mutex_lock (&fromdir->lock);
err = netfs_attempt_unlink (cred, fromdir, fromname);
- mutex_unlock (&fromdir->lock);
+ pthread_mutex_unlock (&fromdir->lock);
/* If the unlink failed, then back out the link */
if (err)
{
- mutex_lock (&todir->lock);
+ pthread_mutex_lock (&todir->lock);
netfs_attempt_unlink (cred, todir, toname);
- mutex_unlock (&todir->lock);
+ pthread_mutex_unlock (&todir->lock);
return err;
}
return 0;
}
- mutex_lock (&fromdir->lock);
+ pthread_mutex_lock (&fromdir->lock);
purge_lookup_cache (fromdir, fromname, strlen (fromname));
p = nfs_initialize_rpc (NFSPROC_RENAME (protocol_version),
cred, 0, &rpcbuf, fromdir, -1);
if (! p)
{
- mutex_unlock (&fromdir->lock);
+ pthread_mutex_unlock (&fromdir->lock);
return errno;
}
p = xdr_encode_fhandle (p, &fromdir->nn->handle);
p = xdr_encode_string (p, fromname);
- mutex_unlock (&fromdir->lock);
+ pthread_mutex_unlock (&fromdir->lock);
- mutex_lock (&todir->lock);
+ pthread_mutex_lock (&todir->lock);
purge_lookup_cache (todir, toname, strlen (toname));
p = xdr_encode_fhandle (p, &todir->nn->handle);
p = xdr_encode_string (p, toname);
- mutex_unlock (&todir->lock);
+ pthread_mutex_unlock (&todir->lock);
err = conduct_rpc (&rpcbuf, &p);
if (!err)
@@ -1410,7 +1410,7 @@ netfs_attempt_rename (struct iouser *cred, struct node *fromdir,
p++;
if (protocol_version == 3) /* XXX Should we add `&& !err' ? */
{
- mutex_lock (&fromdir->lock);
+ pthread_mutex_lock (&fromdir->lock);
p = process_wcc_stat (fromdir, p, !err);
p = process_wcc_stat (todir, p, !err);
}
diff --git a/nfs/rpc.c b/nfs/rpc.c
index 0b0444d0..c0d0290e 100644
--- a/nfs/rpc.c
+++ b/nfs/rpc.c
@@ -49,10 +49,10 @@ static struct rpc_list *outstanding_rpcs;
/* Wake up this condition when an outstanding RPC has received a reply
or we should check for timeouts. */
-static struct condition rpc_wakeup = CONDITION_INITIALIZER;
+static pthread_cond_t rpc_wakeup = PTHREAD_COND_INITIALIZER;
/* Lock the global data and the REPLY fields of outstanding RPC's. */
-static struct mutex outstanding_lock = MUTEX_INITIALIZER;
+static pthread_mutex_t outstanding_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -186,7 +186,7 @@ conduct_rpc (void **rpcbuf, int **pp)
int n;
int cancel;
- mutex_lock (&outstanding_lock);
+ pthread_mutex_lock (&outstanding_lock);
link_rpc (&outstanding_rpcs, hdr);
@@ -198,7 +198,7 @@ conduct_rpc (void **rpcbuf, int **pp)
if (mounted_soft && ntransmit == soft_retries)
{
unlink_rpc (hdr);
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_unlock (&outstanding_lock);
return ETIMEDOUT;
}
@@ -210,7 +210,7 @@ conduct_rpc (void **rpcbuf, int **pp)
if (cc == -1)
{
unlink_rpc (hdr);
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_unlock (&outstanding_lock);
return errno;
}
else
@@ -221,12 +221,12 @@ conduct_rpc (void **rpcbuf, int **pp)
while (!hdr->reply
&& (mapped_time->seconds - lasttrans < timeout)
&& !cancel)
- cancel = hurd_condition_wait (&rpc_wakeup, &outstanding_lock);
+ cancel = pthread_hurd_cond_wait_np (&rpc_wakeup, &outstanding_lock);
if (cancel)
{
unlink_rpc (hdr);
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_unlock (&outstanding_lock);
return EINTR;
}
@@ -242,7 +242,7 @@ conduct_rpc (void **rpcbuf, int **pp)
}
while (!hdr->reply);
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_unlock (&outstanding_lock);
/* Switch to the reply buffer. */
*rpcbuf = hdr->reply;
@@ -349,25 +349,31 @@ conduct_rpc (void **rpcbuf, int **pp)
/* Dedicated thread to signal those waiting on rpc_wakeup
once a second. */
-void
-timeout_service_thread ()
+void *
+timeout_service_thread (void *arg)
{
+ (void) arg;
+
while (1)
{
sleep (1);
- mutex_lock (&outstanding_lock);
- condition_broadcast (&rpc_wakeup);
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_lock (&outstanding_lock);
+ pthread_cond_broadcast (&rpc_wakeup);
+ pthread_mutex_unlock (&outstanding_lock);
}
+
+ return NULL;
}
/* Dedicate thread to receive RPC replies, register them on the queue
of pending wakeups, and deal appropriately. */
-void
-rpc_receive_thread ()
+void *
+rpc_receive_thread (void *arg)
{
void *buf;
+ (void) arg;
+
/* Allocate a receive buffer. */
buf = malloc (1024 + read_size);
assert (buf);
@@ -385,7 +391,7 @@ rpc_receive_thread ()
struct rpc_list *r;
int xid = *(int *)buf;
- mutex_lock (&outstanding_lock);
+ pthread_mutex_lock (&outstanding_lock);
/* Find the rpc that we just fulfilled. */
for (r = outstanding_rpcs; r; r = r->next)
@@ -394,7 +400,7 @@ rpc_receive_thread ()
{
unlink_rpc (r);
r->reply = buf;
- condition_broadcast (&rpc_wakeup);
+ pthread_cond_broadcast (&rpc_wakeup);
break;
}
}
@@ -402,7 +408,7 @@ rpc_receive_thread ()
if (! r)
fprintf (stderr, "NFS dropping reply xid %d\n", xid);
#endif
- mutex_unlock (&outstanding_lock);
+ pthread_mutex_unlock (&outstanding_lock);
/* If r is not null then we had a message from a pending
(i.e. known) rpc. Thus, it was fulfilled and if we want
@@ -414,4 +420,6 @@ rpc_receive_thread ()
}
}
}
+
+ return NULL;
}
diff --git a/nfsd/Makefile b/nfsd/Makefile
index 5487a946..daaf86e8 100644
--- a/nfsd/Makefile
+++ b/nfsd/Makefile
@@ -24,7 +24,8 @@ SRCS = cache.c loop.c main.c ops.c fsys.c xdr.c
OBJS = $(subst .c,.o,$(SRCS))
target = nfsd
installationdir = $(sbindir)
-HURDLIBS=threads shouldbeinlibc
+HURDLIBS = shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/nfsd/cache.c b/nfsd/cache.c
index 7b96dbc2..060cc738 100644
--- a/nfsd/cache.c
+++ b/nfsd/cache.c
@@ -24,6 +24,7 @@
#include <hurd/fsys.h>
#include <assert.h>
#include <string.h>
+#include <pthread.h>
#include <hurd/io.h>
#include <hurd/auth.h>
#include "nfsd.h"
@@ -42,7 +43,7 @@
static struct idspec *idhashtable[IDHASH_TABLE_SIZE];
-spin_lock_t idhashlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t idhashlock = PTHREAD_SPINLOCK_INITIALIZER;
static int nfreeids;
static int leastidlastuse;
@@ -90,14 +91,14 @@ idspec_lookup (int nuids, int ngids, int *uids, int *gids)
hash = idspec_hash (nuids, ngids, uids, gids);
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
for (i = idhashtable[hash]; i; i = i->next)
if (idspec_compare (i, nuids, ngids, uids, gids))
{
i->references++;
if (i->references == 1)
nfreeids--;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
return i;
}
@@ -117,7 +118,7 @@ idspec_lookup (int nuids, int ngids, int *uids, int *gids)
i->prevp = &idhashtable[hash];
idhashtable[hash] = i;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
return i;
}
@@ -184,7 +185,7 @@ process_cred (int *p, struct idspec **credp)
void
cred_rele (struct idspec *i)
{
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
i->references--;
if (i->references == 0)
{
@@ -193,16 +194,16 @@ cred_rele (struct idspec *i)
leastidlastuse = i->lastuse;
nfreeids++;
}
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
void
cred_ref (struct idspec *i)
{
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
assert (i->references);
i->references++;
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
void
@@ -211,7 +212,7 @@ scan_creds ()
int n;
int newleast = mapped_time->seconds;
- spin_lock (&idhashlock);
+ pthread_spin_lock (&idhashlock);
if (mapped_time->seconds - leastidlastuse > ID_KEEP_TIMEOUT)
{
@@ -245,13 +246,13 @@ scan_creds ()
if (nfreeids)
leastidlastuse = newleast;
}
- spin_unlock (&idhashlock);
+ pthread_spin_unlock (&idhashlock);
}
static struct cache_handle *fhhashtable[FHHASH_TABLE_SIZE];
-struct mutex fhhashlock = MUTEX_INITIALIZER;
+pthread_mutex_t fhhashlock = PTHREAD_MUTEX_INITIALIZER;
static int nfreefh;
static int leastfhlastuse;
@@ -275,14 +276,14 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
file_t port;
hash = fh_hash ((char *)p, i);
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
for (c = fhhashtable[hash]; c; c = c->next)
if (c->ids == i && ! bcmp (c->handle, p, NFS2_FHSIZE))
{
if (c->references == 0)
nfreefh--;
c->references++;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = c;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -295,7 +296,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
|| fsys_getfile (fsys, i->uids, i->nuids, i->gids, i->ngids,
(char *)(p + 1), NFS2_FHSIZE - sizeof (int), &port))
{
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = 0;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -313,7 +314,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
c->prevp = &fhhashtable[hash];
fhhashtable[hash] = c;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
*cp = c;
return p + NFS2_FHSIZE / sizeof (int);
}
@@ -321,7 +322,7 @@ lookup_cache_handle (int *p, struct cache_handle **cp, struct idspec *i)
void
cache_handle_rele (struct cache_handle *c)
{
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
c->references--;
if (c->references == 0)
{
@@ -330,7 +331,7 @@ cache_handle_rele (struct cache_handle *c)
leastfhlastuse = c->lastuse;
nfreefh++;
}
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
}
void
@@ -339,7 +340,7 @@ scan_fhs ()
int n;
int newleast = mapped_time->seconds;
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
if (mapped_time->seconds - leastfhlastuse > FH_KEEP_TIMEOUT)
{
@@ -373,7 +374,7 @@ scan_fhs ()
if (nfreefh)
leastfhlastuse = newleast;
}
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
}
struct cache_handle *
@@ -416,7 +417,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
/* Cache it. */
hash = fh_hash (fhandle, credc->ids);
- mutex_lock (&fhhashlock);
+ pthread_mutex_lock (&fhhashlock);
for (c = fhhashtable[hash]; c; c = c->next)
if (c->ids == credc->ids && ! bcmp (fhandle, c->handle, NFS2_FHSIZE))
{
@@ -424,7 +425,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
if (c->references == 0)
nfreefh--;
c->references++;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return c;
}
@@ -438,7 +439,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
&newport);
if (err)
{
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return 0;
}
@@ -456,7 +457,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
c->next->prevp = &c->next;
c->prevp = &fhhashtable[hash];
fhhashtable[hash] = c;
- mutex_unlock (&fhhashlock);
+ pthread_mutex_unlock (&fhhashlock);
return c;
}
@@ -464,7 +465,7 @@ create_cached_handle (int fs, struct cache_handle *credc, file_t userport)
static struct cached_reply *replyhashtable [REPLYHASH_TABLE_SIZE];
-static spin_lock_t replycachelock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t replycachelock = PTHREAD_SPINLOCK_INITIALIZER;
static int nfreereplies;
static int leastreplylastuse;
@@ -480,7 +481,7 @@ check_cached_replies (int xid,
hash = abs(xid % REPLYHASH_TABLE_SIZE);
- spin_lock (&replycachelock);
+ pthread_spin_lock (&replycachelock);
for (cr = replyhashtable[hash]; cr; cr = cr->next)
if (cr->xid == xid
&& !bcmp (sender, &cr->source, sizeof (struct sockaddr_in)))
@@ -488,14 +489,14 @@ check_cached_replies (int xid,
cr->references++;
if (cr->references == 1)
nfreereplies--;
- spin_unlock (&replycachelock);
- mutex_lock (&cr->lock);
+ pthread_spin_unlock (&replycachelock);
+ pthread_mutex_lock (&cr->lock);
return cr;
}
cr = malloc (sizeof (struct cached_reply));
- mutex_init (&cr->lock);
- mutex_lock (&cr->lock);
+ pthread_mutex_init (&cr->lock, NULL);
+ pthread_mutex_lock (&cr->lock);
memcpy (&cr->source, sender, sizeof (struct sockaddr_in));
cr->xid = xid;
cr->data = 0;
@@ -507,7 +508,7 @@ check_cached_replies (int xid,
cr->prevp = &replyhashtable[hash];
replyhashtable[hash] = cr;
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
return cr;
}
@@ -516,8 +517,8 @@ check_cached_replies (int xid,
void
release_cached_reply (struct cached_reply *cr)
{
- mutex_unlock (&cr->lock);
- spin_lock (&replycachelock);
+ pthread_mutex_unlock (&cr->lock);
+ pthread_spin_lock (&replycachelock);
cr->references--;
if (cr->references == 0)
{
@@ -526,7 +527,7 @@ release_cached_reply (struct cached_reply *cr)
leastreplylastuse = cr->lastuse;
nfreereplies++;
}
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
}
void
@@ -535,7 +536,7 @@ scan_replies ()
int n;
int newleast = mapped_time->seconds;
- spin_lock (&replycachelock);
+ pthread_spin_lock (&replycachelock);
if (mapped_time->seconds - leastreplylastuse > REPLY_KEEP_TIMEOUT)
{
@@ -569,5 +570,5 @@ scan_replies ()
if (nfreereplies)
leastreplylastuse = newleast;
}
- spin_unlock (&replycachelock);
+ pthread_spin_unlock (&replycachelock);
}
diff --git a/nfsd/loop.c b/nfsd/loop.c
index bfec5e5a..f2d6d546 100644
--- a/nfsd/loop.c
+++ b/nfsd/loop.c
@@ -35,9 +35,10 @@
#include <rpc/rpc_msg.h>
#undef malloc
-void
-server_loop (int fd)
+void *
+server_loop (void *arg)
{
+ int fd = (int) arg;
char buf[MAXIOSIZE];
int xid;
int *p, *r;
diff --git a/nfsd/main.c b/nfsd/main.c
index ee071090..d5607d37 100644
--- a/nfsd/main.c
+++ b/nfsd/main.c
@@ -24,6 +24,7 @@
#include <rpc/pmap_prot.h>
#include <maptime.h>
#include <hurd.h>
+#include <pthread.h>
#include <error.h>
int main_udp_socket, pmap_udp_socket;
@@ -31,6 +32,22 @@ struct sockaddr_in main_address, pmap_address;
static char index_file[] = LOCALSTATEDIR "/state/misc/nfsd.index";
char *index_file_name = index_file;
+/* Launch a server loop thread */
+static void
+create_server_thread (int socket)
+{
+ pthread_t thread;
+ int fail;
+
+ fail = pthread_create (&thread, NULL, server_loop, (void *) socket);
+ if (fail)
+ error (1, fail, "Creating main server thread");
+
+ fail = pthread_detach (thread);
+ if (fail)
+ error (1, fail, "Detaching main server thread");
+}
+
int
main (int argc, char **argv)
{
@@ -73,12 +90,10 @@ main (int argc, char **argv)
init_filesystems ();
- cthread_detach (cthread_fork ((cthread_fn_t) server_loop,
- (any_t)(intptr_t) pmap_udp_socket));
+ create_server_thread (pmap_udp_socket);
while (nthreads--)
- cthread_detach (cthread_fork ((cthread_fn_t) server_loop,
- (any_t)(intptr_t) main_udp_socket));
+ create_server_thread (main_udp_socket);
for (;;)
{
diff --git a/nfsd/nfsd.h b/nfsd/nfsd.h
index e89a411b..4afff061 100644
--- a/nfsd/nfsd.h
+++ b/nfsd/nfsd.h
@@ -22,7 +22,7 @@
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <rpc/types.h>
#include "../nfs/nfs-spec.h" /* XXX */
#include <hurd/fs.h>
@@ -55,7 +55,7 @@ struct cache_handle
struct cached_reply
{
struct cached_reply *next, **prevp;
- struct mutex lock;
+ pthread_mutex_t lock;
struct sockaddr_in source;
int xid;
time_t lastuse;
@@ -109,7 +109,7 @@ void release_cached_reply (struct cached_reply *cr);
void scan_replies (void);
/* loop.c */
-void server_loop (int);
+void * server_loop (void *);
/* ops.c */
extern struct proctable nfs2table, mounttable, pmaptable;
diff --git a/pfinet/Makefile b/pfinet/Makefile
index 48b47915..d442629d 100644
--- a/pfinet/Makefile
+++ b/pfinet/Makefile
@@ -114,7 +114,8 @@ FROBBEDLINUXHEADERS = autoconf.h binfmts.h config.h errno.h fcntl.h fs.h \
ASMHEADERS = atomic.h bitops.h byteorder.h delay.h errno.h hardirq.h init.h \
segment.h spinlock.h system.h types.h uaccess.h
-HURDLIBS=trivfs fshelp threads ports ihash shouldbeinlibc iohelp
+HURDLIBS=trivfs fshelp ports ihash shouldbeinlibc iohelp
+OTHERLIBS = -lpthread
target = pfinet
diff --git a/pfinet/ethernet.c b/pfinet/ethernet.c
index 0fd76706..447d5b06 100644
--- a/pfinet/ethernet.c
+++ b/pfinet/ethernet.c
@@ -98,13 +98,13 @@ static int bpf_ether_filter_len = sizeof (bpf_ether_filter) / sizeof (short);
static struct port_bucket *etherport_bucket;
-static any_t
-ethernet_thread (any_t arg)
+static void *
+ethernet_thread (void *arg)
{
ports_manage_port_operations_one_thread (etherport_bucket,
ethernet_demuxer,
0);
- return 0;
+ return NULL;
}
int
@@ -134,7 +134,7 @@ ethernet_demuxer (mach_msg_header_t *inp,
datalen = ETH_HLEN
+ msg->packet_type.msgt_number - sizeof (struct packet_header);
- __mutex_lock (&net_bh_lock);
+ pthread_mutex_lock (&net_bh_lock);
skb = alloc_skb (datalen, GFP_ATOMIC);
skb_put (skb, datalen);
skb->dev = dev;
@@ -148,7 +148,7 @@ ethernet_demuxer (mach_msg_header_t *inp,
/* Drop it on the queue. */
skb->protocol = eth_type_trans (skb, dev);
netif_rx (skb);
- __mutex_unlock (&net_bh_lock);
+ pthread_mutex_unlock (&net_bh_lock);
return 1;
}
@@ -157,10 +157,19 @@ ethernet_demuxer (mach_msg_header_t *inp,
void
ethernet_initialize (void)
{
+ pthread_t thread;
+ error_t err;
etherport_bucket = ports_create_bucket ();
etherreadclass = ports_create_class (0, 0);
- cthread_detach (cthread_fork (ethernet_thread, 0));
+ err = pthread_create (&thread, NULL, ethernet_thread, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
int
diff --git a/pfinet/glue-include/asm/spinlock.h b/pfinet/glue-include/asm/spinlock.h
index 1666b0e2..ef13312d 100644
--- a/pfinet/glue-include/asm/spinlock.h
+++ b/pfinet/glue-include/asm/spinlock.h
@@ -1,8 +1,6 @@
#ifndef _HACK_ASM_SPINLOCK_H_
#define _HACK_ASM_SPINLOCK_H_
-#include <cthreads.h>
-
typedef struct { } spinlock_t;
#define SPIN_LOCK_UNLOCKED { }
diff --git a/pfinet/glue-include/linux/interrupt.h b/pfinet/glue-include/linux/interrupt.h
index 5f485e32..df58d2f4 100644
--- a/pfinet/glue-include/linux/interrupt.h
+++ b/pfinet/glue-include/linux/interrupt.h
@@ -14,13 +14,13 @@
#define start_bh_atomic() ((void) 0)
#define end_bh_atomic() ((void) 0)
/*
-extern struct mutex net_bh_lock;
-#define start_bh_atomic() __mutex_lock (&net_bh_lock)
-#define end_bh_atomic() __mutex_unlock (&net_bh_lock)
+extern pthread_mutex_t net_bh_lock;
+#define start_bh_atomic() pthread_mutex_lock (&net_bh_lock)
+#define end_bh_atomic() pthread_mutex_unlock (&net_bh_lock)
*/
/* See sched.c::net_bh_worker comments. */
-extern struct condition net_bh_wakeup;
+extern pthread_cond_t net_bh_wakeup;
#define NET_BH 0xb00bee51
@@ -30,7 +30,7 @@ static inline void
mark_bh (int bh)
{
assert (bh == NET_BH);
- condition_broadcast (&net_bh_wakeup);
+ pthread_cond_broadcast (&net_bh_wakeup);
}
void net_bh (void);
diff --git a/pfinet/glue-include/linux/sched.h b/pfinet/glue-include/linux/sched.h
index d4cae42a..aea6c47a 100644
--- a/pfinet/glue-include/linux/sched.h
+++ b/pfinet/glue-include/linux/sched.h
@@ -7,7 +7,7 @@
#include <hurd/hurd_types.h>
#include <limits.h>
#include <assert.h>
-#include <cthreads.h>
+#include <pthread.h>
#include "mapped-time.h"
@@ -90,12 +90,12 @@ capable(int cap)
}
-extern struct mutex global_lock;
+extern pthread_mutex_t global_lock;
static inline void
interruptible_sleep_on (struct wait_queue **p)
{
- struct condition **condp = (void *) p, *c;
+ pthread_cond_t **condp = (void *) p, *c;
int isroot;
struct wait_queue **next_wait;
@@ -104,14 +104,14 @@ interruptible_sleep_on (struct wait_queue **p)
{
c = malloc (sizeof **condp);
assert (c);
- condition_init (c);
+ pthread_cond_init (c, NULL);
*condp = c;
}
isroot = current->isroot; /* This is our context that needs switched. */
next_wait = current->next_wait; /* This too, for multiple schedule calls. */
current->next_wait = 0;
- if (hurd_condition_wait (c, &global_lock))
+ if (pthread_hurd_cond_wait_np (c, &global_lock))
current->signal = 1; /* We got cancelled, mark it for later. */
current->isroot = isroot; /* Switch back to our context. */
current->next_wait = next_wait;
@@ -121,9 +121,9 @@ interruptible_sleep_on (struct wait_queue **p)
static inline void
wake_up_interruptible (struct wait_queue **p)
{
- struct condition **condp = (void *) p, *c = *condp;
+ pthread_cond_t **condp = (void *) p, *c = *condp;
if (c)
- condition_broadcast (c);
+ pthread_cond_broadcast (c);
}
#define wake_up wake_up_interruptible
diff --git a/pfinet/glue-include/linux/timer.h b/pfinet/glue-include/linux/timer.h
index cc8dec80..5497b109 100644
--- a/pfinet/glue-include/linux/timer.h
+++ b/pfinet/glue-include/linux/timer.h
@@ -1,7 +1,7 @@
#ifndef _HACK_TIMER_H_
#define _HACK_TIMER_H_
-#include <cthreads.h>
+#include <pthread.h>
enum tstate
{
diff --git a/pfinet/glue-include/linux/wait.h b/pfinet/glue-include/linux/wait.h
index 7ee962dc..58f4960e 100644
--- a/pfinet/glue-include/linux/wait.h
+++ b/pfinet/glue-include/linux/wait.h
@@ -1,14 +1,14 @@
#ifndef _HACK_WAIT_H_
#define _HACK_WAIT_H_
-#include <cthreads.h>
+#include <pthread.h>
/* This data structure actually represents one waiter on a wait queue,
and waiters always expect to initialize it with { current, NULL }.
The actual wait queue is a `struct wait_queue *' stored somewhere.
We ignore these structures provided by the waiters entirely.
In the `struct wait_queue *' that is the "head of the wait queue" slot,
- we actually store a `struct condition *' pointing to malloc'd storage. */
+ we actually store a `pthread_cond_t *' pointing to malloc'd storage. */
struct wait_queue
{
@@ -19,13 +19,13 @@ struct wait_queue
struct select_table_elt
{
- struct condition *dependent_condition;
+ pthread_cond_t *dependent_condition;
struct select_table_elt *next;
};
typedef struct select_table_struct
{
- struct condition master_condition;
+ pthread_cond_t master_condition;
struct select_table_elt *head;
} select_table;
diff --git a/pfinet/iioctl-ops.c b/pfinet/iioctl-ops.c
index c0dd6d5f..9904b9b3 100644
--- a/pfinet/iioctl-ops.c
+++ b/pfinet/iioctl-ops.c
@@ -55,7 +55,7 @@ struct device *get_dev (char *name)
memcpy (ifname, name, IFNAMSIZ-1);
ifname[IFNAMSIZ-1] = 0;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
for (dev = dev_base; dev; dev = dev->next)
if (strcmp (dev->name, ifname) == 0)
@@ -110,7 +110,7 @@ siocgifXaddr (io_t port,
sin->sin_addr.s_addr = addrs[type];
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
end_using_socket_port (user);
return err;
}
@@ -157,7 +157,7 @@ siocsifXaddr (io_t port,
err = configure_device (dev, addrs[0], addrs[1], addrs[2], addrs[3]);
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
end_using_socket_port (user);
return err;
}
@@ -194,7 +194,7 @@ S_iioctl_siocsifflags (io_t port,
err = ethernet_change_flags (dev, flags);
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
end_using_socket_port (user);
return err;
}
@@ -215,7 +215,7 @@ S_iioctl_siocgifflags (io_t port,
{
*flags = dev->flags;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -241,7 +241,7 @@ S_iioctl_siocgifmetric (io_t port,
{
*metric = 0; /* Not supported. */
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -296,7 +296,7 @@ S_iioctl_siocgifhwaddr (io_t port,
addr->sa_family = dev->type;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -316,7 +316,7 @@ S_iioctl_siocgifmtu (io_t port,
{
*mtu = dev->mtu;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -351,7 +351,7 @@ S_iioctl_siocsifmtu (io_t port,
notifier_call_chain (&netdev_chain, NETDEV_CHANGEMTU, dev);
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
end_using_socket_port (user);
return err;
}
@@ -372,7 +372,7 @@ S_iioctl_siocgifindex (io_t port,
{
*index = dev->ifindex;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -385,7 +385,7 @@ S_iioctl_siocgifname (io_t port,
error_t err = 0;
struct device *dev;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
dev = dev_get_by_index (*index);
if (!dev)
err = ENODEV;
@@ -394,7 +394,7 @@ S_iioctl_siocgifname (io_t port,
strncpy (ifnam, dev->name, IFNAMSIZ);
ifnam[IFNAMSIZ-1] = '\0';
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
diff --git a/pfinet/io-ops.c b/pfinet/io-ops.c
index ef8d8513..0236c594 100644
--- a/pfinet/io-ops.c
+++ b/pfinet/io-ops.c
@@ -48,12 +48,12 @@ S_io_write (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
if (user->sock->flags & O_NONBLOCK)
m.msg_flags |= MSG_DONTWAIT;
err = (*user->sock->ops->sendmsg) (user->sock, &m, datalen, 0);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (err < 0)
err = -err;
@@ -98,13 +98,13 @@ S_io_read (struct sock_user *user,
iov.iov_base = *data;
iov.iov_len = amount;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = (*user->sock->ops->recvmsg) (user->sock, &m, amount,
((user->sock->flags & O_NONBLOCK)
? MSG_DONTWAIT : 0),
0);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (err < 0)
{
@@ -142,7 +142,7 @@ S_io_readable (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
/* We need to avoid calling the Linux ioctl routines,
@@ -178,7 +178,7 @@ S_io_readable (struct sock_user *user,
break;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -189,12 +189,12 @@ S_io_set_all_openmodes (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (bits & O_NONBLOCK)
user->sock->flags |= O_NONBLOCK;
else
user->sock->flags &= ~O_NONBLOCK;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -207,7 +207,7 @@ S_io_get_openmodes (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
sk = user->sock->sk;
*bits = 0;
@@ -218,7 +218,7 @@ S_io_get_openmodes (struct sock_user *user,
if (user->sock->flags & O_NONBLOCK)
*bits |= O_NONBLOCK;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -229,10 +229,10 @@ S_io_set_some_openmodes (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (bits & O_NONBLOCK)
user->sock->flags |= O_NONBLOCK;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -243,10 +243,10 @@ S_io_clear_some_openmodes (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (bits & O_NONBLOCK)
user->sock->flags &= ~O_NONBLOCK;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -262,7 +262,7 @@ S_io_select (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
/* In Linux, this means (supposedly) that I/O will never be possible.
@@ -283,7 +283,7 @@ S_io_select (struct sock_user *user,
interruptible_sleep_on (user->sock->sk->sleep);
if (signal_pending (current)) /* This means we were cancelled. */
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
avail = (*user->sock->ops->poll) ((void *) 0xdeadbeef,
@@ -296,7 +296,7 @@ S_io_select (struct sock_user *user,
/* We got something. */
*select_type = avail;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -342,7 +342,7 @@ S_io_reauthenticate (struct sock_user *user,
aux_uids = aubuf;
aux_gids = agbuf;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
newuser = make_sock_user (user->sock, 0, 1, 0);
auth = getauth ();
@@ -380,7 +380,7 @@ S_io_reauthenticate (struct sock_user *user,
mach_port_move_member (mach_task_self (), newuser->pi.port_right,
pfinet_bucket->portset);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (newuser);
@@ -410,7 +410,7 @@ S_io_restrict_auth (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
isroot = 0;
if (user->isroot)
@@ -429,7 +429,7 @@ S_io_restrict_auth (struct sock_user *user,
*newobject = ports_get_right (newuser);
*newobject_type = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newuser);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -442,12 +442,12 @@ S_io_duplicate (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
newuser = make_sock_user (user->sock, user->isroot, 0, 0);
*newobject = ports_get_right (newuser);
*newobject_type = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newuser);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -464,14 +464,14 @@ S_io_identity (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (user->sock->identity == MACH_PORT_NULL)
{
err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
&user->sock->identity);
if (err)
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
}
@@ -482,7 +482,7 @@ S_io_identity (struct sock_user *user,
*fsystype = MACH_MSG_TYPE_MAKE_SEND;
*fileno = user->sock->st_ino;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
diff --git a/pfinet/kmem_cache.c b/pfinet/kmem_cache.c
index 8c73c9bf..aab192e1 100644
--- a/pfinet/kmem_cache.c
+++ b/pfinet/kmem_cache.c
@@ -20,12 +20,12 @@
/* Hack replacement for Linux's kmem_cache_t allocator, using plain malloc
and cthreads locking. The locking here is probably unnecessary. */
-#include <cthreads.h>
+#include <pthread.h>
#include <linux/malloc.h>
struct kmem_cache_s
{
- struct mutex lock;
+ pthread_mutex_t lock;
void *freelist;
size_t item_size;
@@ -43,7 +43,7 @@ kmem_cache_create (const char *name, size_t item_size,
kmem_cache_t *new = malloc (sizeof *new);
if (!new)
return 0;
- mutex_init (&new->lock);
+ pthread_mutex_init (&new->lock, NULL);
new->freelist = 0;
new->item_size = item_size;
new->ctor = ctor;
@@ -58,14 +58,14 @@ kmem_cache_alloc (kmem_cache_t *cache, int flags)
{
void *p;
- __mutex_lock (&cache->lock);
+ pthread_mutex_lock (&cache->lock);
p = cache->freelist;
if (p != 0) {
cache->freelist = *(void **)(p + cache->item_size);
- __mutex_unlock (&cache->lock);
+ pthread_mutex_unlock (&cache->lock);
return p;
}
- __mutex_unlock (&cache->lock);
+ pthread_mutex_unlock (&cache->lock);
p = malloc (cache->item_size + sizeof (void *));
if (p && cache->ctor)
@@ -79,10 +79,10 @@ kmem_cache_free (kmem_cache_t *cache, void *p)
{
void **const nextp = (void **) (p + cache->item_size);
- __mutex_lock (&cache->lock);
+ pthread_mutex_lock (&cache->lock);
*nextp = cache->freelist;
cache->freelist = p;
- __mutex_unlock (&cache->lock);
+ pthread_mutex_unlock (&cache->lock);
/* XXX eventually destroy some... */
}
diff --git a/pfinet/main.c b/pfinet/main.c
index 1357b037..7ec1bf1c 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -249,6 +249,7 @@ main (int argc,
error_t err;
mach_port_t bootstrap;
struct stat st;
+ pthread_t thread;
pfinet_bucket = ports_create_bucket ();
addrport_class = ports_create_class (clean_addrport, 0);
@@ -261,9 +262,16 @@ main (int argc,
init_time ();
ethernet_initialize ();
- cthread_detach (cthread_fork (net_bh_worker, 0));
+ err = pthread_create (&thread, NULL, net_bh_worker, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
prepare_current (1); /* Set up to call into Linux initialization. */
@@ -284,7 +292,7 @@ main (int argc,
htonl (INADDR_LOOPBACK), htonl (IN_CLASSA_NET),
htonl (INADDR_NONE), htonl (INADDR_NONE));
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* Parse options. When successful, this configures the interfaces
before returning; to do so, it will acquire the global_lock.
diff --git a/pfinet/options.c b/pfinet/options.c
index 21a35c61..1d0a9e1f 100644
--- a/pfinet/options.c
+++ b/pfinet/options.c
@@ -350,7 +350,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
}
/* Successfully finished parsing, return a result. */
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
for (in = h->interfaces; in < h->interfaces + h->num_interfaces; in++)
{
@@ -367,7 +367,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
in->peer, INADDR_NONE);
if (err)
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
FAIL (err, 16, 0, "cannot configure interface");
}
}
@@ -436,7 +436,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
err = - (*tb->tb_delete) (tb, &req.rtm, &rta, &req.nlh, 0);
if (err && err != ESRCH)
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
FAIL (err, 17, 0, "cannot remove old default gateway");
}
err = 0;
@@ -452,7 +452,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
: - (*tb->tb_insert) (tb, &req.rtm, &rta, &req.nlh, 0));
if (err)
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
FAIL (err, 17, 0, "cannot set default gateway");
}
}
@@ -474,7 +474,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
}
#endif
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* Fall through to free hook. */
diff --git a/pfinet/pfinet-ops.c b/pfinet/pfinet-ops.c
index 8e251020..6724575c 100644
--- a/pfinet/pfinet-ops.c
+++ b/pfinet/pfinet-ops.c
@@ -48,7 +48,7 @@ S_pfinet_siocgifconf (io_t port,
error_t err = 0;
struct ifconf ifc;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (amount == (vm_size_t) -1)
{
/* Get the needed buffer length. */
@@ -57,7 +57,7 @@ S_pfinet_siocgifconf (io_t port,
err = dev_ifconf ((char *) &ifc);
if (err)
{
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return -err;
}
amount = ifc.ifc_len;
@@ -88,6 +88,6 @@ S_pfinet_siocgifconf (io_t port,
*ifr = ifc.ifc_buf;
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
diff --git a/pfinet/pfinet.h b/pfinet/pfinet.h
index 050ba6f7..66353956 100644
--- a/pfinet/pfinet.h
+++ b/pfinet/pfinet.h
@@ -28,9 +28,10 @@
#include <hurd/trivfs.h>
#include <sys/mman.h>
#include <sys/socket.h>
+#include <pthread.h>
-extern struct mutex global_lock;
-extern struct mutex net_bh_lock;
+extern pthread_mutex_t global_lock;
+extern pthread_mutex_t net_bh_lock;
struct port_bucket *pfinet_bucket;
struct port_class *addrport_class;
@@ -75,7 +76,7 @@ struct sock_user *make_sock_user (struct socket *, int, int, int);
error_t make_sockaddr_port (struct socket *, int,
mach_port_t *, mach_msg_type_name_t *);
void init_devices (void);
-any_t net_bh_worker (any_t);
+void *net_bh_worker (void *);
void init_time (void);
void ip_rt_add (short, u_long, u_long, u_long, struct device *,
u_short, u_long);
diff --git a/pfinet/sched.c b/pfinet/sched.c
index 37e4ecbd..89927741 100644
--- a/pfinet/sched.c
+++ b/pfinet/sched.c
@@ -23,9 +23,9 @@
#include <linux/sched.h>
#include <linux/interrupt.h>
-struct mutex global_lock = MUTEX_INITIALIZER;
-struct mutex net_bh_lock = MUTEX_INITIALIZER;
-struct condition net_bh_wakeup = CONDITION_INITIALIZER;
+pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t net_bh_lock = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t net_bh_wakeup = PTHREAD_COND_INITIALIZER;
struct task_struct current_contents; /* zeros are right default values */
@@ -55,16 +55,16 @@ sock_wake_async (struct socket *sock, int how)
queue, or dropped, without synchronizing with RPC service threads.
(The RPC service threads lock out the running of net_bh, but not
the queuing/dropping of packets in netif_rx.) */
-any_t
-net_bh_worker (any_t arg)
+void *
+net_bh_worker (void *arg)
{
- __mutex_lock (&net_bh_lock);
+ pthread_mutex_lock (&net_bh_lock);
while (1)
{
- condition_wait (&net_bh_wakeup, &net_bh_lock);
- __mutex_lock (&global_lock);
+ pthread_cond_wait (&net_bh_wakeup, &net_bh_lock);
+ pthread_mutex_lock (&global_lock);
net_bh ();
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
/*NOTREACHED*/
return 0;
diff --git a/pfinet/socket-ops.c b/pfinet/socket-ops.c
index b4172dc4..3f8b7fbc 100644
--- a/pfinet/socket-ops.c
+++ b/pfinet/socket-ops.c
@@ -60,7 +60,7 @@ S_socket_create (struct trivfs_protid *master,
if (protocol < 0)
return EPROTONOSUPPORT;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task_protid (master);
@@ -97,7 +97,7 @@ S_socket_create (struct trivfs_protid *master,
ports_port_deref (user);
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -112,10 +112,10 @@ S_socket_listen (struct sock_user *user, int queue_limit)
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = - (*user->sock->ops->listen) (user->sock, queue_limit);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -136,7 +136,7 @@ S_socket_accept (struct sock_user *user,
sock = user->sock;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
@@ -169,7 +169,7 @@ S_socket_accept (struct sock_user *user,
sock_release (newsock);
}
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -186,14 +186,14 @@ S_socket_connect (struct sock_user *user,
sock = user->sock;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = - (*sock->ops->connect) (sock, &addr->address, addr->address.sa_len,
sock->flags);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* MiG should do this for us, but it doesn't. */
if (!err)
@@ -213,11 +213,11 @@ S_socket_bind (struct sock_user *user,
if (! addr)
return EADDRNOTAVAIL;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = - (*user->sock->ops->bind) (user->sock,
&addr->address, addr->address.sa_len);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* MiG should do this for us, but it doesn't. */
if (!err)
@@ -234,10 +234,10 @@ S_socket_name (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
make_sockaddr_port (user->sock, 0, addr_port, addr_port_name);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -251,10 +251,10 @@ S_socket_peername (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = make_sockaddr_port (user->sock, 1, addr_port, addr_port_name);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -268,7 +268,7 @@ S_socket_connect2 (struct sock_user *user1,
if (!user1 || !user2)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user1);
@@ -280,7 +280,7 @@ S_socket_connect2 (struct sock_user *user1,
else
err = - (*user1->sock->ops->socketpair) (user1->sock, user2->sock);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* MiG should do this for us, but it doesn't. */
if (!err)
@@ -362,10 +362,10 @@ S_socket_shutdown (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = - (*user->sock->ops->shutdown) (user->sock, direction);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -382,7 +382,7 @@ S_socket_getopt (struct sock_user *user,
if (! user)
return EOPNOTSUPP;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
int len = *datalen;
@@ -391,7 +391,7 @@ S_socket_getopt (struct sock_user *user,
(user->sock, level, option, *data, &len);
*datalen = len;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* XXX option data not properly typed, needs byte-swapping for netmsgserver.
Most options are ints, some like IP_OPTIONS are bytesex-neutral. */
@@ -414,14 +414,14 @@ S_socket_setopt (struct sock_user *user,
/* XXX option data not properly typed, needs byte-swapping for netmsgserver.
Most options are ints, some like IP_OPTIONS are bytesex-neutral. */
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
err = - (level == SOL_SOCKET ? sock_setsockopt
: *user->sock->ops->setsockopt)
(user->sock, level, option, data, datalen);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -452,12 +452,12 @@ S_socket_send (struct sock_user *user,
if (nports != 0 || controllen != 0)
return EINVAL;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
if (user->sock->flags & O_NONBLOCK)
m.msg_flags |= MSG_DONTWAIT;
sent = (*user->sock->ops->sendmsg) (user->sock, &m, datalen, 0);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
/* MiG should do this for us, but it doesn't. */
if (addr && sent >= 0)
@@ -513,12 +513,12 @@ S_socket_recv (struct sock_user *user,
iov.iov_base = *data;
iov.iov_len = amount;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
become_task (user);
if (user->sock->flags & O_NONBLOCK)
flags |= MSG_DONTWAIT;
err = (*user->sock->ops->recvmsg) (user->sock, &m, amount, flags, 0);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (err < 0)
err = -err;
diff --git a/pfinet/socket.c b/pfinet/socket.c
index d56c1794..23a2dd91 100644
--- a/pfinet/socket.c
+++ b/pfinet/socket.c
@@ -43,13 +43,13 @@ sock_alloc (void)
{
static ino_t nextino; /* locked by global_lock */
struct socket *sock;
- struct condition *c;
+ pthread_cond_t *c;
- sock = malloc (sizeof *sock + sizeof (struct condition));
+ sock = malloc (sizeof *sock + sizeof (pthread_cond_t));
if (!sock)
return 0;
c = (void *) &sock[1];
- condition_init (c);
+ pthread_cond_init (c, NULL);
bzero (sock, sizeof *sock);
sock->state = SS_UNCONNECTED;
sock->identity = MACH_PORT_NULL;
@@ -120,7 +120,7 @@ clean_socketport (void *arg)
{
struct sock_user *const user = arg;
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
sock_release (user->sock);
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
diff --git a/pfinet/timer-emul.c b/pfinet/timer-emul.c
index 6eb20bc4..5a503597 100644
--- a/pfinet/timer-emul.c
+++ b/pfinet/timer-emul.c
@@ -18,6 +18,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+/* Do not include glue-include/linux/errno.h */
+#define _HACK_ERRNO_H
+
#include <linux/timer.h>
#include <asm/system.h>
#include <linux/sched.h>
@@ -31,8 +34,8 @@ volatile struct mapped_time_value *mapped_time;
struct timer_list *timers;
thread_t timer_thread = 0;
-static int
-timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
+static void *
+timer_function (void *this_is_a_pointless_variable_with_a_rather_long_name)
{
mach_port_t recv;
int wait = 0;
@@ -41,7 +44,7 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
timer_thread = mach_thread_self ();
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
int jiff = jiffies;
@@ -53,13 +56,13 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
else
wait = ((timers->expires - jiff) * 1000) / HZ;
- __mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
mach_msg (NULL, (MACH_RCV_MSG | MACH_RCV_INTERRUPT
| (wait == -1 ? 0 : MACH_RCV_TIMEOUT)),
0, 0, recv, wait, MACH_PORT_NULL);
- __mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (timers->expires < jiffies)
{
@@ -78,7 +81,7 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name)
}
}
- return 0;
+ return NULL;
}
@@ -157,6 +160,7 @@ init_time ()
{
error_t err;
struct timeval tp;
+ pthread_t thread;
err = maptime_map (0, 0, &mapped_time);
if (err)
@@ -167,5 +171,12 @@ init_time ()
root_jiffies = (long long) tp.tv_sec * HZ
+ ((long long) tp.tv_usec * HZ) / 1000000;
- cthread_detach (cthread_fork ((cthread_fn_t) timer_function, 0));
+ err = pthread_create (&thread, NULL, timer_function, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
diff --git a/pfinet/tunnel.c b/pfinet/tunnel.c
index 6f9e1498..cf907f59 100644
--- a/pfinet/tunnel.c
+++ b/pfinet/tunnel.c
@@ -21,7 +21,7 @@
#include "pfinet.h"
#include <hurd.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <fcntl.h>
#include <device/device.h>
#include <device/net_status.h>
@@ -47,9 +47,9 @@ struct tunnel_device
file_t underlying;
struct iouser *user;
struct sk_buff_head xq; /* Transmit queue. */
- struct condition wait; /* For read and select. */
- struct condition select_alert; /* For read and select. */
- struct mutex lock; /* For read and select. */
+ pthread_cond_t wait; /* For read and select. */
+ pthread_cond_t select_alert; /* For read and select. */
+ pthread_mutex_t lock; /* For read and select. */
int read_blocked; /* For read and select. */
struct device dev;
struct net_device_stats stats;
@@ -117,7 +117,7 @@ tunnel_xmit (struct sk_buff *skb, struct device *dev)
assert (tdev);
- __mutex_lock (&tdev->lock);
+ pthread_mutex_lock (&tdev->lock);
/* Avoid unlimited growth. */
if (skb_queue_len(&tdev->xq) > 128)
@@ -134,11 +134,11 @@ tunnel_xmit (struct sk_buff *skb, struct device *dev)
if (tdev->read_blocked)
{
tdev->read_blocked = 0;
- condition_broadcast (&tdev->wait);
- condition_broadcast (&tdev->select_alert);
+ pthread_cond_broadcast (&tdev->wait);
+ pthread_cond_broadcast (&tdev->select_alert);
}
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return 0;
}
@@ -211,9 +211,9 @@ setup_tunnel_device (char *name, struct device **device)
if (err)
error (2, err, "%s", tdev->dev.name);
- __mutex_init (&tdev->lock);
- condition_init (&tdev->wait);
- condition_init (&tdev->select_alert);
+ pthread_mutex_init (&tdev->lock, NULL);
+ pthread_cond_init (&tdev->wait, NULL);
+ pthread_cond_init (&tdev->select_alert, NULL);
/* This call adds the device to the `dev_base' chain,
initializes its `ifindex' member (which matters!),
@@ -294,20 +294,20 @@ trivfs_S_io_read (struct trivfs_protid *cred,
tdev = (struct tunnel_device *) cred->po->cntl->hook;
- __mutex_lock (&tdev->lock);
+ pthread_mutex_lock (&tdev->lock);
while (skb_queue_len(&tdev->xq) == 0)
{
if (cred->po->openmodes & O_NONBLOCK)
{
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return EWOULDBLOCK;
}
tdev->read_blocked = 1;
- if (hurd_condition_wait (&tdev->wait, &tdev->lock))
+ if (pthread_hurd_cond_wait_np (&tdev->wait, &tdev->lock))
{
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return EINTR;
}
/* See term/users.c for possible race? */
@@ -327,7 +327,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
if (*data == MAP_FAILED)
{
dev_kfree_skb (skb);
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return ENOMEM;
}
}
@@ -340,7 +340,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
/* Set atime, see term/users.c */
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return 0;
}
@@ -375,9 +375,9 @@ trivfs_S_io_write (struct trivfs_protid *cred,
tdev = (struct tunnel_device *) cred->po->cntl->hook;
- __mutex_lock (&tdev->lock);
+ pthread_mutex_lock (&tdev->lock);
- __mutex_lock (&net_bh_lock);
+ pthread_mutex_lock (&net_bh_lock);
skb = alloc_skb (datalen, GFP_ATOMIC);
skb->len = datalen;
skb->dev = &tdev->dev;
@@ -388,11 +388,11 @@ trivfs_S_io_write (struct trivfs_protid *cred,
skb->mac.raw = skb->data;
skb->protocol = htons (ETH_P_IP);
netif_rx (skb);
- __mutex_unlock (&net_bh_lock);
+ pthread_mutex_unlock (&net_bh_lock);
*amount = datalen;
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return 0;
}
@@ -418,7 +418,7 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
tdev = (struct tunnel_device *) cred->po->cntl->hook;
- __mutex_lock (&tdev->lock);
+ pthread_mutex_lock (&tdev->lock);
/* XXX: Now return the length of the next entry in the queue.
From the BSD manual:
@@ -442,7 +442,7 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
else
*amount = 0;
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return 0;
}
@@ -474,23 +474,23 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if (*type == 0)
return 0;
- __mutex_lock (&tdev->lock);
+ pthread_mutex_lock (&tdev->lock);
while (1)
{
if (skb_queue_len (&tdev->xq) != 0)
{
*type = SELECT_READ;
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
tdev->read_blocked = 1;
- if (hurd_condition_wait (&tdev->select_alert, &tdev->lock))
+ if (pthread_hurd_cond_wait_np (&tdev->select_alert, &tdev->lock))
{
*type = 0;
- __mutex_unlock (&tdev->lock);
+ pthread_mutex_unlock (&tdev->lock);
return EINTR;
}
}
diff --git a/pflocal/Makefile b/pflocal/Makefile
index 78b4c3f9..bfc2f4e8 100644
--- a/pflocal/Makefile
+++ b/pflocal/Makefile
@@ -25,7 +25,8 @@ SRCS = connq.c io.c pflocal.c socket.c pf.c sock.c sserver.c
MIGSTUBS = ioServer.o socketServer.o
OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
-HURDLIBS = pipe trivfs iohelp fshelp threads ports ihash shouldbeinlibc
+HURDLIBS = pipe trivfs iohelp fshelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
diff --git a/pflocal/connq.c b/pflocal/connq.c
index 17dae14c..bf937652 100644
--- a/pflocal/connq.c
+++ b/pflocal/connq.c
@@ -18,7 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <cthreads.h>
+#include <pthread.h>
#include <assert.h>
#include "connq.h"
@@ -33,14 +33,14 @@ struct connq
unsigned max;
/* Threads that have done an accept on this queue wait on this condition. */
- struct condition listeners;
+ pthread_cond_t listeners;
unsigned num_listeners;
/* Threads that have done a connect on this queue wait on this condition. */
- struct condition connectors;
+ pthread_cond_t connectors;
unsigned num_connectors;
- struct mutex lock;
+ pthread_mutex_t lock;
};
/* ---------------------------------------------------------------- */
@@ -65,7 +65,7 @@ connq_request_init (struct connq_request *req, struct sock *sock)
static void
connq_request_enqueue (struct connq *cq, struct connq_request *req)
{
- assert (! mutex_try_lock (&cq->lock));
+ assert (pthread_mutex_trylock (&cq->lock));
req->next = NULL;
*cq->tail = req;
@@ -81,7 +81,7 @@ connq_request_dequeue (struct connq *cq)
{
struct connq_request *req;
- assert (! mutex_try_lock (&cq->lock));
+ assert (pthread_mutex_trylock (&cq->lock));
assert (cq->head);
req = cq->head;
@@ -117,9 +117,9 @@ connq_create (struct connq **cq)
new->num_listeners = 0;
new->num_connectors = 0;
- mutex_init (&new->lock);
- condition_init (&new->listeners);
- condition_init (&new->connectors);
+ pthread_mutex_init (&new->lock, NULL);
+ pthread_cond_init (&new->listeners, NULL);
+ pthread_cond_init (&new->connectors, NULL);
*cq = new;
return 0;
@@ -147,18 +147,18 @@ connq_listen (struct connq *cq, int noblock, struct sock **sock)
{
error_t err = 0;
- mutex_lock (&cq->lock);
+ pthread_mutex_lock (&cq->lock);
if (noblock && cq->count == 0 && cq->num_connectors == 0)
{
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return EWOULDBLOCK;
}
if (! sock && (cq->count > 0 || cq->num_connectors > 0))
/* The caller just wants to know if a connection ready. */
{
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return 0;
}
@@ -172,10 +172,10 @@ connq_listen (struct connq *cq, int noblock, struct sock **sock)
if (cq->num_connectors > 0)
/* Someone is waiting for an acceptor. Signal that we can
service their request. */
- condition_signal (&cq->connectors);
+ pthread_cond_signal (&cq->connectors);
do
- if (hurd_condition_wait (&cq->listeners, &cq->lock))
+ if (pthread_hurd_cond_wait_np (&cq->listeners, &cq->lock))
{
cq->num_listeners--;
err = EINTR;
@@ -198,7 +198,7 @@ connq_listen (struct connq *cq, int noblock, struct sock **sock)
else could. (This case is rare but possible: it would require
one thread to do a select on the socket and a second to do an
accept.) */
- condition_signal (&cq->listeners);
+ pthread_cond_signal (&cq->listeners);
else
/* There is no one else to process the request and the connection
has now been initiated. This is not actually a problem as even
@@ -209,7 +209,7 @@ connq_listen (struct connq *cq, int noblock, struct sock **sock)
;
out:
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return err;
}
@@ -220,7 +220,7 @@ connq_listen (struct connq *cq, int noblock, struct sock **sock)
error_t
connq_connect (struct connq *cq, int noblock)
{
- mutex_lock (&cq->lock);
+ pthread_mutex_lock (&cq->lock);
/* Check for listeners after we've locked CQ for good. */
@@ -229,7 +229,7 @@ connq_connect (struct connq *cq, int noblock)
/* We are in non-blocking mode and would have to wait to secure an
entry in the listen queue. */
{
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return EWOULDBLOCK;
}
@@ -238,14 +238,14 @@ connq_connect (struct connq *cq, int noblock)
while (cq->count + cq->num_connectors > cq->max + cq->num_listeners)
/* The queue is full and there is no immediate listener to service
us. Block until we can get a slot. */
- if (hurd_condition_wait (&cq->connectors, &cq->lock))
+ if (pthread_hurd_cond_wait_np (&cq->connectors, &cq->lock))
{
cq->num_connectors --;
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return EINTR;
}
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return 0;
}
@@ -263,7 +263,7 @@ connq_connect_complete (struct connq *cq, struct sock *sock)
connq_request_init (req, sock);
- mutex_lock (&cq->lock);
+ pthread_mutex_lock (&cq->lock);
assert (cq->num_connectors > 0);
cq->num_connectors --;
@@ -276,26 +276,26 @@ connq_connect_complete (struct connq *cq, struct sock *sock)
thread dequeues this request. */
{
cq->num_listeners --;
- condition_signal (&cq->listeners);
+ pthread_cond_signal (&cq->listeners);
}
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
}
/* Follow up to connq_connect. Cancel the connect. */
void
connq_connect_cancel (struct connq *cq)
{
- mutex_lock (&cq->lock);
+ pthread_mutex_lock (&cq->lock);
assert (cq->num_connectors > 0);
cq->num_connectors --;
if (cq->count + cq->num_connectors >= cq->max + cq->num_listeners)
/* A connector is blocked and could use the spot we reserved. */
- condition_signal (&cq->connectors);
+ pthread_cond_signal (&cq->connectors);
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
}
/* Set CQ's queue length to LENGTH. */
@@ -304,7 +304,7 @@ connq_set_length (struct connq *cq, int max)
{
int omax;
- mutex_lock (&cq->lock);
+ pthread_mutex_lock (&cq->lock);
omax = cq->max;
cq->max = max;
@@ -313,9 +313,9 @@ connq_set_length (struct connq *cq, int max)
/* This is an increase in the number of connection slots which has
made some slots available and there are waiting threads. Wake
them up. */
- condition_broadcast (&cq->listeners);
+ pthread_cond_broadcast (&cq->listeners);
- mutex_unlock (&cq->lock);
+ pthread_mutex_unlock (&cq->lock);
return 0;
}
diff --git a/pflocal/io.c b/pflocal/io.c
index b2ae7593..f67052f3 100644
--- a/pflocal/io.c
+++ b/pflocal/io.c
@@ -186,14 +186,14 @@ S_io_select (struct sock_user *user,
*select_type &= SELECT_READ | SELECT_WRITE;
sock = user->sock;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (sock->listen_queue)
/* Sock is used for accepting connections, not I/O. For these, you can
only select for reading, which will block until a connection request
comes along. */
{
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
*select_type &= SELECT_READ;
@@ -233,17 +233,17 @@ S_io_select (struct sock_user *user,
pipe_acquire_reader (read_pipe);
if (pipe_wait_readable (read_pipe, 1, 1) != EWOULDBLOCK)
ready |= SELECT_READ; /* Data immediately readable (or error). */
- mutex_unlock (&read_pipe->lock);
+ pthread_mutex_unlock (&read_pipe->lock);
}
if (valid & SELECT_WRITE)
{
pipe_acquire_writer (write_pipe);
if (pipe_wait_writable (write_pipe, 1) != EWOULDBLOCK)
ready |= SELECT_WRITE; /* Data immediately writable (or error). */
- mutex_unlock (&write_pipe->lock);
+ pthread_mutex_unlock (&write_pipe->lock);
}
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
if (ready)
/* No need to block, we've already got some results. */
@@ -294,30 +294,30 @@ S_io_stat (struct sock_user *user, struct stat *st)
/* As we try to be clever with large transfers, ask for them. */
st->st_blksize = vm_page_size * 16;
- mutex_lock (&sock->lock); /* Make sure the pipes don't go away... */
+ pthread_mutex_lock (&sock->lock); /* Make sure the pipes don't go away... */
rpipe = sock->read_pipe;
wpipe = sock->write_pipe;
if (rpipe)
{
- mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
copy_time (&rpipe->read_time, &st->st_atim.tv_sec, &st->st_atim.tv_nsec);
/* This seems useful. */
st->st_size = pipe_readable (rpipe, 1);
- mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
}
if (wpipe)
{
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
copy_time (&wpipe->write_time, &st->st_mtim.tv_sec, &st->st_mtim.tv_nsec);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
copy_time (&sock->change_time, &st->st_ctim.tv_sec, &st->st_ctim.tv_nsec);
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
return 0;
}
@@ -343,12 +343,12 @@ S_io_set_all_openmodes (struct sock_user *user, int bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
if (bits & O_NONBLOCK)
user->sock->flags |= SOCK_NONBLOCK;
else
user->sock->flags &= ~SOCK_NONBLOCK;
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return 0;
}
@@ -359,10 +359,10 @@ S_io_set_some_openmodes (struct sock_user *user, int bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
if (bits & O_NONBLOCK)
user->sock->flags |= SOCK_NONBLOCK;
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return 0;
}
@@ -373,10 +373,10 @@ S_io_clear_some_openmodes (struct sock_user *user, int bits)
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
if (bits & O_NONBLOCK)
user->sock->flags &= ~SOCK_NONBLOCK;
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return 0;
}
@@ -454,12 +454,12 @@ S_io_pathconf (struct sock_user *user, int name, int *value)
return EOPNOTSUPP;
else if (name == _PC_PIPE_BUF)
{
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
if (user->sock->write_pipe == NULL)
*value = 0;
else
*value = user->sock->write_pipe->write_atomic;
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return 0;
}
else
@@ -481,13 +481,13 @@ S_io_identity (struct sock_user *user,
if (server_id == MACH_PORT_NULL)
{
- static struct mutex server_id_lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t server_id_lock = PTHREAD_MUTEX_INITIALIZER;
- mutex_lock (&server_id_lock);
+ pthread_mutex_lock (&server_id_lock);
if (server_id == MACH_PORT_NULL) /* Recheck with the lock held. */
err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
&server_id);
- mutex_unlock (&server_id_lock);
+ pthread_mutex_unlock (&server_id_lock);
if (err)
return err;
@@ -495,11 +495,11 @@ S_io_identity (struct sock_user *user,
sock = user->sock;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (sock->id == MACH_PORT_NULL)
err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
&sock->id);
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
if (! err)
{
diff --git a/pflocal/sock.c b/pflocal/sock.c
index 292e4290..ac66eaca 100644
--- a/pflocal/sock.c
+++ b/pflocal/sock.c
@@ -19,7 +19,7 @@
#include <string.h> /* For memset() */
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/pipe.h>
@@ -38,7 +38,7 @@ sock_acquire_read_pipe (struct sock *sock, struct pipe **pipe)
{
error_t err = 0;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
*pipe = sock->read_pipe;
if (*pipe != NULL)
@@ -57,7 +57,7 @@ sock_acquire_read_pipe (struct sock *sock, struct pipe **pipe)
else
err = ENOTCONN;
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
return err;
}
@@ -70,7 +70,7 @@ sock_acquire_write_pipe (struct sock *sock, struct pipe **pipe)
{
error_t err = 0;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
*pipe = sock->write_pipe;
if (*pipe != NULL)
pipe_acquire_writer (*pipe); /* Do this before unlocking the sock! */
@@ -85,7 +85,7 @@ sock_acquire_write_pipe (struct sock *sock, struct pipe **pipe)
else
err = ENOTCONN;
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
return err;
}
@@ -123,7 +123,7 @@ sock_create (struct pipe_class *pipe_class, mode_t mode, struct sock **sock)
new->pipe_class = pipe_class;
new->addr = NULL;
memset (&new->change_time, 0, sizeof (new->change_time));
- mutex_init (&new->lock);
+ pthread_mutex_init (&new->lock, NULL);
*sock = new;
return 0;
@@ -148,7 +148,7 @@ _sock_norefs (struct sock *sock)
/* A sock should never have an address when it has 0 refs, as the
address should hold a reference to the sock! */
assert (sock->addr == NULL);
- mutex_unlock (&sock->lock); /* Unlock so sock_free can do stuff. */
+ pthread_mutex_unlock (&sock->lock); /* Unlock so sock_free can do stuff. */
sock_free (sock);
}
@@ -195,9 +195,9 @@ sock_create_port (struct sock *sock, mach_port_t *port)
ensure_sock_server ();
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
sock->refs++;
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
user->sock = sock;
@@ -214,7 +214,7 @@ struct addr
{
struct port_info pi;
struct sock *sock;
- struct mutex lock;
+ pthread_mutex_t lock;
};
struct port_class *addr_port_class;
@@ -227,18 +227,18 @@ addr_unbind (void *vaddr)
struct sock *sock;
struct addr *addr = vaddr;
- mutex_lock (&addr->lock);
+ pthread_mutex_lock (&addr->lock);
sock = addr->sock;
if (sock)
{
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
sock->addr = NULL;
addr->sock = NULL;
ports_port_deref_weak (addr);
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
sock_deref (sock);
}
- mutex_unlock (&addr->lock);
+ pthread_mutex_unlock (&addr->lock);
}
/* Cleanup after the address ADDR, which is going away... */
@@ -264,7 +264,7 @@ addr_create (struct addr **addr)
{
ensure_sock_server ();
(*addr)->sock = NULL;
- mutex_init (&(*addr)->lock);
+ pthread_mutex_init (&(*addr)->lock, NULL);
}
return err;
@@ -277,8 +277,8 @@ sock_bind (struct sock *sock, struct addr *addr)
error_t err = 0;
struct addr *old_addr;
- mutex_lock (&addr->lock);
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&addr->lock);
+ pthread_mutex_lock (&sock->lock);
old_addr = sock->addr;
if (addr && old_addr)
@@ -304,8 +304,8 @@ sock_bind (struct sock *sock, struct addr *addr)
}
}
- mutex_unlock (&sock->lock);
- mutex_unlock (&addr->lock);
+ pthread_mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&addr->lock);
return err;
}
@@ -341,11 +341,11 @@ ensure_addr (struct sock *sock, struct addr **addr)
error_t
addr_get_sock (struct addr *addr, struct sock **sock)
{
- mutex_lock (&addr->lock);
+ pthread_mutex_lock (&addr->lock);
*sock = addr->sock;
if (*sock)
(*sock)->refs++;
- mutex_unlock (&addr->lock);
+ pthread_mutex_unlock (&addr->lock);
return *sock ? 0 : EADDRNOTAVAIL;
}
@@ -356,9 +356,9 @@ sock_get_addr (struct sock *sock, struct addr **addr)
{
error_t err;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
err = ensure_addr (sock, addr);
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
return err; /* XXX */
}
@@ -368,7 +368,7 @@ sock_get_addr (struct sock *sock, struct addr **addr)
/* We hold this lock before we lock two sockets at once, to prevent someone
else trying to lock the same two sockets in the reverse order, resulting
in a deadlock. */
-static struct mutex socket_pair_lock;
+static pthread_mutex_t socket_pair_lock;
/* Connect SOCK1 and SOCK2. */
error_t
@@ -396,11 +396,11 @@ sock_connect (struct sock *sock1, struct sock *sock2)
/* Incompatible socket types. */
return EOPNOTSUPP; /* XXX?? */
- mutex_lock (&socket_pair_lock);
- mutex_lock (&sock1->lock);
+ pthread_mutex_lock (&socket_pair_lock);
+ pthread_mutex_lock (&sock1->lock);
if (sock1 != sock2)
/* If SOCK1 == SOCK2, then we get a fifo! */
- mutex_lock (&sock2->lock);
+ pthread_mutex_lock (&sock2->lock);
if ((sock1->flags & SOCK_CONNECTED) || (sock2->flags & SOCK_CONNECTED))
/* An already-connected socket. */
@@ -426,9 +426,9 @@ sock_connect (struct sock *sock1, struct sock *sock2)
}
if (sock1 != sock2)
- mutex_unlock (&sock2->lock);
- mutex_unlock (&sock1->lock);
- mutex_unlock (&socket_pair_lock);
+ pthread_mutex_unlock (&sock2->lock);
+ pthread_mutex_unlock (&sock1->lock);
+ pthread_mutex_unlock (&socket_pair_lock);
if (old_sock1_write_pipe)
{
@@ -450,7 +450,7 @@ sock_shutdown (struct sock *sock, unsigned flags)
struct pipe *read_pipe = NULL;
struct pipe *write_pipe = NULL;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
old_flags = sock->flags;
sock->flags |= flags;
@@ -469,7 +469,7 @@ sock_shutdown (struct sock *sock, unsigned flags)
}
/* Unlock SOCK here, as we may subsequently wake up other threads. */
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
if (read_pipe)
pipe_remove_reader (read_pipe);
diff --git a/pflocal/sock.h b/pflocal/sock.h
index 6bad8af8..fb2db5a4 100644
--- a/pflocal/sock.h
+++ b/pflocal/sock.h
@@ -22,7 +22,7 @@
#define __SOCK_H__
#include <assert.h>
-#include <cthreads.h> /* For mutexes */
+#include <pthread.h> /* For mutexes */
#include <sys/mman.h>
#include <sys/types.h>
@@ -42,7 +42,7 @@ struct sock_user
struct sock
{
int refs;
- struct mutex lock;
+ pthread_mutex_t lock;
/* What kind of socket this is. */
struct pipe_class *pipe_class;
@@ -118,11 +118,11 @@ void _sock_norefs (struct sock *sock);
static inline void __attribute__ ((unused))
sock_deref (struct sock *sock)
{
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (--sock->refs == 0)
_sock_norefs (sock);
else
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
}
/* Return a new socket just like TEMPLATE in SOCK. */
diff --git a/pflocal/socket.c b/pflocal/socket.c
index 64a80a46..46749fee 100644
--- a/pflocal/socket.c
+++ b/pflocal/socket.c
@@ -53,10 +53,10 @@ static error_t
ensure_connq (struct sock *sock)
{
error_t err = 0;
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (!sock->listen_queue)
err = connq_create (&sock->listen_queue);
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
return err;
}
@@ -105,7 +105,7 @@ S_socket_connect (struct sock_user *user, struct addr *addr)
/* For connection-oriented protocols, only connect with sockets that
are actually listening. */
{
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (sock->connect_queue)
/* SOCK is already doing a connect. */
err = EALREADY;
@@ -121,7 +121,7 @@ S_socket_connect (struct sock_user *user, struct addr *addr)
to do so will fail with EALREADY. */
sock->connect_queue = cq;
/* Unlock SOCK while waiting. */
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
err = connq_connect (peer->listen_queue,
sock->flags & SOCK_NONBLOCK);
@@ -139,7 +139,7 @@ S_socket_connect (struct sock_user *user, struct addr *addr)
sock_free (server);
}
- mutex_lock (&sock->lock);
+ pthread_mutex_lock (&sock->lock);
if (err)
connq_connect_cancel (peer->listen_queue);
}
@@ -149,7 +149,7 @@ S_socket_connect (struct sock_user *user, struct addr *addr)
sock->connect_queue = NULL;
}
- mutex_unlock (&sock->lock);
+ pthread_mutex_unlock (&sock->lock);
}
else
err = ECONNREFUSED;
@@ -425,7 +425,7 @@ S_socket_getopt (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
switch (level)
{
case SOL_SOCKET:
@@ -445,7 +445,7 @@ S_socket_getopt (struct sock_user *user,
ret = ENOPROTOOPT;
break;
}
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return ret;
}
@@ -459,14 +459,14 @@ S_socket_setopt (struct sock_user *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->sock->lock);
+ pthread_mutex_lock (&user->sock->lock);
switch (level)
{
default:
ret = ENOPROTOOPT;
break;
}
- mutex_unlock (&user->sock->lock);
+ pthread_mutex_unlock (&user->sock->lock);
return ret;
}
diff --git a/pflocal/sserver.c b/pflocal/sserver.c
index 7e00b323..9de0aa54 100644
--- a/pflocal/sserver.c
+++ b/pflocal/sserver.c
@@ -18,7 +18,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <cthreads.h>
+#include <pthread.h>
+#include <stdio.h>
#include <hurd/ports.h>
@@ -29,7 +30,7 @@ struct port_bucket *sock_port_bucket;
/* True if there are threads servicing sock requests. */
static int sock_server_active = 0;
-static spin_lock_t sock_server_active_lock = SPIN_LOCK_INITIALIZER;
+static pthread_spinlock_t sock_server_active_lock = PTHREAD_SPINLOCK_INITIALIZER;
/* A demuxer for socket operations. */
static int
@@ -45,8 +46,8 @@ sock_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp)
}
/* Handle socket requests while there are sockets around. */
-static void
-handle_sock_requests ()
+static void *
+handle_sock_requests (void *unused)
{
while (ports_count_bucket (sock_port_bucket) > 0)
{
@@ -56,12 +57,14 @@ handle_sock_requests ()
}
/* The last service thread is about to exist; make this known. */
- spin_lock (&sock_server_active_lock);
+ pthread_spin_lock (&sock_server_active_lock);
sock_server_active = 0;
- spin_unlock (&sock_server_active_lock);
+ pthread_spin_unlock (&sock_server_active_lock);
/* Let the whole joke start once again. */
ports_enable_bucket (sock_port_bucket);
+
+ return NULL;
}
/* Makes sure there are some request threads for sock operations, and starts
@@ -71,14 +74,23 @@ handle_sock_requests ()
void
ensure_sock_server ()
{
- spin_lock (&sock_server_active_lock);
+ pthread_t thread;
+ error_t err;
+
+ pthread_spin_lock (&sock_server_active_lock);
if (sock_server_active)
- spin_unlock (&sock_server_active_lock);
+ pthread_spin_unlock (&sock_server_active_lock);
else
{
sock_server_active = 1;
- spin_unlock (&sock_server_active_lock);
- cthread_detach (cthread_fork ((cthread_fn_t)handle_sock_requests,
- (any_t)0));
+ pthread_spin_unlock (&sock_server_active_lock);
+ err = pthread_create (&thread, NULL, handle_sock_requests, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
}
diff --git a/proc/Makefile b/proc/Makefile
index d54166d2..2eed13c1 100644
--- a/proc/Makefile
+++ b/proc/Makefile
@@ -31,7 +31,8 @@ MIGSFLAGS="-DPROCESS_INTRAN=pstruct_t reqport_find (process_t)" \
MIGSTUBS = processServer.o notifyServer.o \
ourmsgUser.o proc_excUser.o proc_excServer.o
OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
-HURDLIBS=threads ihash ports shouldbeinlibc
+HURDLIBS = ihash ports shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/proc/info.c b/proc/info.c
index f35ad166..40f9d210 100644
--- a/proc/info.c
+++ b/proc/info.c
@@ -467,7 +467,7 @@ S_proc_getprocinfo (struct proc *callerp,
/* Release GLOBAL_LOCK around time consuming bits, and more importatantly,
potential calls to P's msgport, which can block. */
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (*flags & PI_FETCH_TASKINFO)
{
@@ -618,7 +618,7 @@ S_proc_getprocinfo (struct proc *callerp,
*waits_len = waits_used;
/* Reacquire GLOBAL_LOCK to make the central locking code happy. */
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
return err;
}
diff --git a/proc/main.c b/proc/main.c
index f2cdfdf5..494169e7 100644
--- a/proc/main.c
+++ b/proc/main.c
@@ -42,16 +42,16 @@ message_demuxer (mach_msg_header_t *inp,
extern int proc_exc_server (mach_msg_header_t *, mach_msg_header_t *);
int status;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
status = (process_server (inp, outp)
|| notify_server (inp, outp)
|| ports_interrupt_server (inp, outp)
|| proc_exc_server (inp, outp));
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return status;
}
-struct mutex global_lock = MUTEX_INITIALIZER;
+pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
int
main (int argc, char **argv, char **envp)
diff --git a/proc/mgt.c b/proc/mgt.c
index 1180c700..7af9c1aa 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -106,7 +106,7 @@ S_proc_reauthenticate (struct proc *p, mach_port_t rendport)
naux_gids = sizeof (agbuf) / sizeof (uid_t);
/* Release the global lock while blocking on the auth server and client. */
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
err = auth_server_authenticate (authserver,
rendport, MACH_MSG_TYPE_COPY_SEND,
MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND,
@@ -114,7 +114,7 @@ S_proc_reauthenticate (struct proc *p, mach_port_t rendport)
&aux_uids, &naux_uids,
&gen_gids, &ngen_gids,
&aux_gids, &naux_gids);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (err)
return err;
@@ -565,7 +565,7 @@ allocate_proc (task_t task)
p->p_task = task;
p->p_msgport = MACH_PORT_NULL;
- condition_init (&p->p_wakeup);
+ pthread_cond_init (&p->p_wakeup, NULL);
return p;
}
@@ -756,7 +756,7 @@ process_has_exited (struct proc *p)
/* If an operation is in progress for this process, cause it
to wakeup and return now. */
if (p->p_waiting || p->p_msgportwait)
- condition_broadcast (&p->p_wakeup);
+ pthread_cond_broadcast (&p->p_wakeup);
p->p_dead = 1;
diff --git a/proc/msg.c b/proc/msg.c
index ff1dbc54..a6eca218 100644
--- a/proc/msg.c
+++ b/proc/msg.c
@@ -21,6 +21,7 @@
#include <hurd/startup.h>
#include <assert.h>
#include <stdlib.h>
+#include <stdio.h>
/* Check to see if process P is blocked trying to get the message
port of process AVAILP; if so, return its call. */
@@ -29,18 +30,18 @@ check_message_return (struct proc *p, void *availpaddr)
{
if (p->p_msgportwait)
{
- condition_broadcast (&p->p_wakeup);
+ pthread_cond_broadcast (&p->p_wakeup);
p->p_msgportwait = 0;
}
}
/* Register ourselves with init. */
-static any_t
-tickle_init (any_t initport)
+static void *
+tickle_init (void *initport)
{
startup_essential_task ((mach_port_t) initport, mach_task_self (),
MACH_PORT_NULL, "proc", master_host_port);
- return 0;
+ return NULL;
}
error_t
@@ -63,9 +64,21 @@ S_proc_setmsgport (struct proc *p,
p->p_checkmsghangs = 0;
if (p == startup_proc)
+ {
/* Init is single threaded, so we can't delay our reply for
the essential task RPC; spawn a thread to do it. */
- cthread_detach (cthread_fork (tickle_init, (any_t) msgport));
+ pthread_t thread;
+ error_t err;
+ err = pthread_create (&thread, NULL, tickle_init,
+ (void*) (uintptr_t) msgport);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
+ }
return 0;
}
@@ -77,7 +90,7 @@ check_message_dying (struct proc *p, struct proc *dyingp)
{
if (p->p_msgportwait)
{
- condition_broadcast (&p->p_wakeup);
+ pthread_cond_broadcast (&p->p_wakeup);
p->p_msgportwait = 0;
}
}
@@ -128,7 +141,7 @@ restart:
{
callerp->p_msgportwait = 1;
p->p_checkmsghangs = 1;
- cancel = hurd_condition_wait (&callerp->p_wakeup, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (&callerp->p_wakeup, &global_lock);
if (callerp->p_dead)
return EOPNOTSUPP;
if (cancel)
diff --git a/proc/proc.h b/proc/proc.h
index 7943e0be..247795dc 100644
--- a/proc/proc.h
+++ b/proc/proc.h
@@ -26,7 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <sys/mman.h>
#include <hurd/ports.h>
#include <hurd/ihash.h>
-#include <cthreads.h>
+#include <pthread.h>
struct proc
{
@@ -60,7 +60,7 @@ struct proc
/* Communication */
mach_port_t p_msgport; /* send right */
- struct condition p_wakeup;
+ pthread_cond_t p_wakeup;
/* Miscellaneous information */
vm_address_t p_argv, p_envp;
@@ -145,7 +145,7 @@ mach_port_t master_device_port;
mach_port_t generic_port; /* messages not related to a specific proc */
-struct mutex global_lock;
+pthread_mutex_t global_lock;
static inline void __attribute__ ((unused))
process_drop (struct proc *p)
diff --git a/proc/stubs.c b/proc/stubs.c
index de3a9b11..096e55ef 100644
--- a/proc/stubs.c
+++ b/proc/stubs.c
@@ -15,12 +15,13 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <cthreads.h>
+#include <pthread.h>
#include <stdlib.h>
#include <hurd/hurd_types.h>
#include <mach/message.h>
#include <string.h>
#include <assert.h>
+#include <stdio.h>
#include "proc.h"
@@ -41,8 +42,8 @@ struct msg_sig_post_request
/* Send the Mach message indicated by msg_spec. call cthread_exit
when it has been delivered. */
-static any_t
-blocking_message_send (any_t arg)
+static void *
+blocking_message_send (void *arg)
{
struct msg_sig_post_request *const req = arg;
error_t err;
@@ -146,8 +147,17 @@ send_signal (mach_port_t msgport,
struct msg_sig_post_request *copy = malloc (sizeof *copy);
if (copy)
{
+ pthread_t thread;
+ error_t err;
memcpy (copy, &message, sizeof message);
- cthread_detach (cthread_fork (blocking_message_send, copy));
+ err = pthread_create (&thread, NULL, blocking_message_send, copy);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
break;
}
diff --git a/proc/wait.c b/proc/wait.c
index 6fc94e83..824e6672 100644
--- a/proc/wait.c
+++ b/proc/wait.c
@@ -154,7 +154,7 @@ alert_parent (struct proc *p)
if (p->p_parent->p_waiting)
{
- condition_broadcast (&p->p_parent->p_wakeup);
+ pthread_cond_broadcast (&p->p_parent->p_wakeup);
p->p_parent->p_waiting = 0;
}
}
@@ -228,7 +228,7 @@ S_proc_wait (struct proc *p,
return EWOULDBLOCK;
p->p_waiting = 1;
- cancel = hurd_condition_wait (&p->p_wakeup, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (&p->p_wakeup, &global_lock);
if (p->p_dead)
return EOPNOTSUPP;
if (cancel)
@@ -252,7 +252,7 @@ S_proc_mark_stop (struct proc *p,
if (p->p_parent->p_waiting)
{
- condition_broadcast (&p->p_parent->p_wakeup);
+ pthread_cond_broadcast (&p->p_parent->p_wakeup);
p->p_parent->p_waiting = 0;
}
diff --git a/storeio/Makefile b/storeio/Makefile
index 0190be07..c1317587 100644
--- a/storeio/Makefile
+++ b/storeio/Makefile
@@ -23,6 +23,7 @@ target = storeio
SRCS = dev.c storeio.c open.c pager.c io.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = trivfs pager fshelp iohelp store threads ports ihash shouldbeinlibc
+HURDLIBS = trivfs pager fshelp iohelp store ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/storeio/dev.c b/storeio/dev.c
index 31b084f9..8f520cd2 100644
--- a/storeio/dev.c
+++ b/storeio/dev.c
@@ -173,10 +173,10 @@ dev_open (struct dev *dev)
if (!dev->inhibit_cache)
{
dev->buf_offs = -1;
- rwlock_init (&dev->io_lock);
+ pthread_rwlock_init (&dev->io_lock, NULL);
dev->block_mask = (1 << dev->store->log2_block_size) - 1;
dev->pager = 0;
- mutex_init (&dev->pager_lock);
+ pthread_mutex_init (&dev->pager_lock, NULL);
}
return 0;
@@ -218,9 +218,9 @@ dev_sync(struct dev *dev, int wait)
if (dev->pager != NULL)
pager_sync (dev->pager, wait);
- rwlock_writer_lock (&dev->io_lock);
+ pthread_rwlock_wrlock (&dev->io_lock);
err = dev_buf_discard (dev);
- rwlock_writer_unlock (&dev->io_lock);
+ pthread_rwlock_unlock (&dev->io_lock);
return err;
}
@@ -243,7 +243,7 @@ buffered_rw (struct dev *dev, off_t offs, size_t len, size_t *amount,
size_t io_offs = 0; /* Offset within this I/O operation. */
unsigned block_offs = offs & block_mask; /* Offset within a block. */
- rwlock_writer_lock (&dev->io_lock);
+ pthread_rwlock_wrlock (&dev->io_lock);
if (block_offs != 0)
/* The start of the I/O isn't block aligned. */
@@ -282,7 +282,7 @@ buffered_rw (struct dev *dev, off_t offs, size_t len, size_t *amount,
if (! err)
*amount = io_offs;
- rwlock_writer_unlock (&dev->io_lock);
+ pthread_rwlock_unlock (&dev->io_lock);
return err;
}
@@ -306,7 +306,7 @@ dev_rw (struct dev *dev, off_t offs, size_t len, size_t *amount,
else if (offs + len > dev->store->size)
len = dev->store->size - offs;
- rwlock_reader_lock (&dev->io_lock);
+ pthread_rwlock_rdlock (&dev->io_lock);
if (dev_buf_is_active (dev)
|| (offs & block_mask) != 0 || (len & block_mask) != 0)
/* Some non-aligned I/O has been done, or is needed, so we need to deal
@@ -314,14 +314,14 @@ dev_rw (struct dev *dev, off_t offs, size_t len, size_t *amount,
{
/* Acquire a writer lock instead of a reader lock. Note that other
writers may have acquired the lock by the time we get it. */
- rwlock_reader_unlock (&dev->io_lock);
+ pthread_rwlock_unlock (&dev->io_lock);
err = buffered_rw (dev, offs, len, amount, buf_rw, raw_rw);
}
else
/* Only block-aligned I/O is being done, so things are easy. */
{
err = (*raw_rw) (offs, 0, len, amount);
- rwlock_reader_unlock (&dev->io_lock);
+ pthread_rwlock_unlock (&dev->io_lock);
}
return err;
diff --git a/storeio/dev.h b/storeio/dev.h
index 23924ca5..139668a7 100644
--- a/storeio/dev.h
+++ b/storeio/dev.h
@@ -22,7 +22,7 @@
#include <mach.h>
#include <device/device.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <hurd/store.h>
#include <hurd/trivfs.h>
@@ -57,7 +57,7 @@ struct dev
/* This lock protects `store', `owner' and `nperopens'. The other
members never change after creation, except for those locked by
io_lock (below). */
- struct mutex lock;
+ pthread_mutex_t lock;
/* Nonzero iff the --no-cache flag was given.
If this is set, the remaining members are not used at all
@@ -71,7 +71,7 @@ struct dev
/* Lock to arbitrate I/O through this device. Block I/O can occur in
parallel, and requires only a reader-lock.
Non-block I/O is always serialized, and requires a writer-lock. */
- struct rwlock io_lock;
+ pthread_rwlock_t io_lock;
/* Non-block I/O is buffered through BUF. BUF_OFFS is the device offset
corresponding to the start of BUF (which holds one block); if it is -1,
@@ -81,7 +81,7 @@ struct dev
int buf_dirty;
struct pager *pager;
- struct mutex pager_lock;
+ pthread_mutex_t pager_lock;
};
static inline int
diff --git a/storeio/open.c b/storeio/open.c
index 805115ce..f6a641d7 100644
--- a/storeio/open.c
+++ b/storeio/open.c
@@ -35,7 +35,7 @@ open_create (struct dev *dev, struct open **open)
(*open)->dev = dev;
(*open)->offs = 0;
- mutex_init (&(*open)->lock);
+ pthread_mutex_init (&(*open)->lock, NULL);
return 0;
}
@@ -59,11 +59,11 @@ open_write (struct open *open, off_t offs, void *buf, size_t len,
if (offs < 0)
/* Use OPEN's offset. */
{
- mutex_lock (&open->lock);
+ pthread_mutex_lock (&open->lock);
err = dev_write (open->dev, open->offs, buf, len, amount);
if (! err)
open->offs += *amount;
- mutex_unlock (&open->lock);
+ pthread_mutex_unlock (&open->lock);
}
else
err = dev_write (open->dev, offs, buf, len, amount);
@@ -81,11 +81,11 @@ open_read (struct open *open, off_t offs, size_t amount,
if (offs < 0)
/* Use OPEN's offset. */
{
- mutex_lock (&open->lock);
+ pthread_mutex_lock (&open->lock);
err = dev_read (open->dev, open->offs, amount, buf, len);
if (! err)
open->offs += *len;
- mutex_unlock (&open->lock);
+ pthread_mutex_unlock (&open->lock);
}
else
err = dev_read (open->dev, offs, amount, buf, len);
@@ -101,7 +101,7 @@ open_seek (struct open *open, off_t offs, int whence, off_t *new_offs)
{
error_t err = 0;
- mutex_lock (&open->lock);
+ pthread_mutex_lock (&open->lock);
switch (whence)
{
@@ -121,7 +121,7 @@ open_seek (struct open *open, off_t offs, int whence, off_t *new_offs)
err = EINVAL;
}
- mutex_unlock (&open->lock);
+ pthread_mutex_unlock (&open->lock);
return err;
}
diff --git a/storeio/open.h b/storeio/open.h
index cbac2a37..78ad95ca 100644
--- a/storeio/open.h
+++ b/storeio/open.h
@@ -36,7 +36,7 @@ struct open
off_t offs;
/* A lock used to control write access to OFFS. */
- struct mutex lock;
+ pthread_mutex_t lock;
};
/* Returns a new per-open structure for the device DEV in OPEN. If an error
diff --git a/storeio/pager.c b/storeio/pager.c
index 1fb1d07e..cbae7eb6 100644
--- a/storeio/pager.c
+++ b/storeio/pager.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
+#include <stdio.h>
#include "dev.h"
@@ -127,22 +128,26 @@ void
pager_clear_user_data (struct user_pager_info *upi)
{
struct dev *dev = (struct dev *)upi;
- mutex_lock (&dev->pager_lock);
+ pthread_mutex_lock (&dev->pager_lock);
dev->pager = 0;
- mutex_unlock (&dev->pager_lock);
+ pthread_mutex_unlock (&dev->pager_lock);
}
static struct port_bucket *pager_port_bucket = 0;
/* A top-level function for the paging thread that just services paging
requests. */
-static void
-service_paging_requests (any_t arg)
+static void *
+service_paging_requests (void *arg)
{
+ (void) arg;
+
for (;;)
ports_manage_port_operations_multithread (pager_port_bucket,
pager_demuxer,
1000 * 30, 1000 * 60 * 5, 0);
+
+ return NULL;
}
/* Initialize paging for this device. */
@@ -151,18 +156,27 @@ init_dev_paging ()
{
if (! pager_port_bucket)
{
- static struct mutex pager_global_lock = MUTEX_INITIALIZER;
+ static pthread_mutex_t pager_global_lock = PTHREAD_MUTEX_INITIALIZER;
- mutex_lock (&pager_global_lock);
+ pthread_mutex_lock (&pager_global_lock);
if (pager_port_bucket == NULL)
{
+ pthread_t thread;
+ error_t err;
+
pager_port_bucket = ports_create_bucket ();
/* Make a thread to service paging requests. */
- cthread_detach (cthread_fork ((cthread_fn_t)service_paging_requests,
- (any_t)0));
+ err = pthread_create (&thread, NULL, service_paging_requests, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
}
- mutex_unlock (&pager_global_lock);
+ pthread_mutex_unlock (&pager_global_lock);
}
}
@@ -226,7 +240,7 @@ dev_get_memory_object (struct dev *dev, vm_prot_t prot, memory_object_t *memobj)
init_dev_paging ();
- mutex_lock (&dev->pager_lock);
+ pthread_mutex_lock (&dev->pager_lock);
if (dev->pager == NULL)
{
@@ -235,7 +249,7 @@ dev_get_memory_object (struct dev *dev, vm_prot_t prot, memory_object_t *memobj)
1, MEMORY_OBJECT_COPY_DELAY);
if (dev->pager == NULL)
{
- mutex_unlock (&dev->pager_lock);
+ pthread_mutex_unlock (&dev->pager_lock);
return errno;
}
created = 1;
@@ -247,7 +261,7 @@ dev_get_memory_object (struct dev *dev, vm_prot_t prot, memory_object_t *memobj)
/* Pager is currently being destroyed, try again. */
{
dev->pager = 0;
- mutex_unlock (&dev->pager_lock);
+ pthread_mutex_unlock (&dev->pager_lock);
return dev_get_memory_object (dev, prot, memobj);
}
else
@@ -258,7 +272,7 @@ dev_get_memory_object (struct dev *dev, vm_prot_t prot, memory_object_t *memobj)
if (created)
ports_port_deref (dev->pager);
- mutex_unlock (&dev->pager_lock);
+ pthread_mutex_unlock (&dev->pager_lock);
}
return err;
diff --git a/storeio/storeio.c b/storeio/storeio.c
index a88c8e43..3bde9644 100644
--- a/storeio/storeio.c
+++ b/storeio/storeio.c
@@ -128,7 +128,7 @@ main (int argc, char *argv[])
struct storeio_argp_params params;
bzero (&device, sizeof device);
- mutex_init (&device.lock);
+ pthread_mutex_init (&device.lock, NULL);
params.dev = &device;
argp_parse (&argp, argc, argv, 0, 0, &params);
@@ -221,7 +221,7 @@ check_open_hook (struct trivfs_control *trivfs_control,
if (!err && dev_is_readonly (dev) && (flags & O_WRITE))
return EROFS;
- mutex_lock (&dev->lock);
+ pthread_mutex_lock (&dev->lock);
if (dev->store == NULL)
{
/* Try and open the store. */
@@ -231,7 +231,7 @@ check_open_hook (struct trivfs_control *trivfs_control,
error, as this allows stat to work correctly. XXX */
err = 0;
}
- mutex_unlock (&dev->lock);
+ pthread_mutex_unlock (&dev->lock);
return err;
}
@@ -244,10 +244,10 @@ open_hook (struct trivfs_peropen *peropen)
if (dev->store)
{
- mutex_lock (&dev->lock);
+ pthread_mutex_lock (&dev->lock);
if (dev->nperopens++ == 0)
err = store_clear_flags (dev->store, STORE_INACTIVE);
- mutex_unlock (&dev->lock);
+ pthread_mutex_unlock (&dev->lock);
if (!err)
err = open_create (dev, (struct open **)&peropen->hook);
}
@@ -261,10 +261,10 @@ close_hook (struct trivfs_peropen *peropen)
if (peropen->hook)
{
- mutex_lock (&dev->lock);
+ pthread_mutex_lock (&dev->lock);
if (--dev->nperopens == 0)
store_set_flags (dev->store, STORE_INACTIVE);
- mutex_unlock (&dev->lock);
+ pthread_mutex_unlock (&dev->lock);
open_free (peropen->hook);
}
}
@@ -325,7 +325,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
int nosync = (flags & FSYS_GOAWAY_NOSYNC);
struct port_class *root_port_class = fsys->protid_class;
- mutex_lock (&device->lock);
+ pthread_mutex_lock (&device->lock);
if (device->store == NULL)
/* The device is not actually open.
@@ -337,7 +337,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
err = ports_inhibit_class_rpcs (root_port_class);
if (err == EINTR || (err && !force))
{
- mutex_unlock (&device->lock);
+ pthread_mutex_unlock (&device->lock);
return err;
}
@@ -370,7 +370,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
/* Allow normal operations to proceed. */
ports_enable_class (root_port_class);
ports_resume_class_rpcs (root_port_class);
- mutex_unlock (&device->lock);
+ pthread_mutex_unlock (&device->lock);
/* Complain that there are still users. */
return EBUSY;
diff --git a/term/Makefile b/term/Makefile
index 4aa6e3df..025a9b39 100644
--- a/term/Makefile
+++ b/term/Makefile
@@ -25,7 +25,8 @@ makemode := server
target = term
SRCS = devio.c munge.c users.c main.c ptyio.c hurdio.c xinl.c
-HURDLIBS = trivfs fshelp iohelp threads ports ihash shouldbeinlibc
+HURDLIBS = trivfs fshelp iohelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
OBJS = $(subst .c,.o,$(SRCS)) termServer.o device_replyServer.o tioctlServer.o ourmsgUser.o
include ../Makeconf
diff --git a/term/devio.c b/term/devio.c
index 8aa960b9..7c7d8fd8 100644
--- a/term/devio.c
+++ b/term/devio.c
@@ -51,7 +51,7 @@
#include <device/device.h>
#include <device/device_request.h>
#include <device/tty_status.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/ports.h>
@@ -313,7 +313,7 @@ device_write_reply_inband (mach_port_t replypt,
if (replypt != phys_reply_writes)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
output_pending = 0;
@@ -322,8 +322,8 @@ device_write_reply_inband (mach_port_t replypt,
if (amount >= npending_output)
{
npending_output = 0;
- condition_broadcast (outputq->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (outputq->wait);
+ pthread_cond_broadcast (&select_alert);
}
else
{
@@ -340,7 +340,7 @@ device_write_reply_inband (mach_port_t replypt,
else
devio_start_output ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -356,7 +356,7 @@ device_read_reply_inband (mach_port_t replypt,
if (replypt != phys_reply)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
input_pending = 0;
@@ -376,7 +376,7 @@ device_read_reply_inband (mach_port_t replypt,
else if (error_code == D_WOULD_BLOCK)
{
devio_desert_dtr ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -390,7 +390,7 @@ device_read_reply_inband (mach_port_t replypt,
else
input_pending = 1;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -542,7 +542,7 @@ device_open_reply (mach_port_t replyport,
if (replyport != phys_reply)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
assert (open_pending != NOTPENDING);
@@ -556,7 +556,7 @@ device_open_reply (mach_port_t replyport,
phys_reply_pi = 0;
open_pending = NOTPENDING;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -574,7 +574,7 @@ device_open_reply (mach_port_t replyport,
if (err)
{
open_pending = NOTPENDING;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
phys_reply_writes = ports_get_send_right (phys_reply_writes_pi);
@@ -604,7 +604,7 @@ device_open_reply (mach_port_t replyport,
devio_desert_dtr ();
open_pending = NOTPENDING;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -735,7 +735,7 @@ ports_do_mach_notify_send_once (mach_port_t notify)
{
error_t err;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (notify == phys_reply_writes)
{
@@ -778,7 +778,7 @@ ports_do_mach_notify_send_once (mach_port_t notify)
else
err = EOPNOTSUPP;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
diff --git a/term/hurdio.c b/term/hurdio.c
index b1d0c944..368c2322 100644
--- a/term/hurdio.c
+++ b/term/hurdio.c
@@ -26,8 +26,9 @@
#include <errno.h>
#include <error.h>
#include <string.h>
+#include <stdio.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/ports.h>
@@ -68,7 +69,7 @@ thread_t writer_thread = MACH_PORT_NULL;
/* This flag is set if the output was suspended. */
static int output_stopped;
-static struct condition hurdio_writer_condition;
+static pthread_cond_t hurdio_writer_condition;
/* Hold the amount of bytes that are currently in the progress of
being written. May be set to zero while you hold the global lock
@@ -77,24 +78,41 @@ size_t npending_output;
/* True if we should assert the dtr. */
int assert_dtr;
-static struct condition hurdio_assert_dtr_condition;
+static pthread_cond_t hurdio_assert_dtr_condition;
/* Forward */
static error_t hurdio_desert_dtr ();
-static any_t hurdio_reader_loop (any_t arg);
-static any_t hurdio_writer_loop (any_t arg);
+static void *hurdio_reader_loop (void *arg);
+static void *hurdio_writer_loop (void *arg);
static error_t hurdio_set_bits (struct termios *state);
static error_t
hurdio_init (void)
{
- condition_init (&hurdio_writer_condition);
- condition_init (&hurdio_assert_dtr_condition);
+ pthread_t thread;
+ error_t err;
+
+ pthread_cond_init (&hurdio_writer_condition, NULL);
+ pthread_cond_init (&hurdio_assert_dtr_condition, NULL);
- cthread_detach (cthread_fork (hurdio_reader_loop, 0));
- cthread_detach (cthread_fork (hurdio_writer_loop, 0));
+ err = pthread_create (&thread, NULL, hurdio_reader_loop, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
+ err = pthread_create (&thread, NULL, hurdio_writer_loop, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
return 0;
}
@@ -129,7 +147,7 @@ static void
wait_for_dtr (void)
{
while (!assert_dtr)
- hurd_condition_wait (&hurdio_assert_dtr_condition, &global_lock);
+ pthread_cond_wait (&hurdio_assert_dtr_condition, &global_lock);
assert_dtr = 0;
if (tty_arg == 0)
@@ -165,15 +183,15 @@ wait_for_dtr (void)
report_carrier_on ();
/* Signal that the writer thread should resume its work. */
- condition_broadcast (&hurdio_writer_condition);
+ pthread_cond_broadcast (&hurdio_writer_condition);
}
}
/* Read and enqueue input characters. Is also responsible to assert
the DTR if necessary. */
-static any_t
-hurdio_reader_loop (any_t arg)
+static void *
+hurdio_reader_loop (void *arg)
{
/* XXX The input buffer has 256 bytes. */
#define BUFFER_SIZE 256
@@ -182,7 +200,7 @@ hurdio_reader_loop (any_t arg)
size_t datalen;
error_t err;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
reader_thread = mach_thread_self ();
while (1)
@@ -190,14 +208,14 @@ hurdio_reader_loop (any_t arg)
/* We can only start when the DTR has been asserted. */
while (ioport == MACH_PORT_NULL)
wait_for_dtr ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
data = buffer;
datalen = BUFFER_SIZE;
err = io_read (ioport, &data, &datalen, -1, BUFFER_SIZE);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
/* Error or EOF can mean the carrier has been dropped. */
if (err || !datalen)
hurdio_desert_dtr ();
@@ -223,8 +241,8 @@ hurdio_reader_loop (any_t arg)
/* Output characters. */
-static any_t
-hurdio_writer_loop (any_t arg)
+static void *
+hurdio_writer_loop (void *arg)
{
/* XXX The output buffer has 256 bytes. */
#define BUFFER_SIZE 256
@@ -236,7 +254,7 @@ hurdio_writer_loop (any_t arg)
int npending_output_copy;
mach_port_t ioport_copy;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
writer_thread = mach_thread_self ();
while (1)
@@ -244,7 +262,7 @@ hurdio_writer_loop (any_t arg)
while (writer_thread != MACH_PORT_NULL
&& (ioport == MACH_PORT_NULL || !qsize (outputq)
|| output_stopped))
- hurd_condition_wait (&hurdio_writer_condition, &global_lock);
+ pthread_cond_wait (&hurdio_writer_condition, &global_lock);
if (writer_thread == MACH_PORT_NULL) /* A sign to die. */
return 0;
@@ -269,10 +287,10 @@ hurdio_writer_loop (any_t arg)
*bufp++ = dequeue (outputq);
/* Submit all the outstanding characters to the I/O port. */
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
err = io_write (ioport_copy, pending_output, npending_output_copy,
-1, &amount);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
mach_port_mod_refs (mach_task_self (), ioport_copy,
MACH_PORT_RIGHT_SEND, -1);
@@ -285,8 +303,8 @@ hurdio_writer_loop (any_t arg)
if (amount >= npending_output)
{
npending_output = 0;
- condition_broadcast (outputq->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (outputq->wait);
+ pthread_cond_broadcast (&select_alert);
}
else
{
@@ -321,7 +339,7 @@ hurdio_start_output ()
}
output_stopped = 0;
}
- condition_broadcast (&hurdio_writer_condition);
+ pthread_cond_broadcast (&hurdio_writer_condition);
return 0;
}
@@ -468,7 +486,7 @@ hurdio_assert_dtr ()
if (ioport == MACH_PORT_NULL)
{
assert_dtr = 1;
- condition_signal (&hurdio_assert_dtr_condition);
+ pthread_cond_signal (&hurdio_assert_dtr_condition);
}
return 0;
diff --git a/term/main.c b/term/main.c
index e15fee53..9cc32d4d 100644
--- a/term/main.c
+++ b/term/main.c
@@ -211,7 +211,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
break;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
(*bottom->fini) ();
tty_type = v->type;
@@ -232,7 +232,7 @@ parse_opt (int opt, char *arg, struct argp_state *state)
error_t err = (*bottom->init) ();
if (err == 0 && (termflags & TTY_OPEN))
err = (*bottom->assert_dtr) ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
break;
@@ -413,7 +413,7 @@ main (int argc, char **argv)
memset (&termstate, 0, sizeof (termstate));
termflags = NO_CARRIER | NO_OWNER;
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
/* Initialize status from underlying node. */
err = io_stat ((*ourcntl)->underlying, &st);
@@ -441,8 +441,8 @@ main (int argc, char **argv)
if (err)
error (1, err, "Initializing bottom handler");
- condition_init (&carrier_alert);
- condition_init (&select_alert);
+ pthread_cond_init (&carrier_alert, NULL);
+ pthread_cond_init (&select_alert, NULL);
/* Launch. */
ports_manage_port_operations_multithread (term_bucket, demuxer, 0, 0, 0);
diff --git a/term/munge.c b/term/munge.c
index 660a99bd..7e08e2d2 100644
--- a/term/munge.c
+++ b/term/munge.c
@@ -707,7 +707,7 @@ drain_output ()
while ((qsize (outputq) || (*bottom->pending_output_size) ())
&& (!(termflags & NO_CARRIER) || (termstate.c_cflag & CLOCAL))
&& !cancel)
- cancel = hurd_condition_wait (outputq->wait, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (outputq->wait, &global_lock);
return cancel ? EINTR : 0;
}
@@ -726,10 +726,10 @@ create_queue (int size, int lowat, int hiwat)
q->hiwat = hiwat;
q->cs = q->ce = q->array;
q->arraylen = size;
- q->wait = malloc (sizeof (struct condition));
+ q->wait = malloc (sizeof (pthread_cond_t));
assert (q->wait);
- condition_init (q->wait);
+ pthread_cond_init (q->wait, NULL);
return q;
}
diff --git a/term/ptyio.c b/term/ptyio.c
index b02cda3f..0f5ddb01 100644
--- a/term/ptyio.c
+++ b/term/ptyio.c
@@ -30,9 +30,9 @@
static int pty_read_blocked = 0;
/* Wake this up when tty output occurs and pty_read_blocked is set */
-static struct condition pty_read_wakeup = CONDITION_INITIALIZER;
+static pthread_cond_t pty_read_wakeup = PTHREAD_COND_INITIALIZER;
-static struct condition pty_select_wakeup = CONDITION_INITIALIZER;
+static pthread_cond_t pty_select_wakeup = PTHREAD_COND_INITIALIZER;
/* Set if "dtr" is on. */
static int dtr_on = 0;
@@ -70,11 +70,11 @@ pty_open_hook (struct trivfs_control *cntl,
if ((flags & (O_READ|O_WRITE)) == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (ptyopen)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBUSY;
}
@@ -87,7 +87,7 @@ pty_open_hook (struct trivfs_control *cntl,
control_byte = 0;
pktnostop = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -95,23 +95,23 @@ pty_open_hook (struct trivfs_control *cntl,
error_t
pty_po_create_hook (struct trivfs_peropen *po)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (po->openmodes & (O_READ | O_WRITE))
{
nptyperopens++;
report_carrier_on ();
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
error_t
pty_po_destroy_hook (struct trivfs_peropen *po)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((po->openmodes & (O_READ | O_WRITE)) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
nptyperopens--;
@@ -120,7 +120,7 @@ pty_po_destroy_hook (struct trivfs_peropen *po)
ptyopen = 0;
report_carrier_off ();
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -130,8 +130,8 @@ wake_reader ()
if (pty_read_blocked)
{
pty_read_blocked = 0;
- condition_broadcast (&pty_read_wakeup);
- condition_broadcast (&pty_select_wakeup);
+ pthread_cond_broadcast (&pty_read_wakeup);
+ pthread_cond_broadcast (&pty_select_wakeup);
}
}
@@ -306,11 +306,11 @@ pty_io_read (struct trivfs_protid *cred,
{
int size;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_READ) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
@@ -320,13 +320,13 @@ pty_io_read (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_NONBLOCK)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
pty_read_blocked = 1;
- if (hurd_condition_wait (&pty_read_wakeup, &global_lock))
+ if (pthread_hurd_cond_wait_np (&pty_read_wakeup, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -370,7 +370,7 @@ pty_io_read (struct trivfs_protid *cred,
*cp++ = dequeue (outputq);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -385,11 +385,11 @@ pty_io_write (struct trivfs_protid *cred,
int i, flush;
int cancel = 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_WRITE) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
@@ -400,14 +400,14 @@ pty_io_write (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_NONBLOCK)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
- cancel = hurd_condition_wait (inputq->wait, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (inputq->wait, &global_lock);
}
if (cancel)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -433,7 +433,7 @@ pty_io_write (struct trivfs_protid *cred,
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
*amount = datalen;
return 0;
@@ -443,7 +443,7 @@ pty_io_write (struct trivfs_protid *cred,
error_t
pty_io_readable (size_t *amt)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (control_byte)
{
*amt = 1;
@@ -452,7 +452,7 @@ pty_io_readable (size_t *amt)
}
else
*amt = qsize (outputq);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -466,7 +466,7 @@ pty_io_select (struct trivfs_protid *cred, mach_port_t reply,
if (*type == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
@@ -483,17 +483,17 @@ pty_io_select (struct trivfs_protid *cred, mach_port_t reply,
if (avail)
{
*type = avail;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
pty_read_blocked = 1;
- if (hurd_condition_wait (&pty_select_wakeup, &global_lock))
+ if (pthread_hurd_cond_wait_np (&pty_select_wakeup, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -508,7 +508,7 @@ S_tioctl_tiocsig (io_t port,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
drop_output ();
clear_queue (inputq);
@@ -516,7 +516,7 @@ S_tioctl_tiocsig (io_t port,
ptyio_notice_input_flushed ();
send_signal (sig);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return 0;
@@ -533,7 +533,7 @@ S_tioctl_tiocpkt (io_t port,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!!mode == !!packet_mode)
err = 0;
@@ -546,7 +546,7 @@ S_tioctl_tiocpkt (io_t port,
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -563,7 +563,7 @@ S_tioctl_tiocucntl (io_t port,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!!mode == !!user_ioctl_mode)
err = 0;
@@ -576,7 +576,7 @@ S_tioctl_tiocucntl (io_t port,
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -592,13 +592,13 @@ S_tioctl_tiocremote (io_t port,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
remote_input_mode = how;
drop_output ();
clear_queue (inputq);
clear_queue (rawq);
ptyio_notice_input_flushed ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return 0;
}
@@ -612,7 +612,7 @@ S_tioctl_tiocext (io_t port,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (mode && !external_processing)
{
if (packet_mode)
@@ -633,7 +633,7 @@ S_tioctl_tiocext (io_t port,
external_processing = 0;
termstate.c_lflag &= ~EXTPROC;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return 0;
}
diff --git a/term/term.h b/term/term.h
index 2df20337..f154d4c0 100644
--- a/term/term.h
+++ b/term/term.h
@@ -18,7 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
-#include <cthreads.h>
+#include <pthread.h>
#include <assert.h>
#include <errno.h>
#include <hurd/trivfs.h>
@@ -95,16 +95,16 @@ long termflags;
#define QUEUE_HIWAT 8100
/* Global lock */
-struct mutex global_lock;
+pthread_mutex_t global_lock;
/* Wakeup when NO_CARRIER turns off */
-struct condition carrier_alert;
+pthread_cond_t carrier_alert;
/* Wakeup for select */
-struct condition select_alert;
+pthread_cond_t select_alert;
/* Wakeup for pty select, if not null */
-struct condition *pty_select_alert;
+pthread_cond_t *pty_select_alert;
/* Bucket for all our ports. */
struct port_bucket *term_bucket;
@@ -188,7 +188,7 @@ struct queue
int hiwat;
short *cs, *ce;
int arraylen;
- struct condition *wait;
+ pthread_cond_t *wait;
quoted_char array[0];
};
@@ -227,10 +227,10 @@ clear_queue (struct queue *q)
{
q->susp = 0;
q->cs = q->ce = q->array;
- condition_broadcast (q->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (q->wait);
+ pthread_cond_broadcast (&select_alert);
if (q == inputq && pty_select_alert != NULL)
- condition_broadcast (pty_select_alert);
+ pthread_cond_broadcast (pty_select_alert);
}
#endif /* Use extern inlines. */
@@ -254,10 +254,10 @@ dequeue_quote (struct queue *q)
beep = 1;
if (beep)
{
- condition_broadcast (q->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (q->wait);
+ pthread_cond_broadcast (&select_alert);
if (q == inputq && pty_select_alert != NULL)
- condition_broadcast (pty_select_alert);
+ pthread_cond_broadcast (pty_select_alert);
else if (q == outputq)
call_asyncs (O_WRITE);
}
@@ -288,12 +288,12 @@ enqueue_internal (struct queue **qp, quoted_char c)
if (qsize (q) == 1)
{
- condition_broadcast (q->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (q->wait);
+ pthread_cond_broadcast (&select_alert);
if (q == inputq)
{
if (pty_select_alert != NULL)
- condition_broadcast (pty_select_alert);
+ pthread_cond_broadcast (pty_select_alert);
call_asyncs (O_READ);
}
}
@@ -349,10 +349,10 @@ queue_erase (struct queue *q)
beep = 1;
if (beep)
{
- condition_broadcast (q->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (q->wait);
+ pthread_cond_broadcast (&select_alert);
if (q == inputq && pty_select_alert != NULL)
- condition_broadcast (pty_select_alert);
+ pthread_cond_broadcast (pty_select_alert);
}
return answer;
}
diff --git a/term/users.c b/term/users.c
index 4ec2b810..9fc1dc23 100644
--- a/term/users.c
+++ b/term/users.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <fcntl.h>
#include <hurd/trivfs.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <stdio.h>
#include <hurd/iohelp.h>
@@ -70,7 +70,7 @@ int foreground_id;
struct winsize window_size;
static int sigs_in_progress;
-static struct condition input_sig_wait = CONDITION_INITIALIZER;
+static pthread_cond_t input_sig_wait = PTHREAD_COND_INITIALIZER;
static int input_sig_wakeup;
static error_t carrier_error;
@@ -114,7 +114,7 @@ check_access_hook (struct trivfs_control *cntl,
{
struct stat st;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
st.st_uid = term_owner;
st.st_gid = term_group;
@@ -126,7 +126,7 @@ check_access_hook (struct trivfs_control *cntl,
if (fshelp_access (&st, S_IWRITE, user) == 0)
*allowed |= O_WRITE;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
error_t (*trivfs_check_access_hook) (struct trivfs_control *, struct iouser *,
@@ -148,7 +148,7 @@ open_hook (struct trivfs_control *cntl,
if ((flags & (O_READ|O_WRITE)) == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(termflags & TTY_OPEN))
{
@@ -174,7 +174,7 @@ open_hook (struct trivfs_control *cntl,
if (termflags & EXCL_USE)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBUSY;
}
}
@@ -190,7 +190,7 @@ open_hook (struct trivfs_control *cntl,
err = (*bottom->assert_dtr) ();
if (err)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
}
@@ -199,11 +199,11 @@ open_hook (struct trivfs_control *cntl,
while (((termflags & NO_CARRIER) && !(termstate.c_cflag & CLOCAL))
&& !(flags & O_NONBLOCK)
&& !cancel)
- cancel = hurd_condition_wait (&carrier_alert, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (&carrier_alert, &global_lock);
if (cancel)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -224,7 +224,7 @@ open_hook (struct trivfs_control *cntl,
(*bottom->gwinsz) (&window_size);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
error_t (*trivfs_check_open_hook) (struct trivfs_control *,
@@ -237,10 +237,10 @@ pi_create_hook (struct trivfs_protid *cred)
if (cred->pi.class == pty_class)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (cred->hook)
((struct protid_hook *)cred->hook)->refcnt++;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -252,7 +252,7 @@ pi_destroy_hook (struct trivfs_protid *cred)
if (cred->pi.class == pty_class)
return;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (cred->hook)
{
assert (((struct protid_hook *)cred->hook)->refcnt > 0);
@@ -261,7 +261,7 @@ pi_destroy_hook (struct trivfs_protid *cred)
bug. */
/* free (cred->hook) */;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
void (*trivfs_protid_destroy_hook) (struct trivfs_protid *) = pi_destroy_hook;
@@ -271,7 +271,7 @@ po_create_hook (struct trivfs_peropen *po)
if (po->cntl == ptyctl)
return pty_po_create_hook (po);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
nperopens++;
if (po->openmodes & O_ASYNC)
{
@@ -279,7 +279,7 @@ po_create_hook (struct trivfs_peropen *po)
num_icky_async_peropens++;
call_asyncs (O_READ | O_WRITE);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
error_t (*trivfs_peropen_create_hook) (struct trivfs_peropen *) =
@@ -294,7 +294,7 @@ po_destroy_hook (struct trivfs_peropen *po)
return;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((po->openmodes & O_ASYNC) && --num_icky_async_peropens == 0)
termflags &= ~ICKY_ASYNC;
@@ -316,7 +316,7 @@ po_destroy_hook (struct trivfs_peropen *po)
termflags &= ~TTY_OPEN;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
void (*trivfs_peropen_destroy_hook) (struct trivfs_peropen *)
= po_destroy_hook;
@@ -363,7 +363,7 @@ S_term_getctty (mach_port_t arg,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -374,7 +374,7 @@ S_term_getctty (mach_port_t arg,
err = 0;
}
ports_port_deref (cred);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -436,16 +436,16 @@ S_term_open_ctty (mach_port_t arg,
return EINVAL;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!cred->po->openmodes & (O_READ|O_WRITE))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
err = EBADF;
}
else
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
err = trivfs_protid_dup (cred, &newcred);
if (!err)
@@ -489,7 +489,7 @@ trivfs_S_file_chown (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
/* XXX */
st.st_uid = term_owner;
@@ -517,7 +517,7 @@ trivfs_S_file_chown (struct trivfs_protid *cred,
err = 0;
out:
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -534,7 +534,7 @@ trivfs_S_file_chmod (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!cred->isroot)
{
/* XXX */
@@ -558,7 +558,7 @@ trivfs_S_file_chmod (struct trivfs_protid *cred,
err = 0;
out:
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -584,25 +584,25 @@ trivfs_S_io_write (struct trivfs_protid *cred,
if (cred->pi.class == pty_class)
return pty_io_write (cred, data, datalen, amt);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
/* Check for errors first. */
if ((cred->po->openmodes & O_WRITE) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
if ((termstate.c_lflag & TOSTOP) && !fg_p (cred))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBACKGROUND;
}
if ((termflags & NO_CARRIER) && !(termstate.c_cflag & CLOCAL))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EIO;
}
@@ -618,7 +618,8 @@ trivfs_S_io_write (struct trivfs_protid *cred,
else
{
if (!qavail (outputq))
- cancel = hurd_condition_wait (outputq->wait, &global_lock);
+ cancel = pthread_hurd_cond_wait_np (outputq->wait,
+ &global_lock);
}
}
if (cancel)
@@ -636,7 +637,7 @@ trivfs_S_io_write (struct trivfs_protid *cred,
call_asyncs (O_WRITE);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ((cancel && datalen && !*amt) ? (err ?: EINTR) : 0);
}
@@ -662,17 +663,17 @@ trivfs_S_io_read (struct trivfs_protid *cred,
if (cred->pi.class == pty_class)
return pty_io_read (cred, data, datalen, amount);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_READ) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
if (!fg_p (cred))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBACKGROUND;
}
@@ -681,20 +682,20 @@ trivfs_S_io_read (struct trivfs_protid *cred,
if ((termflags & NO_CARRIER) && !(termstate.c_cflag & CLOCAL) || !amount)
{
/* Return EOF, Posix.1 7.1.1.10. */
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
*datalen = 0;
return 0;
}
if (cred->po->openmodes & O_NONBLOCK)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
- if (hurd_condition_wait (inputq->wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (inputq->wait, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
@@ -713,9 +714,9 @@ trivfs_S_io_read (struct trivfs_protid *cred,
if (sigs_in_progress)
{
input_sig_wakeup++;
- if (hurd_condition_wait (&input_sig_wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (&input_sig_wait, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -778,7 +779,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
call_asyncs (O_READ);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return !*datalen && cancel ? EINTR : 0;
}
@@ -835,16 +836,16 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
if (cred->pi.class == pty_class)
return pty_io_readable (amt);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_READ) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
*amt = qsize (inputq);
if (remote_input_mode && *amt)
--*amt;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -868,7 +869,7 @@ trivfs_S_io_revoke (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!cred->isroot)
{
@@ -881,12 +882,12 @@ trivfs_S_io_revoke (struct trivfs_protid *cred,
err = fshelp_isowner (&st, cred->user);
if (err)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_inhibit_bucket_rpcs (term_bucket);
ports_class_iterate (cred->pi.class, iterator_function);
@@ -917,9 +918,9 @@ S_tioctl_tiocmodg (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = (*bottom->mdmstate) (state);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -942,14 +943,14 @@ S_tioctl_tiocmods (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_SET, state);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -971,7 +972,7 @@ S_tioctl_tiocexcl (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -981,7 +982,7 @@ S_tioctl_tiocexcl (io_t port)
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1003,7 +1004,7 @@ S_tioctl_tiocnxcl (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
@@ -1012,7 +1013,7 @@ S_tioctl_tiocnxcl (io_t port)
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1035,7 +1036,7 @@ S_tioctl_tiocflush (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1054,7 +1055,7 @@ S_tioctl_tiocflush (io_t port,
err = drop_output ();
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1078,7 +1079,7 @@ S_tioctl_tiocgeta (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
modes[0] = termstate.c_iflag;
modes[1] = termstate.c_oflag;
modes[2] = termstate.c_cflag;
@@ -1086,7 +1087,7 @@ S_tioctl_tiocgeta (io_t port,
memcpy (ccs, termstate.c_cc, NCCS);
speeds[0] = termstate.__ispeed;
speeds[1] = termstate.__ospeed;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return 0;
@@ -1115,7 +1116,7 @@ set_state (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1179,7 +1180,7 @@ set_state (io_t port,
}
leave:
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1257,10 +1258,10 @@ S_tioctl_tiocsetd (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
if (disc != 0)
err = ENXIO;
@@ -1288,16 +1289,16 @@ S_tioctl_tiocdrain (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & O_WRITE))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return EBADF;
}
err = drain_output ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1320,7 +1321,7 @@ S_tioctl_tiocswinsz (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1341,7 +1342,7 @@ S_tioctl_tiocswinsz (io_t port,
send_signal (SIGWINCH);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -1362,9 +1363,9 @@ S_tioctl_tiocgwinsz (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
*size = window_size;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return 0;
@@ -1388,9 +1389,9 @@ S_tioctl_tiocmget (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = (*bottom->mdmstate) (bits);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1414,13 +1415,13 @@ S_tioctl_tiocmset (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_SET, bits);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1443,12 +1444,12 @@ S_tioctl_tiocmbic (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_BIC, bits);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1472,13 +1473,13 @@ S_tioctl_tiocmbis (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_BIS, bits);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
}
@@ -1500,7 +1501,7 @@ S_tioctl_tiocstart (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1513,7 +1514,7 @@ S_tioctl_tiocstart (io_t port)
if (err)
termflags = old_termflags;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1535,7 +1536,7 @@ S_tioctl_tiocstop (io_t port)
ports_port_deref (cred);
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1547,7 +1548,7 @@ S_tioctl_tiocstop (io_t port)
if (err)
termflags = old_termflags;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1571,7 +1572,7 @@ S_tioctl_tiocsti (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
/* BSD returns EACCES if this is not our controlling terminal,
but we have no way to do that. (And I don't think it actually
@@ -1584,7 +1585,7 @@ S_tioctl_tiocsti (io_t port,
input_character (c);
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1608,7 +1609,7 @@ S_tioctl_tiocoutq (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
@@ -1617,7 +1618,7 @@ S_tioctl_tiocoutq (io_t port,
*queue_size = qsize (outputq) + (*bottom->pending_output_size) ();
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1641,7 +1642,7 @@ S_tioctl_tiocspgrp (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
@@ -1650,7 +1651,7 @@ S_tioctl_tiocspgrp (io_t port,
foreground_id = -pgrp;
err = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1674,7 +1675,7 @@ S_tioctl_tiocgpgrp (io_t port,
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (termflags & NO_OWNER)
ret = ENOTTY; /* that's what BSD says... */
else
@@ -1682,7 +1683,7 @@ S_tioctl_tiocgpgrp (io_t port,
*pgrp = - foreground_id;
ret = 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return ret;
@@ -1705,12 +1706,12 @@ S_tioctl_tioccdtr (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_BIC, TIOCM_DTR);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1733,12 +1734,12 @@ S_tioctl_tiocsdtr (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->mdmctl) (MDMCTL_BIS, TIOCM_DTR);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1761,12 +1762,12 @@ S_tioctl_tioccbrk (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->clear_break) ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1789,12 +1790,12 @@ S_tioctl_tiocsbrk (io_t port)
return EOPNOTSUPP;
}
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
else
err = (*bottom->set_break) ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
ports_port_deref (cred);
return err;
@@ -1807,13 +1808,13 @@ trivfs_S_file_set_size (struct trivfs_protid *cred,
{
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_WRITE) == 0)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1836,9 +1837,9 @@ trivfs_S_io_get_openmodes (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
*bits = cred->po->openmodes;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1855,7 +1856,7 @@ trivfs_S_io_set_all_openmodes (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
obits = cred->po->openmodes;
if ((obits & O_ASYNC) && --num_icky_async_peropens == 0)
@@ -1871,7 +1872,7 @@ trivfs_S_io_set_all_openmodes (struct trivfs_protid *cred,
call_asyncs (O_READ | O_WRITE);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1887,7 +1888,7 @@ trivfs_S_io_set_some_openmodes (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
obits = cred->po->openmodes;
cred->po->openmodes |= (bits & HONORED_STATE_MODES);
if ((bits & O_ASYNC) && !(obits & O_ASYNC))
@@ -1896,7 +1897,7 @@ trivfs_S_io_set_some_openmodes (struct trivfs_protid *cred,
num_icky_async_peropens++;
call_asyncs (O_READ | O_WRITE);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1909,11 +1910,11 @@ trivfs_S_io_clear_some_openmodes (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((cred->po->openmodes & O_ASYNC) && --num_icky_async_peropens == 0)
termflags &= ~ICKY_ASYNC;
cred->po->openmodes &= ~(bits & HONORED_STATE_MODES);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1927,10 +1928,10 @@ trivfs_S_io_mod_owner (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
termflags &= ~NO_OWNER;
foreground_id = owner;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1943,14 +1944,14 @@ trivfs_S_io_get_owner (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (termflags & NO_OWNER)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENOTTY;
}
*owner = foreground_id;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1963,15 +1964,15 @@ trivfs_S_io_get_icky_async_id (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
*id = async_icky_id;
*idtype = MACH_MSG_TYPE_MAKE_SEND;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1985,10 +1986,10 @@ trivfs_S_io_async (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBADF;
}
ar = malloc (sizeof (struct async_req));
@@ -1997,7 +1998,7 @@ trivfs_S_io_async (struct trivfs_protid *cred,
async_requests = ar;
*id = async_id;
*idtype = MACH_MSG_TYPE_MAKE_SEND;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -2018,7 +2019,7 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if ((cred->po->openmodes & O_WRITE) == 0)
*type &= ~SELECT_WRITE;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
@@ -2031,12 +2032,12 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if (available == 0)
{
ports_interrupt_self_on_port_death (cred, reply);
- if (hurd_condition_wait (&select_alert, &global_lock) == 0)
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock) == 0)
continue;
}
*type = available;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return available ? 0 : EINTR;
}
}
@@ -2066,7 +2067,7 @@ report_sig_end ()
if ((sigs_in_progress == 0) && input_sig_wakeup)
{
input_sig_wakeup = 0;
- condition_broadcast (&input_sig_wait);
+ pthread_cond_broadcast (&input_sig_wait);
}
}
@@ -2091,9 +2092,9 @@ call_asyncs (int dir)
if ((termflags & ICKY_ASYNC) && !(termflags & NO_OWNER))
{
report_sig_start ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
hurd_sig_post (foreground_id, SIGIO, async_icky_id);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
report_sig_end ();
}
@@ -2125,9 +2126,9 @@ send_signal (int signo)
{
right = ports_get_send_right (cttyid);
report_sig_start ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
hurd_sig_post (foreground_id, signo, right);
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
report_sig_end ();
mach_port_deallocate (mach_task_self (), right);
}
@@ -2148,14 +2149,14 @@ void
report_carrier_on ()
{
termflags &= ~NO_CARRIER;
- condition_broadcast (&carrier_alert);
+ pthread_cond_broadcast (&carrier_alert);
}
void
report_carrier_error (error_t err)
{
carrier_error = err;
- condition_broadcast (&carrier_alert);
+ pthread_cond_broadcast (&carrier_alert);
}
kern_return_t
diff --git a/tmpfs/Makefile b/tmpfs/Makefile
index 7730949c..fdcae349 100644
--- a/tmpfs/Makefile
+++ b/tmpfs/Makefile
@@ -23,6 +23,7 @@ target = tmpfs
SRCS = tmpfs.c node.c dir.c pager-stubs.c
OBJS = $(SRCS:.c=.o) default_pagerUser.o
# XXX The shared libdiskfs requires libstore even though we don't use it here.
-HURDLIBS = diskfs pager iohelp fshelp store threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs pager iohelp fshelp store ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/tmpfs/dir.c b/tmpfs/dir.c
index c0ae9785..45a07521 100644
--- a/tmpfs/dir.c
+++ b/tmpfs/dir.c
@@ -210,13 +210,13 @@ diskfs_lookup_hard (struct node *dp,
}
else
{
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup ((ino_t) (intptr_t) dddn, np);
if (type == (LOOKUP|SPEC_DOTDOT))
diskfs_nrele (dp);
else
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
*np = 0;
diff --git a/tmpfs/node.c b/tmpfs/node.c
index bce15370..9d5f9b75 100644
--- a/tmpfs/node.c
+++ b/tmpfs/node.c
@@ -38,18 +38,18 @@ diskfs_alloc_node (struct node *dp, mode_t mode, struct node **npp)
dn = calloc (1, sizeof *dn);
if (dn == 0)
return ENOSPC;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
if (round_page (tmpfs_space_used + sizeof *dn) / vm_page_size
> tmpfs_page_limit)
{
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
free (dn);
return ENOSPC;
}
dn->gen = gen++;
++num_files;
tmpfs_space_used += sizeof *dn;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
dn->type = IFTODT (mode & S_IFMT);
return diskfs_cached_lookup ((ino_t) (uintptr_t) dn, npp);
@@ -179,13 +179,13 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
np = diskfs_make_node (dn);
np->cache_id = (ino_t) (uintptr_t) dn;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
dn->hnext = all_nodes;
if (dn->hnext)
dn->hnext->dn->hprevp = &dn->hnext;
dn->hprevp = &all_nodes;
all_nodes = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
st = &np->dn_stat;
memset (st, 0, sizeof *st);
@@ -212,7 +212,7 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
recompute_blocks (np);
}
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -224,7 +224,7 @@ diskfs_node_iterate (error_t (*fun) (struct node *))
unsigned int num_nodes = 0;
struct node *node, **node_list, **p;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
/* We must copy everything from the hash table into another data structure
to avoid running into any problems with the hash-table being modified
@@ -242,7 +242,7 @@ diskfs_node_iterate (error_t (*fun) (struct node *))
node->references++;
}
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
p = node_list;
while (num_nodes-- > 0)
@@ -250,9 +250,9 @@ diskfs_node_iterate (error_t (*fun) (struct node *))
node = *p++;
if (!err)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
err = (*fun) (node);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
diskfs_nrele (node);
}
diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c
index 83795289..36fa1338 100644
--- a/tmpfs/tmpfs.c
+++ b/tmpfs/tmpfs.c
@@ -67,10 +67,10 @@ diskfs_set_statfs (struct statfs *st)
st->f_bsize = vm_page_size;
st->f_blocks = tmpfs_page_limit;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
st->f_files = num_files;
pages = round_page (tmpfs_space_used) / vm_page_size;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
st->f_bfree = pages < tmpfs_page_limit ? tmpfs_page_limit - pages : 0;
st->f_bavail = st->f_bfree;
@@ -293,8 +293,8 @@ diskfs_append_args (char **argz, size_t *argz_len)
/* Handling of operations for the ports in diskfs_port_bucket, calling
* demuxer for each incoming message */
-static any_t
-diskfs_thread_function (any_t demuxer)
+static void *
+diskfs_thread_function (void *demuxer)
{
error_t err;
@@ -311,7 +311,7 @@ diskfs_thread_function (any_t demuxer)
exit (0);
/* NOTREACHED */
- return (any_t) 0;
+ return NULL;
}
@@ -338,6 +338,7 @@ main (int argc, char **argv)
{
error_t err;
mach_port_t bootstrap, realnode, host_priv;
+ pthread_t pthread_id;
struct stat st;
err = argp_parse (&startup_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL);
@@ -378,8 +379,15 @@ main (int argc, char **argv)
error (4, err, "cannot create root directory");
/* Like diskfs_spawn_first_thread. But do it manually, without timeout */
- cthread_detach (cthread_fork ((cthread_fn_t) diskfs_thread_function,
- (any_t) diskfs_demuxer));
+ err = pthread_create (&pthread_id, NULL, diskfs_thread_function,
+ diskfs_demuxer);
+ if (!err)
+ pthread_detach (pthread_id);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
/* Now that we are all set up to handle requests, and diskfs_root_node is
set properly, it is safe to export our fsys control port to the
@@ -429,10 +437,10 @@ main (int argc, char **argv)
/* We must keep the REALNODE send right to remain the active
translator for the underlying node. */
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
/* and so we die, leaving others to do the real work. */
- cthread_exit (0);
+ pthread_exit (NULL);
/* NOTREACHED */
return 0;
}
diff --git a/tmpfs/tmpfs.h b/tmpfs/tmpfs.h
index 3cb31e6b..b3c636d0 100644
--- a/tmpfs/tmpfs.h
+++ b/tmpfs/tmpfs.h
@@ -77,9 +77,9 @@ extern mach_port_t default_pager;
static inline void
adjust_used (off_t change)
{
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
tmpfs_space_used += change;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
}
#endif
diff --git a/trans/Makefile b/trans/Makefile
index 4e6a22dd..ff5a6a65 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -28,7 +28,8 @@ OBJS = $(SRCS:.c=.o) fsysServer.o ifsockServer.o passwordServer.o \
crashServer.o crash_replyUser.o msgServer.o \
default_pagerServer.o default_pagerUser.o \
device_replyServer.o elfcore.o
-HURDLIBS = threads ports netfs trivfs iohelp fshelp pipe ihash shouldbeinlibc
+HURDLIBS = ports netfs trivfs iohelp fshelp pipe ihash shouldbeinlibc
+LDLIBS += -lpthread
password-LDLIBS = $(LIBCRYPT)
include ../Makeconf
@@ -42,13 +43,13 @@ password: passwordServer.o
streamio: device_replyServer.o
proxy-defpager: default_pagerServer.o default_pagerUser.o
-proxy-defpager crash password streamio: ../libthreads/libthreads.a ../libports/libports.a ../libtrivfs/libtrivfs.a ../libthreads/libthreads.a ../libfshelp/libfshelp.a
+proxy-defpager crash password streamio: ../libports/libports.a ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a
fifo new-fifo: ../libpipe/libpipe.a
fwd: ../libfshelp/libfshelp.a ../libports/libports.a
-hello-mt magic null ifsock fifo new-fifo firmlink: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libthreads/libthreads.a ../libports/libports.a ../libihash/libihash.a
+hello-mt magic null ifsock fifo new-fifo firmlink: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a ../libihash/libihash.a
magic: ../libiohelp/libiohelp.a
hello: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a ../libihash/libihash.a
-fakeroot: ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a ../libiohelp/libiohelp.a ../libthreads/libthreads.a ../libports/libports.a ../libihash/libihash.a
+fakeroot: ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a ../libiohelp/libiohelp.a ../libports/libports.a ../libihash/libihash.a
$(targets): ../libshouldbeinlibc/libshouldbeinlibc.a
$(targets): %: %.o
diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index c1102343..f842fc56 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -25,7 +25,7 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/ihash.h>
#include <hurd/paths.h>
@@ -55,7 +55,7 @@ struct netnode
#define FAKE_MODE (1 << 3)
#define FAKE_REFERENCE (1 << 4) /* got node_norefs with st_nlink > 0 */
-struct mutex idport_ihash_lock = MUTEX_INITIALIZER;
+pthread_mutex_t idport_ihash_lock = PTHREAD_MUTEX_INITIALIZER;
struct hurd_ihash idport_ihash
= HURD_IHASH_INITIALIZER (offsetof (struct netnode, idport_locp));
@@ -73,7 +73,7 @@ new_node (file_t file, mach_port_t idport, int locked, int openmodes,
if (idport != MACH_PORT_NULL)
mach_port_deallocate (mach_task_self (), idport);
if (locked)
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
return ENOMEM;
}
nn->file = file;
@@ -97,17 +97,17 @@ new_node (file_t file, mach_port_t idport, int locked, int openmodes,
if (*np == 0)
{
if (locked)
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
err = ENOMEM;
}
else
{
if (!locked)
- mutex_lock (&idport_ihash_lock);
+ pthread_mutex_lock (&idport_ihash_lock);
err = hurd_ihash_add (&idport_ihash, nn->idport, *np);
if (!err)
netfs_nref (*np); /* Return a reference to the caller. */
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
}
if (err)
{
@@ -138,21 +138,21 @@ netfs_node_norefs (struct node *np)
np->nn->faked |= FAKE_REFERENCE;
++np->references;
}
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return;
}
- spin_unlock (&netfs_node_refcnt_lock); /* Avoid deadlock. */
- mutex_lock (&idport_ihash_lock);
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock); /* Avoid deadlock. */
+ pthread_mutex_lock (&idport_ihash_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
/* Previous holder of this lock might have just got a reference. */
if (np->references > 0)
{
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
return;
}
hurd_ihash_locp_remove (&idport_ihash, np->nn->idport_locp);
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
mach_port_deallocate (mach_task_self (), np->nn->file);
mach_port_deallocate (mach_task_self (), np->nn->idport);
free (np->nn);
@@ -300,18 +300,18 @@ netfs_S_dir_lookup (struct protid *diruser,
}
else
{
- mutex_lock (&idport_ihash_lock);
+ pthread_mutex_lock (&idport_ihash_lock);
np = hurd_ihash_find (&idport_ihash, idport);
if (np != 0)
{
/* We already know about this node. */
mach_port_deallocate (mach_task_self (), idport);
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
err = check_openmodes (np->nn, (flags & (O_RDWR|O_EXEC)), file);
if (!err)
netfs_nref (np);
- mutex_unlock (&np->lock);
- mutex_unlock (&idport_ihash_lock);
+ pthread_mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&idport_ihash_lock);
}
else
err = new_node (file, idport, 1, flags, &np);
@@ -597,7 +597,7 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir,
file_t newfile;
error_t err = dir_mkfile (dir->nn->file, O_RDWR|O_EXEC,
real_from_fake_mode (mode), &newfile);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (err == 0)
err = new_node (newfile, MACH_PORT_NULL, 0, O_RDWR|O_EXEC, np);
return err;
@@ -711,13 +711,13 @@ netfs_S_file_exec (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = check_openmodes (user->po->np->nn, O_EXEC, MACH_PORT_NULL);
file = user->po->np->nn->file;
if (!err)
err = mach_port_mod_refs (mach_task_self (),
file, MACH_PORT_RIGHT_SEND, 1);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
if (!err)
{
@@ -754,9 +754,9 @@ netfs_S_io_map (struct protid *user,
return EOPNOTSUPP;
*rdobjtype = *wrobjtype = MACH_MSG_TYPE_MOVE_SEND;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = io_map (user->po->np->nn->file, rdobj, wrobj);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -771,9 +771,9 @@ netfs_S_io_map_cntl (struct protid *user,
return EOPNOTSUPP;
*objtype = MACH_MSG_TYPE_MOVE_SEND;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = io_map_cntl (user->po->np->nn->file, obj);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -786,9 +786,9 @@ netfs_S_##name (struct protid *user) \
if (!user) \
return EOPNOTSUPP; \
\
- mutex_lock (&user->po->np->lock); \
+ pthread_mutex_lock (&user->po->np->lock); \
err = name (user->po->np->nn->file); \
- mutex_unlock (&user->po->np->lock); \
+ pthread_mutex_unlock (&user->po->np->lock); \
return err; \
}
@@ -808,9 +808,9 @@ netfs_S_io_prenotify (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = io_prenotify (user->po->np->nn->file, start, stop);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -823,9 +823,9 @@ netfs_S_io_postnotify (struct protid *user,
if (!user)
return EOPNOTSUPP;
- mutex_lock (&user->po->np->lock);
+ pthread_mutex_lock (&user->po->np->lock);
err = io_postnotify (user->po->np->nn->file, start, stop);
- mutex_unlock (&user->po->np->lock);
+ pthread_mutex_unlock (&user->po->np->lock);
return err;
}
diff --git a/trans/fifo.c b/trans/fifo.c
index 39043acd..4fe999dd 100644
--- a/trans/fifo.c
+++ b/trans/fifo.c
@@ -26,7 +26,7 @@
#include <fcntl.h>
#include <argp.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <hurd/ports.h>
#include <hurd/trivfs.h>
@@ -46,9 +46,9 @@ struct pipe_class *fifo_pipe_class;
struct pipe *active_fifo = NULL;
/* Lock this when changing ACTIVE_FIFO. */
-struct mutex active_fifo_lock;
+pthread_mutex_t active_fifo_lock;
/* Signal this when ACTIVE_FIFO may have changed. */
-struct condition active_fifo_changed;
+pthread_cond_t active_fifo_changed;
const char *argp_program_version = STANDARD_HURD_VERSION (fifo);
@@ -121,7 +121,7 @@ open_hook (struct trivfs_peropen *po)
if (flags & (O_READ | O_WRITE))
{
- mutex_lock (&active_fifo_lock);
+ pthread_mutex_lock (&active_fifo_lock);
/* Wait until the active fifo has changed so that CONDITION is true. */
#define WAIT(condition, noblock_err) \
@@ -132,7 +132,8 @@ open_hook (struct trivfs_peropen *po)
err = noblock_err; \
break; \
} \
- else if (hurd_condition_wait (&active_fifo_changed, &active_fifo_lock)) \
+ else if (pthread_hurd_cond_wait_np (&active_fifo_changed, \
+ &active_fifo_lock)) \
err = EINTR; \
}
@@ -160,7 +161,7 @@ open_hook (struct trivfs_peropen *po)
if (!err)
{
pipe_add_reader (active_fifo);
- condition_broadcast (&active_fifo_changed);
+ pthread_cond_broadcast (&active_fifo_changed);
/* We'll unlock ACTIVE_FIFO_LOCK below; the writer code won't
make us block because we've ensured that there's a reader
for it. */
@@ -174,7 +175,7 @@ open_hook (struct trivfs_peropen *po)
{
pipe_remove_reader (active_fifo);
active_fifo = NULL;
- condition_broadcast (&active_fifo_changed);
+ pthread_cond_broadcast (&active_fifo_changed);
}
}
}
@@ -199,13 +200,13 @@ open_hook (struct trivfs_peropen *po)
if (!err)
{
pipe_add_writer (active_fifo);
- condition_broadcast (&active_fifo_changed);
+ pthread_cond_broadcast (&active_fifo_changed);
}
}
po->hook = active_fifo;
- mutex_unlock (&active_fifo_lock);
+ pthread_mutex_unlock (&active_fifo_lock);
}
return err;
@@ -221,7 +222,7 @@ close_hook (struct trivfs_peropen *po)
if (!pipe)
return;
- mutex_lock (&active_fifo_lock);
+ pthread_mutex_lock (&active_fifo_lock);
was_active = (active_fifo == pipe);
if (was_active)
@@ -231,7 +232,7 @@ close_hook (struct trivfs_peropen *po)
|| ((flags & O_WRITE) && pipe->writers == 1);
else
/* Let others have their fun. */
- mutex_unlock (&active_fifo_lock);
+ pthread_mutex_unlock (&active_fifo_lock);
if (flags & O_READ)
pipe_remove_reader (pipe);
@@ -243,8 +244,8 @@ close_hook (struct trivfs_peropen *po)
{
if (detach)
active_fifo = NULL;
- condition_broadcast (&active_fifo_changed);
- mutex_unlock (&active_fifo_lock);
+ pthread_cond_broadcast (&active_fifo_changed);
+ pthread_mutex_unlock (&active_fifo_lock);
}
}
@@ -272,10 +273,10 @@ trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
if (pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
st->st_size = pipe_readable (pipe, 1);
st->st_blocks = st->st_size >> 9;
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
st->st_size = st->st_blocks = 0;
@@ -347,10 +348,10 @@ trivfs_S_io_read (struct trivfs_protid *cred,
else
{
struct pipe *pipe = cred->po->hook;
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
err = pipe_read (pipe, cred->po->openmodes & O_NONBLOCK, NULL,
data, data_len, amount);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
return err;
@@ -375,9 +376,9 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
else
{
struct pipe *pipe = cred->po->hook;
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
*amount = pipe_readable (pipe, 1);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
err = 0;
}
@@ -422,10 +423,10 @@ trivfs_S_io_select (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_READ)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe_wait_readable (pipe, 1, 1) != EWOULDBLOCK)
ready |= SELECT_READ; /* Data immediately readable (or error). */
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
ready |= SELECT_READ; /* Error immediately available... */
@@ -435,10 +436,10 @@ trivfs_S_io_select (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_WRITE)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe_wait_writable (pipe, 1) != EWOULDBLOCK)
ready |= SELECT_WRITE; /* Data immediately writable (or error). */
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
ready |= SELECT_WRITE; /* Error immediately available... */
@@ -484,10 +485,10 @@ trivfs_S_io_write (struct trivfs_protid *cred,
err = EBADF;
else
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
err = pipe_write (pipe, flags & O_NONBLOCK, NULL,
data, data_len, amount);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
}
diff --git a/trans/hello-mt.c b/trans/hello-mt.c
index b933cfde..632d3730 100644
--- a/trans/hello-mt.c
+++ b/trans/hello-mt.c
@@ -26,8 +26,7 @@
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
-#include <cthreads.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <version.h>
@@ -39,7 +38,7 @@ static char *contents = (char *) hello;
static size_t contents_len = sizeof hello - 1;
/* This lock protects access to contents and contents_len. */
-static struct rwlock contents_lock;
+static pthread_rwlock_t contents_lock;
/* Trivfs hooks. */
int trivfs_fstype = FSTYPE_MISC;
@@ -72,7 +71,7 @@ int trivfs_support_exec = 0;
/* A hook for us to keep track of the file descriptor state. */
struct open
{
- struct mutex lock;
+ pthread_mutex_t lock;
off_t offs;
};
@@ -101,7 +100,7 @@ open_hook (struct trivfs_peropen *peropen)
/* Initialize the offset. */
op->offs = 0;
- mutex_init (&op->lock);
+ pthread_mutex_init (&op->lock, NULL);
peropen->hook = op;
return 0;
}
@@ -112,7 +111,7 @@ close_hook (struct trivfs_peropen *peropen)
{
struct open *op = peropen->hook;
- mutex_clear (&op->lock);
+ pthread_mutex_init (&op->lock, NULL);
free (op);
}
@@ -136,13 +135,13 @@ trivfs_S_io_read (struct trivfs_protid *cred,
op = cred->po->hook;
- mutex_lock (&op->lock);
+ pthread_mutex_lock (&op->lock);
/* Get the offset. */
if (offs == -1)
offs = op->offs;
- rwlock_reader_lock (&contents_lock);
+ pthread_rwlock_rdlock (&contents_lock);
/* Prune the amount they want to read. */
if (offs > contents_len)
@@ -157,8 +156,8 @@ trivfs_S_io_read (struct trivfs_protid *cred,
*data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
if (*data == MAP_FAILED)
{
- mutex_unlock (&op->lock);
- rwlock_reader_unlock (&contents_lock);
+ pthread_mutex_unlock (&op->lock);
+ pthread_rwlock_unlock (&contents_lock);
return ENOMEM;
}
@@ -169,9 +168,9 @@ trivfs_S_io_read (struct trivfs_protid *cred,
op->offs += amount;
}
- mutex_unlock (&op->lock);
+ pthread_mutex_unlock (&op->lock);
- rwlock_reader_unlock (&contents_lock);
+ pthread_rwlock_unlock (&contents_lock);
*data_len = amount;
return 0;
@@ -191,7 +190,7 @@ trivfs_S_io_seek (struct trivfs_protid *cred,
op = cred->po->hook;
- mutex_lock (&op->lock);
+ pthread_mutex_lock (&op->lock);
switch (whence)
{
@@ -211,7 +210,7 @@ trivfs_S_io_seek (struct trivfs_protid *cred,
err = EINVAL;
}
- mutex_unlock (&op->lock);
+ pthread_mutex_unlock (&op->lock);
return err;
}
@@ -252,12 +251,12 @@ parse_opt (int opt, char *arg, struct argp_state *state)
char *new = strdup (arg);
if (new == NULL)
return ENOMEM;
- rwlock_writer_lock (&contents_lock);
+ pthread_rwlock_wrlock (&contents_lock);
if (contents != hello)
free (contents);
contents = new;
contents_len = strlen (new);
- rwlock_writer_unlock (&contents_lock);
+ pthread_rwlock_unlock (&contents_lock);
break;
}
}
@@ -273,9 +272,9 @@ trivfs_append_args (struct trivfs_control *fsys,
error_t err;
char *opt;
- rwlock_reader_lock (&contents_lock);
+ pthread_rwlock_rdlock (&contents_lock);
err = asprintf (&opt, "--contents=%s", contents) < 0 ? ENOMEM : 0;
- rwlock_reader_unlock (&contents_lock);
+ pthread_rwlock_unlock (&contents_lock);
if (!err)
{
@@ -305,7 +304,7 @@ main (int argc, char **argv)
/* Initialize the lock that will protect CONTENTS and CONTENTS_LEN.
We must do this before argp_parse, because parse_opt (above) will
use the lock. */
- rwlock_init (&contents_lock);
+ pthread_rwlock_init (&contents_lock, NULL);
/* We use the same argp for options available at startup
as for options we'll accept in an fsys_set_options RPC. */
diff --git a/trans/new-fifo.c b/trans/new-fifo.c
index 5306deed..cc16b988 100644
--- a/trans/new-fifo.c
+++ b/trans/new-fifo.c
@@ -26,7 +26,7 @@
#include <fcntl.h>
#include <assert.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd.h>
#include <argz.h>
#include <hurd/fshelp.h>
@@ -85,9 +85,9 @@ struct fifo_trans
/* The current fifo that new opens will see, or NULL if there is none. */
struct pipe *active_fifo;
/* Lock this when changing ACTIVE_FIFO. */
- struct mutex active_fifo_lock;
+ pthread_mutex_t active_fifo_lock;
/* Signal this when ACTIVE_FIFO may have changed. */
- struct condition active_fifo_changed;
+ pthread_cond_t active_fifo_changed;
};
/* Return a new FIFO_TRANS in TRANS, initializing it from FROM if it's
@@ -98,8 +98,8 @@ fifo_trans_create (struct fifo_trans *from, struct fifo_trans **trans)
struct fifo_trans *new = malloc (sizeof (struct fifo_trans));
new->server = 0;
- mutex_init (&new->active_fifo_lock);
- condition_init (&new->active_fifo_changed);
+ pthread_mutex_init (&new->active_fifo_lock, NULL);
+ pthread_cond_init (&new->active_fifo_changed, NULL);
new->parent = from;
@@ -245,7 +245,7 @@ fifo_trans_open (struct fifo_trans *trans, int flags, void **hook)
if (flags & (O_READ | O_WRITE))
{
- mutex_lock (&trans->active_fifo_lock);
+ pthread_mutex_lock (&trans->active_fifo_lock);
/* Wait until the active fifo has changed so that CONDITION is true. */
#define WAIT(condition, noblock_err) \
@@ -256,8 +256,8 @@ fifo_trans_open (struct fifo_trans *trans, int flags, void **hook)
err = noblock_err; \
break; \
} \
- else if (hurd_condition_wait (&trans->active_fifo_changed, \
- &trans->active_fifo_lock)) \
+ else if (pthread_hurd_cond_wait_np (&trans->active_fifo_changed, \
+ &trans->active_fifo_lock)) \
err = EINTR; \
}
@@ -281,7 +281,7 @@ fifo_trans_open (struct fifo_trans *trans, int flags, void **hook)
if (!err)
{
pipe_add_reader (trans->active_fifo);
- condition_broadcast (&trans->active_fifo_changed);
+ pthread_cond_broadcast (&trans->active_fifo_changed);
/* We'll unlock ACTIVE_FIFO_LOCK below; the writer code won't
make us block because we've ensured that there's a reader
for it. */
@@ -295,7 +295,7 @@ fifo_trans_open (struct fifo_trans *trans, int flags, void **hook)
{
pipe_remove_reader (trans->active_fifo);
trans->active_fifo = NULL;
- condition_broadcast (&trans->active_fifo_changed);
+ pthread_cond_broadcast (&trans->active_fifo_changed);
}
}
else
@@ -323,14 +323,14 @@ fifo_trans_open (struct fifo_trans *trans, int flags, void **hook)
if (!err)
{
pipe_add_writer (trans->active_fifo);
- condition_broadcast (&trans->active_fifo_changed);
+ pthread_cond_broadcast (&trans->active_fifo_changed);
}
}
*hook = trans->active_fifo;
}
- mutex_unlock (&trans->active_fifo_lock);
+ pthread_mutex_unlock (&trans->active_fifo_lock);
return err;
}
@@ -345,7 +345,7 @@ fifo_trans_close (struct fifo_trans *trans, struct trivfs_peropen *po)
if (!pipe)
return;
- mutex_lock (&trans->active_fifo_lock);
+ pthread_mutex_lock (&trans->active_fifo_lock);
was_active = (trans->active_fifo == pipe);
if (was_active)
@@ -353,7 +353,7 @@ fifo_trans_close (struct fifo_trans *trans, struct trivfs_peropen *po)
going_away = ((flags & O_READ) && pipe->readers == 1);
else
/* Let others have their fun. */
- mutex_unlock (&trans->active_fifo_lock);
+ pthread_mutex_unlock (&trans->active_fifo_lock);
if (flags & O_READ)
pipe_remove_reader (pipe);
@@ -365,8 +365,8 @@ fifo_trans_close (struct fifo_trans *trans, struct trivfs_peropen *po)
{
if (going_away)
trans->active_fifo = NULL;
- condition_broadcast (&trans->active_fifo_changed);
- mutex_unlock (&trans->active_fifo_lock);
+ pthread_cond_broadcast (&trans->active_fifo_changed);
+ pthread_mutex_unlock (&trans->active_fifo_lock);
}
}
@@ -423,10 +423,10 @@ trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
if (pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
st->st_size = pipe_readable (pipe, 1);
st->st_blocks = st->st_size >> 9;
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
st->st_size = st->st_blocks = 0;
@@ -533,10 +533,10 @@ trivfs_S_io_read (struct trivfs_protid *cred,
{
struct pipe *pipe = cred->po->hook;
assert (pipe);
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
err = pipe_read (pipe, cred->po->openmodes & O_NONBLOCK, NULL,
data, data_len, amount);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
return err;
@@ -562,9 +562,9 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
{
struct pipe *pipe = cred->po->hook;
assert (pipe);
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
*amount = pipe_readable (pipe, 1);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
err = 0;
}
@@ -609,10 +609,10 @@ trivfs_S_io_select (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_READ)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe_wait_readable (pipe, 1, 1) != EWOULDBLOCK)
ready |= SELECT_READ; /* Data immediately readable (or error). */
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
ready |= SELECT_READ; /* Error immediately available... */
@@ -622,10 +622,10 @@ trivfs_S_io_select (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_WRITE)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe_wait_writable (pipe, 1) != EWOULDBLOCK)
ready |= SELECT_WRITE; /* Data immediately writable (or error). */
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
else
ready |= SELECT_WRITE; /* Error immediately available... */
@@ -667,10 +667,10 @@ trivfs_S_io_write (struct trivfs_protid *cred,
else
{
struct pipe *pipe = cred->po->hook;
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
err = pipe_write (pipe, cred->po->openmodes & O_NONBLOCK, NULL,
data, data_len, amount);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
return err;
diff --git a/trans/streamio.c b/trans/streamio.c
index 9ced28b3..60b5d59c 100644
--- a/trans/streamio.c
+++ b/trans/streamio.c
@@ -35,13 +35,13 @@
#include <version.h>
/* The global lock */
-struct mutex global_lock;
+pthread_mutex_t global_lock;
/* Wakeup when device_open is finished */
-struct condition open_alert;
+pthread_cond_t open_alert;
/* Wakeup for select */
-struct condition select_alert;
+pthread_cond_t select_alert;
/* Bucket for all out ports */
struct port_bucket *streamdev_bucket;
@@ -60,7 +60,7 @@ struct buffer
/* The buffer array size. */
size_t size;
/* Wakeup when the buffer is not empty or not full. */
- struct condition *wait;
+ pthread_cond_t *wait;
/* The buffer. */
char buf[0];
};
@@ -73,9 +73,9 @@ create_buffer (size_t size)
assert (new);
new->head = new->tail = new->buf;
new->size = size;
- new->wait = malloc (sizeof (struct condition));
+ new->wait = malloc (sizeof (pthread_cond_t));
assert (new->wait);
- condition_init (new->wait);
+ pthread_cond_init (new->wait, NULL);
return new;
}
@@ -107,8 +107,8 @@ clear_buffer (struct buffer *b)
if (b == 0)
return;
b->head = b->tail = b->buf;
- condition_broadcast (b->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (b->wait);
+ pthread_cond_broadcast (&select_alert);
}
/* Read up to LEN bytes from B to DATA, returning the amount actually read. */
@@ -132,8 +132,8 @@ buffer_read (struct buffer *b, void *data, size_t len)
b->tail = b->buf + size;
}
- condition_broadcast (b->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (b->wait);
+ pthread_cond_broadcast (&select_alert);
return len;
}
@@ -149,8 +149,8 @@ buffer_write (struct buffer *b, void *data, size_t len)
memcpy (b->tail, data, len);
b->tail += len;
- condition_broadcast (b->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (b->wait);
+ pthread_cond_broadcast (&select_alert);
return len;
}
@@ -297,10 +297,10 @@ main (int argc, char *argv[])
if (err)
error (3, err, "trivfs_startup");
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
- condition_init (&open_alert);
- condition_init (&select_alert);
+ pthread_cond_init (&open_alert, NULL);
+ pthread_cond_init (&select_alert, NULL);
if (trivfs_allow_open & O_READ)
input_buffer = create_buffer (256);
@@ -342,7 +342,7 @@ open_hook (struct trivfs_control *cntl, struct iouser *user, int flags)
if (flags & O_ASYNC)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
mode = 0;
if (flags & O_READ)
@@ -355,27 +355,27 @@ open_hook (struct trivfs_control *cntl, struct iouser *user, int flags)
err = dev_open (stream_name, mode);
if (err)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
if (!(flags & O_NONBLOCK))
{
- if (hurd_condition_wait (&open_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&open_alert, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
if (!dev_already_opened ())
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return ENODEV;
}
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -386,9 +386,9 @@ error_t (*trivfs_check_open_hook) (struct trivfs_control *,
static error_t
po_create_hook (struct trivfs_peropen *po)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
nperopens++;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -398,7 +398,7 @@ error_t (*trivfs_peropen_create_hook) (struct trivfs_peropen *) =
static void
po_destroy_hook (struct trivfs_peropen *po)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
nperopens--;
if (!nperopens)
{
@@ -408,7 +408,7 @@ po_destroy_hook (struct trivfs_peropen *po)
dev_close ();
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
}
void (*trivfs_peropen_destroy_hook) (struct trivfs_peropen *)
@@ -437,7 +437,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
int nosync = (flags & FSYS_GOAWAY_NOSYNC);
struct port_class *root_port_class = fsys->protid_class;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (!dev_already_opened ())
exit (0);
@@ -445,7 +445,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
err = ports_inhibit_class_rpcs (root_port_class);
if (err == EINTR || (err && !force))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -462,7 +462,7 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
busy:
ports_enable_class (root_port_class);
ports_resume_class_rpcs (root_port_class);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EBUSY;
}
@@ -482,9 +482,9 @@ trivfs_S_io_read (struct trivfs_protid *cred,
if (!(cred->po->openmodes & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = dev_read (amount, (void **)data, data_len, cred->po->openmodes & O_NONBLOCK);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -501,9 +501,9 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
if (!(cred->po->openmodes & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = dev_readable (amount);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -521,9 +521,9 @@ trivfs_S_io_write (struct trivfs_protid *cred,
if (!(cred->po->openmodes & O_WRITE))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = dev_write ((void *)data, data_len, amount, cred->po->openmodes & O_NONBLOCK);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -560,7 +560,7 @@ trivfs_S_io_select (struct trivfs_protid *cred,
while (1)
{
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if ((*type & SELECT_READ) && buffer_readable (input_buffer))
available |= SELECT_READ;
if (output_buffer)
@@ -572,21 +572,21 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if (available)
{
*type = available;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
if (cred->po->openmodes & O_NONBLOCK)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
ports_interrupt_self_on_port_death (cred, reply);
- if (hurd_condition_wait (&select_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -665,9 +665,9 @@ trivfs_S_file_sync (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = dev_sync (wait);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -681,9 +681,9 @@ trivfs_S_file_syncfs (struct trivfs_protid *cred,
if (!cred)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
err = dev_sync (wait);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -804,15 +804,15 @@ device_open_reply (mach_port_t reply, int returncode, mach_port_t device)
if (reply != phys_reply)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
open_pending = 0;
- condition_broadcast (&open_alert);
+ pthread_cond_broadcast (&open_alert);
if (returncode != 0)
{
dev_close ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -840,7 +840,7 @@ device_open_reply (mach_port_t reply, int returncode, mach_port_t device)
else
{
dev_close ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -848,7 +848,7 @@ device_open_reply (mach_port_t reply, int returncode, mach_port_t device)
if (dev_blksize != 1)
amount = amount / dev_blksize * dev_blksize;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -948,7 +948,7 @@ dev_read (size_t amount, void **buf, size_t *len, int nowait)
if (nowait)
return EWOULDBLOCK;
- if (hurd_condition_wait (input_buffer->wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (input_buffer->wait, &global_lock))
return EINTR;
}
@@ -971,7 +971,7 @@ device_read_reply_inband (mach_port_t reply, error_t errorcode,
if (reply != phys_reply)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
input_pending = 0;
err = errorcode;
@@ -981,7 +981,7 @@ device_read_reply_inband (mach_port_t reply, error_t errorcode,
{
eof = 1;
dev_close ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -990,22 +990,22 @@ device_read_reply_inband (mach_port_t reply, error_t errorcode,
size_t nwritten;
while (!buffer_writable (input_buffer))
- condition_wait (input_buffer->wait, &global_lock);
+ pthread_cond_wait (input_buffer->wait, &global_lock);
nwritten = buffer_write (input_buffer, data, datalen);
data += nwritten;
datalen -= nwritten;
- condition_broadcast (input_buffer->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (input_buffer->wait);
+ pthread_cond_broadcast (&select_alert);
}
}
else
{
dev_close ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1074,7 +1074,7 @@ dev_write (void *buf, size_t len, size_t *amount, int nowait)
if (nowait)
return EWOULDBLOCK;
- if (hurd_condition_wait (output_buffer->wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (output_buffer->wait, &global_lock))
return EINTR;
}
@@ -1090,7 +1090,7 @@ device_write_reply_inband (mach_port_t reply, error_t returncode, int amount)
if (reply != phys_reply_writes)
return EOPNOTSUPP;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
output_pending = 0;
@@ -1099,8 +1099,8 @@ device_write_reply_inband (mach_port_t reply, error_t returncode, int amount)
if (amount >= npending_output)
{
npending_output = 0;
- condition_broadcast (output_buffer->wait);
- condition_broadcast (&select_alert);
+ pthread_cond_broadcast (output_buffer->wait);
+ pthread_cond_broadcast (&select_alert);
}
else
{
@@ -1111,7 +1111,7 @@ device_write_reply_inband (mach_port_t reply, error_t returncode, int amount)
else
dev_close ();
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -1136,7 +1136,7 @@ dev_sync (int wait)
if (!wait)
return 0;
- if (hurd_condition_wait (output_buffer->wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (output_buffer->wait, &global_lock))
return EINTR;
}
diff --git a/ufs/Makefile b/ufs/Makefile
index a1cfc4c9..b66a6259 100644
--- a/ufs/Makefile
+++ b/ufs/Makefile
@@ -24,7 +24,8 @@ SRCS = alloc.c consts.c dir.c hyper.c inode.c main.c pager.c \
sizes.c subr.c tables.c bmap.c pokeloc.c xinl.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = diskfs iohelp fshelp store pager threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/ufs/alloc.c b/ufs/alloc.c
index d8f92255..9056a8b7 100644
--- a/ufs/alloc.c
+++ b/ufs/alloc.c
@@ -64,7 +64,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
extern u_long nextgennumber;
-spin_lock_t alloclock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t alloclock = PTHREAD_SPINLOCK_INITIALIZER;
/* Forward declarations */
static u_long ffs_hashalloc (struct node *, int, long, int,
@@ -244,7 +244,7 @@ ffs_alloc(register struct node *np,
}
assert (cred);
#endif /* DIAGNOSTIC */
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
goto nospace;
if (cred && !idvec_contains (cred->user->uids, 0)
@@ -263,7 +263,7 @@ ffs_alloc(register struct node *np,
bno = (daddr_t)ffs_hashalloc(np, cg, (long)bpref, size,
(u_long (*)())ffs_alloccg);
if (bno > 0) {
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(size);
np->dn_set_ctime = 1;
np->dn_set_mtime = 1;
@@ -278,7 +278,7 @@ ffs_alloc(register struct node *np,
(void) chkdq(ip, (long)-btodb(size), cred, FORCE);
#endif
nospace:
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
printf ("file system full");
/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
@@ -321,7 +321,7 @@ ffs_realloccg(register struct node *np,
panic("ffs_realloccg: missing credential\n");
#endif /* DIAGNOSTIC */
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (!idvec_contains (cred->user->uids, 0)
&& freespace(fs, fs->fs_minfree) <= 0)
@@ -356,7 +356,7 @@ ffs_realloccg(register struct node *np,
bno = ffs_fragextend(np, cg, (long)bprev, osize, nsize);
if (bno) {
assert (bno == bprev);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(nsize - osize);
np->dn_set_ctime = 1;
np->dn_set_mtime = 1;
@@ -430,7 +430,7 @@ ffs_realloccg(register struct node *np,
if (nsize < request)
ffs_blkfree(np, bno + numfrags(fs, nsize),
(long)(request - nsize));
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(nsize - osize);
np->dn_set_mtime = 1;
np->dn_set_ctime = 1;
@@ -457,7 +457,7 @@ nospace:
/*
* no space available
*/
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
printf ("file system full");
/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
@@ -660,11 +660,11 @@ diskfs_alloc_node (struct node *dir,
fs = sblock;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (fs->fs_cstotal.cs_nifree == 0)
{
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
goto noinodes;
}
@@ -678,7 +678,7 @@ diskfs_alloc_node (struct node *dir,
cg = ino_to_cg(fs, ipref);
ino = (ino_t)ffs_hashalloc(dir, cg, (long)ipref,
mode, ffs_nodealloccg);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
if (ino == 0)
goto noinodes;
error = diskfs_cached_lookup (ino, &np);
@@ -694,12 +694,12 @@ diskfs_alloc_node (struct node *dir,
/*
* Set up a new generation number for this inode.
*/
- spin_lock (&gennumberlock);
+ pthread_spin_lock (&gennumberlock);
sex = diskfs_mtime->seconds;
if (++nextgennumber < (u_long)sex)
nextgennumber = sex;
np->dn_stat.st_gen = nextgennumber;
- spin_unlock (&gennumberlock);
+ pthread_spin_unlock (&gennumberlock);
*npp = np;
alloc_sync (np);
@@ -773,11 +773,11 @@ ffs_blkpref(struct node *np,
daddr_t nextblk;
fs = sblock;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
if (lbn < NDADDR) {
cg = ino_to_cg(fs, np->dn->number);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
/*
@@ -796,19 +796,19 @@ ffs_blkpref(struct node *np,
for (cg = startcg; cg < fs->fs_ncg; cg++)
if (csum[cg].cs_nbfree >= avgbfree) {
fs->fs_cgrotor = cg;
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
for (cg = 0; cg <= startcg; cg++)
if (csum[cg].cs_nbfree >= avgbfree) {
fs->fs_cgrotor = cg;
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return 0;
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
/*
* One or more previous blocks have been laid out. If less
* than fs_maxcontig previous blocks are contiguous, the
diff --git a/ufs/dir.c b/ufs/dir.c
index 3c5f152a..c3bd424e 100644
--- a/ufs/dir.c
+++ b/ufs/dir.c
@@ -244,9 +244,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Drop what we *thought* was .. (but isn't any more) and
try *again*. */
diskfs_nput (np);
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
@@ -259,9 +259,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Lock them in the proper order, and then
repeat the directory scan to see if this is still
right. */
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
diff --git a/ufs/hyper.c b/ufs/hyper.c
index ece327a2..95013895 100644
--- a/ufs/hyper.c
+++ b/ufs/hyper.c
@@ -280,7 +280,7 @@ diskfs_set_hypermetadata (int wait, int clean)
{
error_t err;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (csum_dirty)
{
@@ -316,7 +316,7 @@ diskfs_set_hypermetadata (int wait, int clean)
if (err)
{
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return err;
}
@@ -337,7 +337,7 @@ diskfs_set_hypermetadata (int wait, int clean)
wait = 1; /* must be synchronous */
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
/* Update the superblock if necessary (clean bit was just set). */
copy_sblock ();
@@ -355,7 +355,7 @@ copy_sblock ()
err = diskfs_catch_exception ();
assert_perror (err);
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (sblock_dirty)
{
@@ -386,7 +386,7 @@ copy_sblock ()
sblock_dirty = 0;
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
diskfs_end_catch_exception ();
}
diff --git a/ufs/inode.c b/ufs/inode.c
index 77a45edb..066eb1e5 100644
--- a/ufs/inode.c
+++ b/ufs/inode.c
@@ -35,7 +35,7 @@
static struct node *nodehash[INOHSZ];
static error_t read_disknode (struct node *np);
-spin_lock_t gennumberlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t gennumberlock = PTHREAD_SPINLOCK_INITIALIZER;
/* Initialize the inode hash table. */
void
@@ -55,15 +55,15 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
struct node *np;
error_t err;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->dn->number != inum)
continue;
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -74,30 +74,32 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
dn->dirents = 0;
dn->dir_idx = 0;
- rwlock_init (&dn->allocptrlock);
+ pthread_rwlock_init (&dn->allocptrlock, NULL);
+ pthread_mutex_init (&dn->waitlock, NULL);
+ pthread_cond_init (&dn->waitcond, NULL);
dn->dirty = 0;
dn->fileinfo = 0;
np = diskfs_make_node (dn);
np->cache_id = inum;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
dn->hnext = nodehash[INOHASH(inum)];
if (dn->hnext)
dn->hnext->dn->hprevp = &dn->hnext;
dn->hprevp = &nodehash[INOHASH(inum)];
nodehash[INOHASH(inum)] = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = read_disknode (np);
if (!diskfs_check_readonly () && !np->dn_stat.st_gen)
{
- spin_lock (&gennumberlock);
+ pthread_spin_lock (&gennumberlock);
if (++nextgennumber < diskfs_mtime->seconds)
nextgennumber = diskfs_mtime->seconds;
np->dn_stat.st_gen = nextgennumber;
- spin_unlock (&gennumberlock);
+ pthread_spin_unlock (&gennumberlock);
np->dn_set_ctime = 1;
}
@@ -117,14 +119,14 @@ ifind (ino_t inum)
{
struct node *np;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->dn->number != inum)
continue;
assert (np->references);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return np;
}
assert (0);
@@ -168,7 +170,7 @@ diskfs_lost_hardrefs (struct node *np)
if (np->dn->fileinfo)
{
- spin_lock (&_libports_portrefcntlock);
+ pthread_spin_lock (&_libports_portrefcntlock);
pi = (struct port_info *) np->dn->fileinfo->p;
if (pi->refcnt == 1)
{
@@ -178,7 +180,7 @@ diskfs_lost_hardrefs (struct node *np)
can't happen as long as we hold NP locked. So
we can safely unlock _libports_portrefcntlock for
the following call. */
- spin_unlock (&_libports_portrefcntlock);
+ pthread_spin_unlock (&_libports_portrefcntlock);
/* Right now the node is locked with no hard refs;
this is an anomalous situation. Before messing with
@@ -197,7 +199,7 @@ diskfs_lost_hardrefs (struct node *np)
diskfs_nput (np);
}
else
- spin_unlock (&_libports_portrefcntlock);
+ pthread_spin_unlock (&_libports_portrefcntlock);
}
#endif
}
@@ -440,7 +442,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
/* Acquire a reference on all the nodes in the hash table
and enter them into a list on the stack. */
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (n = 0; n < INOHSZ; n++)
for (np = nodehash[n]; np; np = np->dn->hnext)
{
@@ -450,16 +452,16 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
i->np = np;
list = i;
}
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = 0;
for (i = list; i; i = i->next)
{
if (!err)
{
- mutex_lock (&i->np->lock);
+ pthread_mutex_lock (&i->np->lock);
err = (*fun)(i->np);
- mutex_unlock (&i->np->lock);
+ pthread_mutex_unlock (&i->np->lock);
}
diskfs_nrele (i->np);
}
@@ -646,14 +648,14 @@ diskfs_S_file_get_storage_info (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* See if this file fits in the direct block pointers. If not, punt
for now. (Reading indir blocks is a pain, and I'm postponing
pain.) XXX */
if (np->allocsize > NDADDR * sblock->fs_bsize)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -685,7 +687,7 @@ diskfs_S_file_get_storage_info (struct protid *cred,
}
diskfs_end_catch_exception ();
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (! err)
err = store_clone (store, &file_store);
diff --git a/ufs/main.c b/ufs/main.c
index 242107f4..9fc21f81 100644
--- a/ufs/main.c
+++ b/ufs/main.c
@@ -46,19 +46,19 @@ warp_root (void)
error_t err;
err = diskfs_cached_lookup (2, &diskfs_root_node);
assert (!err);
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
}
/* XXX */
-struct mutex printf_lock = MUTEX_INITIALIZER;
+pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER;
int printf (const char *fmt, ...)
{
va_list arg;
int done;
va_start (arg, fmt);
- mutex_lock (&printf_lock);
+ pthread_mutex_lock (&printf_lock);
done = vprintf (fmt, arg);
- mutex_unlock (&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
va_end (arg);
return done;
}
@@ -195,7 +195,7 @@ main (int argc, char **argv)
/* SET HOST NAME */
/* And this thread is done with its work. */
- cthread_exit (0);
+ pthread_exit (NULL);
return 0;
}
diff --git a/ufs/pager.c b/ufs/pager.c
index 3038932d..1e3d140c 100644
--- a/ufs/pager.c
+++ b/ufs/pager.c
@@ -21,9 +21,9 @@
#include <unistd.h>
#include <hurd/store.h>
-spin_lock_t node2pagelock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t node2pagelock = PTHREAD_SPINLOCK_INITIALIZER;
-spin_lock_t unlocked_pagein_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t unlocked_pagein_lock = PTHREAD_SPINLOCK_INITIALIZER;
#ifdef DONT_CACHE_MEMORY_OBJECTS
#define MAY_CACHE 0
@@ -47,11 +47,11 @@ find_address (struct user_pager_info *upi,
vm_address_t offset,
daddr_t *addr,
int *disksize,
- struct rwlock **nplock,
+ pthread_rwlock_t **nplock,
int isread)
{
error_t err;
- struct rwlock *lock;
+ pthread_rwlock_t *lock;
assert (upi->type == DISK || upi->type == FILE_DATA);
@@ -81,37 +81,49 @@ find_address (struct user_pager_info *upi,
I think this is sufficiently rare to put it off for the time
being.) */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
if (offset >= upi->allow_unlocked_pagein
&& (offset + vm_page_size
<= upi->allow_unlocked_pagein + upi->unlocked_pagein_length))
{
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
*nplock = 0;
goto have_lock;
}
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Block on the rwlock if necessary; but when we wake up,
don't acquire it; check again from the top.
This is mutated inline from rwlock.h. */
lock = &np->dn->allocptrlock;
- mutex_lock (&lock->master);
- if (lock->readers == -1 || lock->writers_waiting)
+ /*
+ TD - Why do we lock first?
+ To prevent this nigh-impossible scenario:
+ 1) trylock - writer has lock
+ 2) switch back to writer before we lock waitlock
+ 3) writer finishes: releases lock and broadcasts
+ 4) we wait for a condition that will never get broadcast
+ With this, either we get the lock, or we get the signal.
+ */
+ pthread_mutex_lock (&np->dn->waitlock);
+ if (pthread_rwlock_tryrdlock (lock))
{
- lock->readers_waiting++;
- condition_wait (&lock->wakeup, &lock->master);
- lock->readers_waiting--;
- mutex_unlock (&lock->master);
+ /*
+ TD - we now don't block on the rwlock. Instead, we wait on a
+ condition that will be signalled when the lock is unlocked,
+ or when it is safe not to lock the page. We don't spin on an
+ invariant, as spurius wakeups can do no harm.
+ */
+ pthread_cond_wait (&np->dn->waitcond, &np->dn->waitlock);
+ pthread_mutex_unlock (&np->dn->waitlock);
goto try_again;
}
- lock->readers++;
- mutex_unlock (&lock->master);
+ pthread_mutex_unlock (&np->dn->waitlock);
*nplock = lock;
}
else
{
- rwlock_reader_lock (&np->dn->allocptrlock);
+ pthread_rwlock_rdlock (&np->dn->allocptrlock);
*nplock = &np->dn->allocptrlock;
}
@@ -120,7 +132,7 @@ find_address (struct user_pager_info *upi,
if (offset >= np->allocsize)
{
if (*nplock)
- rwlock_reader_unlock (*nplock);
+ pthread_rwlock_unlock (*nplock);
if (isread)
return EIO;
else
@@ -138,7 +150,7 @@ find_address (struct user_pager_info *upi,
err = fetch_indir_spec (np, lblkno (sblock, offset), indirs);
if (err && *nplock)
- rwlock_reader_unlock (*nplock);
+ pthread_rwlock_unlock (*nplock);
else
{
if (indirs[0].bno)
@@ -162,7 +174,7 @@ pager_read_page (struct user_pager_info *pager,
int *writelock)
{
error_t err;
- struct rwlock *nplock;
+ pthread_rwlock_t *nplock;
daddr_t addr;
int disksize;
@@ -193,7 +205,7 @@ pager_read_page (struct user_pager_info *pager,
}
if (nplock)
- rwlock_reader_unlock (nplock);
+ pthread_rwlock_unlock (nplock);
return err;
}
@@ -207,7 +219,7 @@ pager_write_page (struct user_pager_info *pager,
{
daddr_t addr;
int disksize;
- struct rwlock *nplock;
+ pthread_rwlock_t *nplock;
error_t err;
err = find_address (pager, page, &addr, &disksize, &nplock, 0);
@@ -226,7 +238,7 @@ pager_write_page (struct user_pager_info *pager,
err = 0;
if (nplock)
- rwlock_reader_unlock (nplock);
+ pthread_rwlock_unlock (nplock);
return err;
}
@@ -268,7 +280,7 @@ pager_unlock_page (struct user_pager_info *pager,
dn = np->dn;
di = dino (dn->number);
- rwlock_writer_lock (&dn->allocptrlock);
+ pthread_rwlock_wrlock (&dn->allocptrlock);
/* If this is the last block, we don't let it get unlocked. */
if (address + __vm_page_size
@@ -276,21 +288,31 @@ pager_unlock_page (struct user_pager_info *pager,
{
printf ("attempt to unlock at last block denied\n");
fflush (stdout);
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ /* Wake up any remaining sleeping readers. Wow, so much work.... */
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
err = fetch_indir_spec (np, lblkno (sblock, address), indirs);
if (err)
{
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
err = diskfs_catch_exception ();
if (err)
{
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
@@ -421,7 +443,10 @@ pager_unlock_page (struct user_pager_info *pager,
out:
diskfs_end_catch_exception ();
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return err;
}
@@ -452,10 +477,10 @@ pager_clear_user_data (struct user_pager_info *upi)
/* XXX Do the right thing for the disk pager here too. */
if (upi->type == FILE_DATA)
{
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
if (upi->np->dn->fileinfo == upi)
upi->np->dn->fileinfo = 0;
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
diskfs_nrele_light (upi->np);
}
free (upi);
@@ -491,11 +516,11 @@ diskfs_file_update (struct node *np,
struct dirty_indir *d, *tmp;
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -522,11 +547,11 @@ flush_node_pager (struct node *node)
struct disknode *dn = node->dn;
struct dirty_indir *dirty = dn->dirty;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -558,7 +583,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
&& (!direct_symlink_extension
|| np->dn_stat.st_size >= sblock->fs_maxsymlinklen)));
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
do
if (!np->dn->fileinfo)
{
@@ -575,7 +600,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
{
diskfs_nrele_light (np);
free (upi);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
return MACH_PORT_NULL;
}
np->dn->fileinfo = upi;
@@ -596,7 +621,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
}
while (right == MACH_PORT_NULL);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
mach_port_insert_right (mach_task_self (), right, right,
MACH_MSG_TYPE_MAKE_SEND);
@@ -611,11 +636,11 @@ drop_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (MAY_CACHE && upi)
pager_change_attributes (upi->p, 0, MEMORY_OBJECT_COPY_DELAY, 0);
@@ -630,11 +655,11 @@ allow_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (MAY_CACHE && upi)
pager_change_attributes (upi->p, 1, MEMORY_OBJECT_COPY_DELAY, 0);
diff --git a/ufs/pokeloc.c b/ufs/pokeloc.c
index 267aa106..e1d5ffcb 100644
--- a/ufs/pokeloc.c
+++ b/ufs/pokeloc.c
@@ -28,7 +28,7 @@ struct pokeloc
};
struct pokeloc *pokelist;
-spin_lock_t pokelistlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t pokelistlock = PTHREAD_SPINLOCK_INITIALIZER;
/* Remember that data here on the disk has been modified. */
void
@@ -41,10 +41,10 @@ record_poke (void *loc, vm_size_t length)
pl->offset = trunc_page (offset);
pl->length = round_page (offset + length) - pl->offset;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
pl->next = pokelist;
pokelist = pl;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
}
/* Get rid of any outstanding pokes. */
@@ -53,10 +53,10 @@ flush_pokes ()
{
struct pokeloc *pl;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
pl = pokelist;
pokelist = 0;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
while (pl)
{
@@ -72,7 +72,7 @@ sync_disk (int wait)
{
struct pokeloc *pl, *tmp;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
for (pl = pokelist; pl; pl = tmp)
{
pager_sync_some (diskfs_disk_pager, pl->offset, pl->length, wait);
@@ -80,6 +80,6 @@ sync_disk (int wait)
free (pl);
}
pokelist = 0;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
}
diff --git a/ufs/sizes.c b/ufs/sizes.c
index 58cbfc98..e3d51b7d 100644
--- a/ufs/sizes.c
+++ b/ufs/sizes.c
@@ -91,11 +91,11 @@ diskfs_truncate (struct node *np,
immediately. (We are implicitly changing the data to zeros
and doing it without the kernel's immediate knowledge;
accordingl we must help out the kernel thusly.) */
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -115,7 +115,7 @@ diskfs_truncate (struct node *np,
ports_port_deref (upi->p);
}
- rwlock_writer_lock (&np->dn->allocptrlock);
+ pthread_rwlock_wrlock (&np->dn->allocptrlock);
/* Update the size on disk; fsck will finish freeing blocks if necessary
should we crash. */
@@ -250,7 +250,13 @@ diskfs_truncate (struct node *np,
np->dn_set_ctime = 1;
diskfs_node_update (np, 1);
- rwlock_writer_unlock (&np->dn->allocptrlock);
+ pthread_rwlock_unlock (&np->dn->allocptrlock);
+ /* Wake up any remaining sleeping readers.
+ This sequence of three calls is now necessary whenever we acquire a write
+ lock on allocptrlock. If we do not, we may leak some readers. */
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
/* At this point the last block (as defined by np->allocsize)
might not be allocated. We need to allocate it to maintain
@@ -275,11 +281,11 @@ diskfs_truncate (struct node *np,
diskfs_end_catch_exception ();
/* Now we can permit delayed copies again. */
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
pager_change_attributes (upi->p, MAY_CACHE,
@@ -415,15 +421,23 @@ block_extended (struct node *np,
assert_perror (err);
/* Allow these pageins to occur even though we're holding the lock */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
np->dn->fileinfo->allow_unlocked_pagein = lbn * sblock->fs_bsize;
np->dn->fileinfo->unlocked_pagein_length = round_page (old_size);
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Make sure all waiting pageins see this change. */
- mutex_lock (&np->dn->allocptrlock.master);
- condition_broadcast (&np->dn->allocptrlock.wakeup);
- mutex_unlock (&np->dn->allocptrlock.master);
+ /* BDD - Is this sane? */
+ /* TD - No... no it wasn't. But, it looked right. */
+ /*
+ This new code should, SHOULD, behave as the original code did.
+ This will wake up all readers waiting on the lock. This code favors
+ strongly writers, but, as of making this change, pthreads favors
+ writers, and cthreads did favor writers.
+ */
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
/* Force the pages in core and make sure they are dirty */
for (pokeaddr = (int *)mapaddr;
@@ -432,10 +446,10 @@ block_extended (struct node *np,
*pokeaddr = *pokeaddr;
/* Turn off the special pagein permission */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
np->dn->fileinfo->allow_unlocked_pagein = 0;
np->dn->fileinfo->unlocked_pagein_length = 0;
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Undo mapping */
mach_port_deallocate (mach_task_self (), mapobj);
@@ -497,7 +511,7 @@ diskfs_grow (struct node *np,
if (size == 0)
size = sblock->fs_bsize;
- rwlock_writer_lock (&np->dn->allocptrlock);
+ pthread_rwlock_wrlock (&np->dn->allocptrlock);
/* The old last block of the file. */
olbn = lblkno (sblock, np->allocsize - 1);
@@ -680,7 +694,10 @@ diskfs_grow (struct node *np,
np->allocsize = newallocsize;
}
- rwlock_writer_unlock (&np->dn->allocptrlock);
+ pthread_rwlock_unlock (&np->dn->allocptrlock);
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
if (need_sync)
diskfs_file_update (np, 1);
diff --git a/ufs/ufs.h b/ufs/ufs.h
index f59784d5..0a79f560 100644
--- a/ufs/ufs.h
+++ b/ufs/ufs.h
@@ -25,6 +25,7 @@
#include <hurd/diskfs.h>
#include <sys/mman.h>
#include <assert.h>
+#include <pthread.h>
#include <features.h>
#include "fs.h"
#include "dinode.h"
@@ -54,7 +55,9 @@ struct disknode
/* Links on hash list. */
struct node *hnext, **hprevp;
- struct rwlock allocptrlock;
+ pthread_rwlock_t allocptrlock;
+ pthread_mutex_t waitlock;
+ pthread_cond_t waitcond;
struct dirty_indir *dirty;
@@ -112,14 +115,14 @@ extern struct csum *csum;
int sblock_dirty;
int csum_dirty;
-spin_lock_t node2pagelock;
+pthread_spinlock_t node2pagelock;
-spin_lock_t alloclock;
+pthread_spinlock_t alloclock;
-spin_lock_t gennumberlock;
+pthread_spinlock_t gennumberlock;
u_long nextgennumber;
-spin_lock_t unlocked_pagein_lock;
+pthread_spinlock_t unlocked_pagein_lock;
/* The compat_mode specifies whether or not we write
extensions onto the disk. */
diff --git a/usermux/Makefile b/usermux/Makefile
index 6e06b159..c30b5ab4 100644
--- a/usermux/Makefile
+++ b/usermux/Makefile
@@ -24,6 +24,7 @@ target = usermux
SRCS = usermux.c mux.c leaf.c node.c stubs.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = netfs fshelp iohelp threads ports ihash shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/usermux/mux.c b/usermux/mux.c
index 12da1e14..bfa95fd2 100644
--- a/usermux/mux.c
+++ b/usermux/mux.c
@@ -66,10 +66,10 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, usermux_maptime);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (! err)
- mutex_lock (&(*node)->lock);
+ pthread_mutex_lock (&(*node)->lock);
return err;
}
@@ -178,7 +178,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
{
error_t err;
static time_t cache_timestamp = 0;
- static struct rwlock cache_lock = RWLOCK_INITIALIZER;
+ static pthread_rwlock_t cache_lock = PTHREAD_RWLOCK_INITIALIZER;
static char *cached_data = 0;
static mach_msg_type_number_t cached_data_len = 0;
static int cached_data_entries = 0;
@@ -189,7 +189,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
maptime_read (usermux_maptime, &tv);
if (tv.tv_sec > cache_timestamp + DIRENTS_CACHE_TIME)
{
- rwlock_writer_lock (&cache_lock);
+ pthread_rwlock_wrlock (&cache_lock);
if (cached_data_len > 0)
/* Free the old cache. */
@@ -205,13 +205,13 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
if (! err)
cache_timestamp = tv.tv_sec;
- rwlock_writer_unlock (&cache_lock);
+ pthread_rwlock_unlock (&cache_lock);
if (err)
return err;
}
- rwlock_reader_lock (&cache_lock);
+ pthread_rwlock_rdlock (&cache_lock);
first = cached_data;
bytes_left = cached_data_len;
@@ -223,7 +223,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
if (entries_left == 0)
{
- rwlock_reader_unlock (&cache_lock);
+ pthread_rwlock_unlock (&cache_lock);
return EINVAL;
}
@@ -264,7 +264,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
if (! err)
bcopy (cached_data, *data, bytes_left);
- rwlock_reader_unlock (&cache_lock);
+ pthread_rwlock_unlock (&cache_lock);
fshelp_touch (&dir->nn_stat, TOUCH_ATIME, usermux_maptime);
@@ -298,10 +298,10 @@ lookup_cached (struct usermux *mux, const char *user, int purge,
if (strcasecmp (user, nm->name) == 0)
{
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
if (nm->node)
nm->node->references++;
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
if (nm->node)
{
@@ -348,13 +348,13 @@ lookup_pwent (struct usermux *mux, const char *user, struct passwd *pw,
return err;
}
- rwlock_writer_lock (&mux->names_lock);
+ pthread_rwlock_wrlock (&mux->names_lock);
if (lookup_cached (mux, user, 1, node))
/* An entry for USER has already been created between the time we last
looked and now (which is possible because we didn't lock MUX).
Just throw away our version and return the one already in the cache. */
{
- rwlock_writer_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
nm->node->nn->name = 0; /* Avoid touching the mux name list. */
netfs_nrele (nm->node); /* Free the tentative new node. */
free_name (nm); /* And the name it was under. */
@@ -364,7 +364,7 @@ lookup_pwent (struct usermux *mux, const char *user, struct passwd *pw,
{
nm->next = mux->names;
mux->names = nm;
- rwlock_writer_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
}
return 0;
@@ -379,9 +379,9 @@ lookup_user (struct usermux *mux, const char *user, struct node **node)
struct passwd _pw, *pw;
char pwent_data[2048]; /* XXX what size should this be???? */
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
was_cached = lookup_cached (mux, user, 0, node);
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
if (was_cached)
return 0;
@@ -426,14 +426,14 @@ netfs_attempt_chown (struct iouser *cred, struct node *node, uid_t uid, uid_t gi
node->nn_stat.st_gid = gid;
/* Change the owner of each leaf node. */
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
for (nm = mux->names; nm; nm = nm->next)
if (nm->node)
{
nm->node->nn_stat.st_uid = uid;
nm->node->nn_stat.st_gid = gid;
}
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, usermux_maptime);
}
@@ -463,11 +463,11 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author)
node->nn_stat.st_author = author;
/* Change the owner of each leaf node. */
- rwlock_reader_lock (&mux->names_lock);
+ pthread_rwlock_rdlock (&mux->names_lock);
for (nm = mux->names; nm; nm = nm->next)
if (nm->node)
nm->node->nn_stat.st_author = author;
- rwlock_reader_unlock (&mux->names_lock);
+ pthread_rwlock_unlock (&mux->names_lock);
fshelp_touch (&node->nn_stat, TOUCH_CTIME, usermux_maptime);
}
diff --git a/usermux/node.c b/usermux/node.c
index f4a5f7d7..324b85bf 100644
--- a/usermux/node.c
+++ b/usermux/node.c
@@ -48,7 +48,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **node)
{
*node = 0;
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
diff --git a/usermux/usermux.h b/usermux/usermux.h
index ff4ca5de..c9374aaa 100644
--- a/usermux/usermux.h
+++ b/usermux/usermux.h
@@ -22,7 +22,7 @@
#define __USERMUX_H__
#include <hurd/netfs.h>
-#include <rwlock.h>
+#include <pthread.h>
#include <maptime.h>
struct passwd;
@@ -38,7 +38,7 @@ struct usermux
{
/* The user nodes in this mux. */
struct usermux_name *names;
- struct rwlock names_lock;
+ pthread_rwlock_t names_lock;
/* A template argz, which is used to start each user-specific translator
with the user name appropriately added. */
diff --git a/utils/Makefile b/utils/Makefile
index 3bb8b17c..00f6142f 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -31,7 +31,8 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh
OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
-HURDLIBS = ps ihash store fshelp threads ports ftpconn shouldbeinlibc
+HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
+LDLIBS += -lpthread
login-LDLIBS = -lutil $(LIBCRYPT)
addauth-LDLIBS = $(LIBCRYPT)
setauth-LDLIBS = $(LIBCRYPT)
@@ -52,9 +53,7 @@ ps w: psout.o ../libps/libps.a ../libihash/libihash.a
storeinfo storecat storeread: ../libstore/libstore.a
ftpcp ftpdir: ../libftpconn/libftpconn.a
-# We must include libthreads because of a bug in the way shared libraries
-# work: all libraries that *any* routine in libfshelp uses must be defined.
-settrans: ../libfshelp/libfshelp.a ../libports/libports.a ../libthreads/libthreads.a
+settrans: ../libfshelp/libfshelp.a ../libports/libports.a
ps w ids settrans syncfs showtrans fsysopts storeinfo login vmstat portinfo \
devprobe vminfo addauth rmauth setauth unsu ftpcp ftpdir storeread \
storecat msgport mount: \
@@ -62,12 +61,10 @@ ps w ids settrans syncfs showtrans fsysopts storeinfo login vmstat portinfo \
$(filter-out $(special-targets), $(targets)): %: %.o
-rpctrace: ../libthreads/libthreads.a \
- ../libports/libports.a ../libihash/libihash.a
+rpctrace: ../libports/libports.a ../libihash/libihash.a
rpctrace-CPPFLAGS = -DDATADIR=\"${datadir}\"
fakeauth: authServer.o auth_requestUser.o interruptServer.o \
- ../libthreads/libthreads.a \
../libports/libports.a ../libihash/libihash.a \
../libshouldbeinlibc/libshouldbeinlibc.a
auth-MIGSFLAGS = -imacros $(srcdir)/../auth/authmutations.h
diff --git a/utils/fakeauth.c b/utils/fakeauth.c
index 49fa7f1c..154bf8e4 100644
--- a/utils/fakeauth.c
+++ b/utils/fakeauth.c
@@ -310,8 +310,8 @@ auth_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp)
}
-static any_t
-handle_auth_requests (any_t ignored)
+static void *
+handle_auth_requests (void *ignored)
{
while (1)
ports_manage_port_operations_multithread (auth_bucket, auth_demuxer,
@@ -326,6 +326,7 @@ main (int argc, char **argv)
struct authhandle *firstauth;
auth_t authport;
pid_t child;
+ pthread_t thread;
int status;
int argi;
@@ -375,7 +376,14 @@ believe it has restricted them to different identities or no identity at all.\
real_auth_port = getauth ();
/* Start handling auth requests on our fake handles. */
- cthread_detach (cthread_fork (&handle_auth_requests, (any_t)0));
+ err = pthread_create (&thread, NULL, &handle_auth_requests, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
/* Now we start faking ourselves out. This will immediately
reauthenticate all our descriptors through our proxy auth port.
diff --git a/utils/rpctrace.c b/utils/rpctrace.c
index 9e6825d0..deb83405 100644
--- a/utils/rpctrace.c
+++ b/utils/rpctrace.c
@@ -1437,7 +1437,7 @@ trace_and_forward (mach_msg_header_t *inp, mach_msg_header_t *outp)
}
/* This function runs in the tracing thread and drives all the tracing. */
-static any_t
+static void *
trace_thread_function (void *arg)
{
struct port_bucket *const bucket = arg;
@@ -1716,6 +1716,7 @@ main (int argc, char **argv, char **envp)
bool nostdinc = FALSE;
const char *outfile = 0;
char **cmd_argv = 0;
+ pthread_t thread;
error_t err;
/* Parse our options... */
@@ -1809,7 +1810,14 @@ main (int argc, char **argv, char **envp)
them, and interpose on the ports they carry. The access to the
`traced_info' and ihash data structures is all single-threaded,
happening only in this new thread. */
- cthread_detach (cthread_fork (trace_thread_function, traced_bucket));
+ err = pthread_create (&thread, NULL, trace_thread_function, traced_bucket);
+ if (!err)
+ pthread_detach (thread);
+ else
+ {
+ errno = err;
+ perror ("pthread_create");
+ }
/* Run the program on the command line and wait for it to die.
The other thread does all the tracing and interposing. */