From 3cf32b2119b9e14577b5b9c89c19dca288da287b Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Tue, 4 Sep 2012 00:33:09 +0200 Subject: Switch from cthreads to pthreads Makefiles, headers, types, macros and function calls are renamed where appropriate. Most of this work was done by Barry deFreese and Thomas DiModica. * auth/Makefile: Switch from cthreads to pthreads. * auth/auth.c: Likewise. * boot/Makefile: Likewise. * boot/boot.c: Likewise. * boot/ux.c: Likewise. * console-client/Makefile: Likewise. * console-client/console.c: Likewise. * console-client/driver.c: Likewise. * console-client/driver.h: Likewise. * console-client/generic-speaker.c: Likewise. * console-client/kbd-repeat.c: Likewise. * console-client/ncursesw.c: Likewise. * console-client/pc-kbd.c: Likewise. * console-client/pc-mouse.c: Likewise. * console-client/timer.c: Likewise. * console-client/trans.c: Likewise. * console-client/vga.c: Likewise. * console/Makefile: Likewise. * console/console.c: Likewise. * console/display.c: Likewise. * console/input.c: Likewise. * console/pager.c: Likewise. * defpager/backing.c: Likewise. * exec/Makefile: Likewise. * exec/exec.c: Likewise. * exec/hashexec.c: Likewise. * exec/priv.h: Likewise. * ext2fs/Makefile: Likewise. * ext2fs/balloc.c: Likewise. * ext2fs/dir.c: Likewise. * ext2fs/ext2fs.c: Likewise. * ext2fs/ext2fs.h: Likewise. * ext2fs/ialloc.c: Likewise. * ext2fs/inode.c: Likewise. * ext2fs/msg.c: Likewise. * ext2fs/pager.c: Likewise. * ext2fs/pokel.c: Likewise. * ext2fs/storeinfo.c: Likewise. * ext2fs/truncate.c: Likewise. * fatfs/Makefile: Likewise. * fatfs/dir.c: Likewise. * fatfs/fat.c: Likewise. * fatfs/fatfs.h: Likewise. * fatfs/inode.c: Likewise. * fatfs/main.c: Likewise. * fatfs/pager.c: Likewise. * fatfs/virt-inode.c: Likewise. * ftpfs/Makefile: Likewise. * ftpfs/ccache.c: Likewise. * ftpfs/ccache.h: Likewise. * ftpfs/conn.c: Likewise. * ftpfs/dir.c: Likewise. * ftpfs/fs.c: Likewise. * ftpfs/ftpfs.c: Likewise. * ftpfs/ftpfs.h: Likewise. * ftpfs/ncache.c: Likewise. * ftpfs/netfs.c: Likewise. * ftpfs/node.c: Likewise. * hostmux/Makefile: Likewise. * hostmux/hostmux.h: Likewise. * hostmux/mux.c: Likewise. * hostmux/node.c: Likewise. * hostmux/stubs.c: Likewise. * hurd/shared.h: Likewise. * isofs/Makefile: Likewise. * isofs/inode.c: Likewise. * isofs/lookup.c: Likewise. * isofs/main.c: Likewise. * isofs/pager.c: Likewise. * libcons/Makefile: Likewise. * libcons/cons-switch.c: Likewise. * libcons/cons.h: Likewise. * libcons/dir-changed.c: Likewise. * libcons/file-changed.c: Likewise. * libcons/init-init.c: Likewise. * libcons/vcons-close.c: Likewise. * libcons/vcons-input.c: Likewise. * libcons/vcons-move-mouse.c: Likewise. * libcons/vcons-open.c: Likewise. * libcons/vcons-scrollback.c: Likewise. * libdiskfs/Makefile: Likewise. * libdiskfs/boot-start.c: Likewise. * libdiskfs/dead-name.c: Likewise. * libdiskfs/dir-chg.c: Likewise. * libdiskfs/dir-link.c: Likewise. * libdiskfs/dir-lookup.c: Likewise. * libdiskfs/dir-mkdir.c: Likewise. * libdiskfs/dir-mkfile.c: Likewise. * libdiskfs/dir-readdir.c: Likewise. * libdiskfs/dir-rename.c: Likewise. * libdiskfs/dir-renamed.c: Likewise. * libdiskfs/dir-rmdir.c: Likewise. * libdiskfs/dir-unlink.c: Likewise. * libdiskfs/disk-pager.c: Likewise. * libdiskfs/diskfs-pager.h: Likewise. * libdiskfs/diskfs.h: Likewise. * libdiskfs/file-access.c: Likewise. * libdiskfs/file-chg.c: Likewise. * libdiskfs/file-exec.c: Likewise. * libdiskfs/file-get-fs-opts.c: Likewise. * libdiskfs/file-get-trans.c: Likewise. * libdiskfs/file-get-transcntl.c: Likewise. * libdiskfs/file-getcontrol.c: Likewise. * libdiskfs/file-getfh.c: Likewise. * libdiskfs/file-lock-stat.c: Likewise. * libdiskfs/file-lock.c: Likewise. * libdiskfs/file-reparent.c: Likewise. * libdiskfs/file-set-trans.c: Likewise. * libdiskfs/file-sync.c: Likewise. * libdiskfs/file-syncfs.c: Likewise. * libdiskfs/fsys-getroot.c: Likewise. * libdiskfs/fsys-options.c: Likewise. * libdiskfs/fsys-syncfs.c: Likewise. * libdiskfs/ifsock.c: Likewise. * libdiskfs/init-first.c: Likewise. * libdiskfs/init-init.c: Likewise. * libdiskfs/init-startup.c: Likewise. * libdiskfs/io-duplicate.c: Likewise. * libdiskfs/io-get-conch.c: Likewise. * libdiskfs/io-identity.c: Likewise. * libdiskfs/io-map-cntl.c: Likewise. * libdiskfs/io-map.c: Likewise. * libdiskfs/io-modes-get.c: Likewise. * libdiskfs/io-modes-off.c: Likewise. * libdiskfs/io-modes-on.c: Likewise. * libdiskfs/io-modes-set.c: Likewise. * libdiskfs/io-owner-get.c: Likewise. * libdiskfs/io-owner-mod.c: Likewise. * libdiskfs/io-prenotify.c: Likewise. * libdiskfs/io-read.c: Likewise. * libdiskfs/io-readable.c: Likewise. * libdiskfs/io-reauthenticate.c: Likewise. * libdiskfs/io-rel-conch.c: Likewise. * libdiskfs/io-restrict-auth.c: Likewise. * libdiskfs/io-revoke.c: Likewise. * libdiskfs/io-seek.c: Likewise. * libdiskfs/io-sigio.c: Likewise. * libdiskfs/io-stat.c: Likewise. * libdiskfs/io-write.c: Likewise. * libdiskfs/lookup.c: Likewise. * libdiskfs/name-cache.c: Likewise. * libdiskfs/node-drop.c: Likewise. * libdiskfs/node-make.c: Likewise. * libdiskfs/node-nput.c: Likewise. * libdiskfs/node-nputl.c: Likewise. * libdiskfs/node-nref.c: Likewise. * libdiskfs/node-nrefl.c: Likewise. * libdiskfs/node-nrele.c: Likewise. * libdiskfs/node-nrelel.c: Likewise. * libdiskfs/peropen-rele.c: Likewise. * libdiskfs/priv.h: Likewise. * libdiskfs/shutdown.c: Likewise. * libdiskfs/sync-interval.c: Likewise. * libfshelp/Makefile: Likewise. * libfshelp/fetch-root.c: Likewise. * libfshelp/fshelp.h: Likewise. * libfshelp/get-identity.c: Likewise. * libfshelp/lock-acquire.c: Likewise. * libfshelp/lock-init.c: Likewise. * libfshelp/locks.h: Likewise. * libfshelp/set-active.c: Likewise. * libfshelp/trans.h: Likewise. * libfshelp/transbox-init.c: Likewise. * libiohelp/Makefile: Likewise. * libiohelp/get_conch.c: Likewise. * libiohelp/handle_io_release_conch.c: Likewise. * libiohelp/initialize_conch.c: Likewise. * libiohelp/iohelp.h: Likewise. * libiohelp/verify_user_conch.c: Likewise. * libnetfs/Makefile: Likewise. * libnetfs/dir-lookup.c: Likewise. * libnetfs/dir-mkdir.c: Likewise. * libnetfs/dir-mkfile.c: Likewise. * libnetfs/dir-readdir.c: Likewise. * libnetfs/dir-rmdir.c: Likewise. * libnetfs/dir-unlink.c: Likewise. * libnetfs/drop-node.c: Likewise. * libnetfs/file-chauthor.c: Likewise. * libnetfs/file-check-access.c: Likewise. * libnetfs/file-chflags.c: Likewise. * libnetfs/file-chmod.c: Likewise. * libnetfs/file-chown.c: Likewise. * libnetfs/file-exec.c: Likewise. * libnetfs/file-get-storage-info.c: Likewise. * libnetfs/file-get-translator.c: Likewise. * libnetfs/file-lock-stat.c: Likewise. * libnetfs/file-lock.c: Likewise. * libnetfs/file-reparent.c: Likewise. * libnetfs/file-set-size.c: Likewise. * libnetfs/file-set-translator.c: Likewise. * libnetfs/file-statfs.c: Likewise. * libnetfs/file-sync.c: Likewise. * libnetfs/file-syncfs.c: Likewise. * libnetfs/file-utimes.c: Likewise. * libnetfs/fsys-getroot.c: Likewise. * libnetfs/fsys-set-options.c: Likewise. * libnetfs/init-init.c: Likewise. * libnetfs/io-clear-some-openmodes.c: Likewise. * libnetfs/io-duplicate.c: Likewise. * libnetfs/io-get-openmodes.c: Likewise. * libnetfs/io-get-owner.c: Likewise. * libnetfs/io-identity.c: Likewise. * libnetfs/io-mod-owner.c: Likewise. * libnetfs/io-read.c: Likewise. * libnetfs/io-readable.c: Likewise. * libnetfs/io-reauthenticate.c: Likewise. * libnetfs/io-restrict-auth.c: Likewise. * libnetfs/io-revoke.c: Likewise. * libnetfs/io-seek.c: Likewise. * libnetfs/io-set-all-openmodes.c: Likewise. * libnetfs/io-set-some-openmodes.c: Likewise. * libnetfs/io-stat.c: Likewise. * libnetfs/io-write.c: Likewise. * libnetfs/make-node.c: Likewise. * libnetfs/netfs.h: Likewise. * libnetfs/nput.c: Likewise. * libnetfs/nref.c: Likewise. * libnetfs/nrele.c: Likewise. * libnetfs/release-peropen.c: Likewise. * libnetfs/shutdown.c: Likewise. * libpager/Makefile: Likewise. * libpager/chg-compl.c: Likewise. * libpager/clean.c: Likewise. * libpager/data-request.c: Likewise. * libpager/data-return.c: Likewise. * libpager/data-unlock.c: Likewise. * libpager/inhibit-term.c: Likewise. * libpager/lock-completed.c: Likewise. * libpager/lock-object.c: Likewise. * libpager/mark-error.c: Likewise. * libpager/no-senders.c: Likewise. * libpager/object-init.c: Likewise. * libpager/object-terminate.c: Likewise. * libpager/offer-page.c: Likewise. * libpager/pager-attr.c: Likewise. * libpager/pager-create.c: Likewise. * libpager/pager-shutdown.c: Likewise. * libpager/priv.h: Likewise. * libpager/seqnos.c: Likewise. * libpipe/Makefile: Likewise. * libpipe/pipe.c: Likewise. * libpipe/pipe.h: Likewise. * libports/Makefile: Likewise. * libports/begin-rpc.c: Likewise. * libports/bucket-iterate.c: Likewise. * libports/claim-right.c: Likewise. * libports/class-iterate.c: Likewise. * libports/complete-deallocate.c: Likewise. * libports/count-bucket.c: Likewise. * libports/count-class.c: Likewise. * libports/create-bucket.c: Likewise. * libports/create-internal.c: Likewise. * libports/destroy-right.c: Likewise. * libports/enable-bucket.c: Likewise. * libports/enable-class.c: Likewise. * libports/end-rpc.c: Likewise. * libports/get-right.c: Likewise. * libports/import-port.c: Likewise. * libports/inhibit-all-rpcs.c: Likewise. * libports/inhibit-bucket-rpcs.c: Likewise. * libports/inhibit-class-rpcs.c: Likewise. * libports/inhibit-port-rpcs.c: Likewise. * libports/init.c: Likewise. * libports/interrupt-notified-rpcs.c: Likewise. * libports/interrupt-on-notify.c: Likewise. * libports/interrupt-operation.c: Likewise. * libports/interrupt-rpcs.c: Likewise. * libports/interrupted.c: Likewise. * libports/lookup-port.c: Likewise. * libports/manage-multithread.c: Likewise. * libports/no-senders.c: Likewise. * libports/port-deref-weak.c: Likewise. * libports/port-deref.c: Likewise. * libports/port-ref-weak.c: Likewise. * libports/port-ref.c: Likewise. * libports/ports.h: Likewise. * libports/reallocate-from-external.c: Likewise. * libports/reallocate-port.c: Likewise. * libports/resume-all-rpcs.c: Likewise. * libports/resume-bucket-rpcs.c: Likewise. * libports/resume-class-rpcs.c: Likewise. * libports/resume-port-rpcs.c: Likewise. * libports/stubs.c: Likewise. * libports/transfer-right.c: Likewise. * libstore/Makefile: Likewise. * libstore/gunzip.c: Likewise. * libstore/part.c: Likewise. * libstore/unzipstore.c: Likewise. * libthreads/Makefile: Likewise. * libtreefs/dir-lookup.c: Likewise. * libtreefs/fsys-getroot.c: Likewise. * libtreefs/fsys-hooks.c: Likewise. * libtreefs/fsys.c: Likewise. * libtreefs/trans-help.c: Likewise. * libtreefs/trans-start.c: Likewise. * libtreefs/treefs.h: Likewise. * libtrivfs/cntl-create.c: Likewise. * libtrivfs/dyn-classes.c: Likewise. * libtrivfs/io-reauthenticate.c: Likewise. * libtrivfs/io-restrict-auth.c: Likewise. * libtrivfs/protid-clean.c: Likewise. * libtrivfs/protid-dup.c: Likewise. * libtrivfs/trivfs.h: Likewise. * mach-defpager/Makefile: Likewise. * mach-defpager/default_pager.c: Likewise. * mach-defpager/kalloc.c: Likewise. * mach-defpager/main.c: Likewise. * nfs/Makefile: Likewise. * nfs/cache.c: Likewise. * nfs/main.c: Likewise. * nfs/mount.c: Likewise. * nfs/name-cache.c: Likewise. * nfs/nfs.h: Likewise. * nfs/ops.c: Likewise. * nfs/rpc.c: Likewise. * nfsd/Makefile: Likewise. * nfsd/cache.c: Likewise. * nfsd/loop.c: Likewise. * nfsd/main.c: Likewise. * nfsd/nfsd.h: Likewise. * pfinet/Makefile: Likewise. * pfinet/ethernet.c: Likewise. * pfinet/glue-include/asm/spinlock.h: Likewise. * pfinet/glue-include/linux/interrupt.h: Likewise. * pfinet/glue-include/linux/sched.h: Likewise. * pfinet/glue-include/linux/timer.h: Likewise. * pfinet/glue-include/linux/wait.h: Likewise. * pfinet/iioctl-ops.c: Likewise. * pfinet/io-ops.c: Likewise. * pfinet/kmem_cache.c: Likewise. * pfinet/main.c: Likewise. * pfinet/options.c: Likewise. * pfinet/pfinet-ops.c: Likewise. * pfinet/pfinet.h: Likewise. * pfinet/sched.c: Likewise. * pfinet/socket-ops.c: Likewise. * pfinet/socket.c: Likewise. * pfinet/timer-emul.c: Likewise. * pfinet/tunnel.c: Likewise. * pflocal/Makefile: Likewise. * pflocal/connq.c: Likewise. * pflocal/io.c: Likewise. * pflocal/sock.c: Likewise. * pflocal/sock.h: Likewise. * pflocal/socket.c: Likewise. * pflocal/sserver.c: Likewise. * proc/Makefile: Likewise. * proc/info.c: Likewise. * proc/main.c: Likewise. * proc/mgt.c: Likewise. * proc/msg.c: Likewise. * proc/proc.h: Likewise. * proc/stubs.c: Likewise. * proc/wait.c: Likewise. * storeio/Makefile: Likewise. * storeio/dev.c: Likewise. * storeio/dev.h: Likewise. * storeio/open.c: Likewise. * storeio/open.h: Likewise. * storeio/pager.c: Likewise. * storeio/storeio.c: Likewise. * term/Makefile: Likewise. * term/devio.c: Likewise. * term/hurdio.c: Likewise. * term/main.c: Likewise. * term/munge.c: Likewise. * term/ptyio.c: Likewise. * term/term.h: Likewise. * term/users.c: Likewise. * tmpfs/Makefile: Likewise. * tmpfs/dir.c: Likewise. * tmpfs/node.c: Likewise. * tmpfs/tmpfs.c: Likewise. * tmpfs/tmpfs.h: Likewise. * trans/Makefile: Likewise. * trans/fakeroot.c: Likewise. * trans/fifo.c: Likewise. * trans/hello-mt.c: Likewise. * trans/new-fifo.c: Likewise. * trans/streamio.c: Likewise. * ufs/Makefile: Likewise. * ufs/alloc.c: Likewise. * ufs/dir.c: Likewise. * ufs/hyper.c: Likewise. * ufs/inode.c: Likewise. * ufs/main.c: Likewise. * ufs/pager.c: Likewise. * ufs/pokeloc.c: Likewise. * ufs/sizes.c: Likewise. * ufs/ufs.h: Likewise. * usermux/Makefile: Likewise. * usermux/mux.c: Likewise. * usermux/node.c: Likewise. * usermux/usermux.h: Likewise. * utils/Makefile: Likewise. * utils/fakeauth.c: Likewise. * utils/rpctrace.c: Likewise. --- ufs/Makefile | 3 +- ufs/alloc.c | 38 ++++++++++----------- ufs/dir.c | 8 ++--- ufs/hyper.c | 10 +++--- ufs/inode.c | 44 ++++++++++++------------ ufs/main.c | 10 +++--- ufs/pager.c | 105 ++++++++++++++++++++++++++++++++++++---------------------- ufs/pokeloc.c | 14 ++++---- ufs/sizes.c | 47 +++++++++++++++++--------- ufs/ufs.h | 13 +++++--- 10 files changed, 170 insertions(+), 122 deletions(-) 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 #include -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 #include #include +#include #include #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. */ -- cgit v1.2.3 From 2490911ff4a4f5d8edf6058a97f71e8d75fc52a3 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sun, 25 Nov 2012 22:47:15 +0100 Subject: Move procfs to pthreads --- netfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netfs.c b/netfs.c index 24a6603f..a4d9f9c2 100644 --- a/netfs.c +++ b/netfs.c @@ -208,10 +208,10 @@ error_t netfs_attempt_lookup (struct iouser *user, struct node *dir, error_t err; err = procfs_lookup (dir, name, np); - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); if (! err) - mutex_lock (&(*np)->lock); + pthread_mutex_lock (&(*np)->lock); return err; } @@ -220,12 +220,12 @@ error_t netfs_attempt_lookup (struct iouser *user, struct node *dir, free all its associated storage. */ void netfs_node_norefs (struct node *np) { - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); procfs_cleanup (np); free (np); - spin_lock (&netfs_node_refcnt_lock); + pthread_spin_lock (&netfs_node_refcnt_lock); } -- cgit v1.2.3 From 3aef6957c38c5f6fcdcadc878ae16fb690485f95 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sun, 25 Nov 2012 23:12:41 +0100 Subject: Move DDE to pthreads Makefiles, headers, types, macros and function calls are renamed where appropriate. ds_server now takes a void* and returns a void*. * dde26_test/Makefile: Switch from cthreads to pthreads. * dde_e100/Makefile: Likewise. * dde_e100/main.c: Likewise. * dde26_test/Makefile: Likewise. * dde_e100/Makefile: Likewise. * dde_e100/main.c: Likewise. * dde_e1000/Makefile: Likewise. * dde_e1000/main.c: Likewise. * dde_ne2k_pci/Makefile: Likewise. * dde_ne2k_pci/main.c: Likewise. * dde_pcnet32/Makefile: Likewise. * dde_pcnet32/main.c: Likewise. * dde_pcnet32_test/Makefile: Likewise. * dde_rtl8139/Makefile: Likewise. * dde_rtl8139/main.c: Likewise. * libbpf/Makefile: Likewise. * libddekit/Makefile: Likewise. * libddekit/condvar.c: Likewise. * libddekit/lock.c: Likewise. * libddekit/pgtab.c: Likewise. * libddekit/thread.c: Likewise. * libddekit/timer.c: Likewise. * libhurd-slab/Makefile: Likewise. * libhurd-slab/slab.c: Likewise. * libhurd-slab/slab.h: Likewise. * libmachdev/Makefile: Likewise. * libmachdev/dev_hdr.h: Likewise. * libmachdev/ds_routines.c: Likewise. * libmachdev/if_hdr.h: Likewise. * libmachdev/io_req.h: Likewise. * libmachdev/machdev.h: Likewise. * libmachdev/net.c: Likewise. * libmachdev/queue.h: Likewise. --- dde26_test/Makefile | 2 +- dde_e100/Makefile | 2 +- dde_e100/main.c | 5 +- dde_e1000/Makefile | 2 +- dde_e1000/main.c | 5 +- dde_ne2k_pci/Makefile | 2 +- dde_ne2k_pci/main.c | 5 +- dde_pcnet32/Makefile | 2 +- dde_pcnet32/main.c | 5 +- dde_pcnet32_test/Makefile | 2 +- dde_rtl8139/Makefile | 2 +- dde_rtl8139/main.c | 5 +- libbpf/Makefile | 2 +- libddekit/Makefile | 3 +- libddekit/condvar.c | 24 ++++--- libddekit/lock.c | 21 +++--- libddekit/pgtab.c | 32 +++++----- libddekit/thread.c | 160 +++++++++++++++++++--------------------------- libddekit/timer.c | 5 +- libhurd-slab/Makefile | 2 +- libhurd-slab/slab.c | 20 +++--- libhurd-slab/slab.h | 4 +- libmachdev/Makefile | 3 +- libmachdev/dev_hdr.h | 6 +- libmachdev/ds_routines.c | 5 +- libmachdev/if_hdr.h | 6 +- libmachdev/io_req.h | 10 +-- libmachdev/machdev.h | 2 +- libmachdev/net.c | 4 +- libmachdev/queue.h | 14 ++-- 30 files changed, 178 insertions(+), 184 deletions(-) diff --git a/dde26_test/Makefile b/dde26_test/Makefile index 0ccbf521..1d6f8b67 100644 --- a/dde26_test/Makefile +++ b/dde26_test/Makefile @@ -11,7 +11,7 @@ TARGET = dde26_test SRC_C = main.c -LIBS += -ldde_linux26.o -ldde_linux26_block -ldde_linux26_char -ldde_linux26_net /root/hurd/libddekit/libddekit.a -lpciaccess -lthreads -lshouldbeinlibc +LIBS += -ldde_linux26.o -ldde_linux26_block -ldde_linux26_char -ldde_linux26_net /root/hurd/libddekit/libddekit.a -lpciaccess -lpthread -lshouldbeinlibc CFLAGS += -g # DDE configuration diff --git a/dde_e100/Makefile b/dde_e100/Makefile index db23a0ce..f8ce6063 100644 --- a/dde_e100/Makefile +++ b/dde_e100/Makefile @@ -7,7 +7,7 @@ TARGET = dde_e100 SRC_C = main.c e100.c -LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) +LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lpthread -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) CFLAGS += -g -I$(PKGDIR)/include -I$(BUILDDIR)/include # DDE configuration diff --git a/dde_e100/main.c b/dde_e100/main.c index 98f4452a..df8df1eb 100644 --- a/dde_e100/main.c +++ b/dde_e100/main.c @@ -12,6 +12,8 @@ int using_std = 1; int main(int argc, char **argv) { + pthread_t thread; + l4dde26_init(); l4dde26_process_init(); l4dde26_softirq_init(); @@ -25,7 +27,8 @@ int main(int argc, char **argv) mach_device_init(); trivfs_init(); - cthread_detach (cthread_fork (ds_server, NULL)); + pthread_create (&thread, NULL, ds_server, NULL); + pthread_detach (thread); trivfs_server(); return 0; diff --git a/dde_e1000/Makefile b/dde_e1000/Makefile index 376efe94..2062d0b5 100644 --- a/dde_e1000/Makefile +++ b/dde_e1000/Makefile @@ -7,7 +7,7 @@ TARGET = dde_e1000 SRC_C = main.c e1000_ethtool.c e1000_hw.c e1000_main.c e1000_param.c -LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) +LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lpthread -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) CFLAGS += -g -I$(PKGDIR)/include -I$(BUILDDIR)/include # DDE configuration diff --git a/dde_e1000/main.c b/dde_e1000/main.c index 98f4452a..df8df1eb 100644 --- a/dde_e1000/main.c +++ b/dde_e1000/main.c @@ -12,6 +12,8 @@ int using_std = 1; int main(int argc, char **argv) { + pthread_t thread; + l4dde26_init(); l4dde26_process_init(); l4dde26_softirq_init(); @@ -25,7 +27,8 @@ int main(int argc, char **argv) mach_device_init(); trivfs_init(); - cthread_detach (cthread_fork (ds_server, NULL)); + pthread_create (&thread, NULL, ds_server, NULL); + pthread_detach (thread); trivfs_server(); return 0; diff --git a/dde_ne2k_pci/Makefile b/dde_ne2k_pci/Makefile index f414a3f3..29396856 100644 --- a/dde_ne2k_pci/Makefile +++ b/dde_ne2k_pci/Makefile @@ -9,7 +9,7 @@ TARGET = dde_ne2k_pci SRC_C = main.c ne2k-pci.c 8390.c -LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) +LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lpthread -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) CFLAGS += -g -I$(PKGDIR)/include -I$(BUILDDIR)/include # DDE configuration diff --git a/dde_ne2k_pci/main.c b/dde_ne2k_pci/main.c index 98f4452a..df8df1eb 100644 --- a/dde_ne2k_pci/main.c +++ b/dde_ne2k_pci/main.c @@ -12,6 +12,8 @@ int using_std = 1; int main(int argc, char **argv) { + pthread_t thread; + l4dde26_init(); l4dde26_process_init(); l4dde26_softirq_init(); @@ -25,7 +27,8 @@ int main(int argc, char **argv) mach_device_init(); trivfs_init(); - cthread_detach (cthread_fork (ds_server, NULL)); + pthread_create (&thread, NULL, ds_server, NULL); + pthread_detach (thread); trivfs_server(); return 0; diff --git a/dde_pcnet32/Makefile b/dde_pcnet32/Makefile index 18cd336c..1bf47c4c 100644 --- a/dde_pcnet32/Makefile +++ b/dde_pcnet32/Makefile @@ -7,7 +7,7 @@ TARGET = dde_pcnet32 SRC_C = main.c pcnet32.c -LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) +LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lpthread -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) CFLAGS += -g -I$(PKGDIR)/include -I$(BUILDDIR)/include # DDE configuration diff --git a/dde_pcnet32/main.c b/dde_pcnet32/main.c index 98f4452a..df8df1eb 100644 --- a/dde_pcnet32/main.c +++ b/dde_pcnet32/main.c @@ -12,6 +12,8 @@ int using_std = 1; int main(int argc, char **argv) { + pthread_t thread; + l4dde26_init(); l4dde26_process_init(); l4dde26_softirq_init(); @@ -25,7 +27,8 @@ int main(int argc, char **argv) mach_device_init(); trivfs_init(); - cthread_detach (cthread_fork (ds_server, NULL)); + pthread_create (&thread, NULL, ds_server, NULL); + pthread_detach (thread); trivfs_server(); return 0; diff --git a/dde_pcnet32_test/Makefile b/dde_pcnet32_test/Makefile index c0956691..9f6f11d7 100644 --- a/dde_pcnet32_test/Makefile +++ b/dde_pcnet32_test/Makefile @@ -9,7 +9,7 @@ TARGET = dde_pcnet32 SRC_C = main.c arping.c pcnet32.c -LIBS += -ldde_linux26.o -ldde_linux26_block -ldde_linux26_char -ldde_linux26_net /root/hurd/libddekit/libddekit.a -lpciaccess -lthreads -lshouldbeinlibc +LIBS += -ldde_linux26.o -ldde_linux26_block -ldde_linux26_char -ldde_linux26_net /root/hurd/libddekit/libddekit.a -lpciaccess -lpthread -lshouldbeinlibc CFLAGS += -g # DDE configuration diff --git a/dde_rtl8139/Makefile b/dde_rtl8139/Makefile index f2c49547..95b6fa0a 100644 --- a/dde_rtl8139/Makefile +++ b/dde_rtl8139/Makefile @@ -9,7 +9,7 @@ TARGET = dde_rtl8139 SRC_C = main.c 8139cp.c -LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) +LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lpthread -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path) CFLAGS += -g -I$(PKGDIR)/include -I$(BUILDDIR)/include # DDE configuration diff --git a/dde_rtl8139/main.c b/dde_rtl8139/main.c index 98f4452a..7007b075 100644 --- a/dde_rtl8139/main.c +++ b/dde_rtl8139/main.c @@ -12,6 +12,8 @@ int using_std = 1; int main(int argc, char **argv) { + pthread_t thread; + l4dde26_init(); l4dde26_process_init(); l4dde26_softirq_init(); @@ -25,7 +27,8 @@ int main(int argc, char **argv) mach_device_init(); trivfs_init(); - cthread_detach (cthread_fork (ds_server, NULL)); + pthread_create (&thread, NULL, ds_server, NULL; + pthread_detach (thread); trivfs_server(); return 0; diff --git a/libbpf/Makefile b/libbpf/Makefile index 1000429d..ec0723c9 100644 --- a/libbpf/Makefile +++ b/libbpf/Makefile @@ -26,7 +26,7 @@ installhdrs = bpf_impl.h MIGSTUBS = OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS)) -HURDLIBS = threads +OTHERLIBS = -lpthread MIGCOMSFLAGS = diff --git a/libddekit/Makefile b/libddekit/Makefile index 29000cd9..a11534b7 100644 --- a/libddekit/Makefile +++ b/libddekit/Makefile @@ -40,7 +40,8 @@ LCLHDRS = $(installhdrs) \ MIGSTUBS = deviceUser.o machUser.o OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS)) -HURDLIBS = threads ports shouldbeinlibc hurd-slab +HURDLIBS = ports shouldbeinlibc hurd-slab +OTHERLIBS = -lpthread MIGCOMSFLAGS = -prefix dde_ diff --git a/libddekit/condvar.c b/libddekit/condvar.c index 55c57f8b..64df3ed6 100644 --- a/libddekit/condvar.c +++ b/libddekit/condvar.c @@ -4,31 +4,35 @@ * * \author Thomas Friebel */ -#include +#include +#include "ddekit/memory.h" #include "ddekit/condvar.h" struct ddekit_condvar { - struct condition cond; + pthread_cond_t cond; }; ddekit_condvar_t *ddekit_condvar_init() { - struct condition *cvp; + ddekit_condvar_t *cvp; - cvp = condition_alloc (); - condition_init (cvp); + cvp = ddekit_simple_malloc (sizeof (*cvp)); - return (ddekit_condvar_t *) cvp; + if (cvp == NULL) + return NULL; + + pthread_cond_init (&cvp->cond, NULL); + return cvp; } void ddekit_condvar_deinit(ddekit_condvar_t *cvp) { - condition_free (&cvp->cond); + ddekit_simple_free (cvp); } void ddekit_condvar_wait(ddekit_condvar_t *cvp, ddekit_lock_t *mp) { /* This isn't nice. The encapsulation is broken. * TODO I can merge the two files condvar.c and lock.c. */ - condition_wait (&cvp->cond, (struct mutex *) *mp); + pthread_cond_wait (&cvp->cond, (pthread_mutex_t *) *mp); } int ddekit_condvar_wait_timed(ddekit_condvar_t *cvp, @@ -40,9 +44,9 @@ int ddekit_condvar_wait_timed(ddekit_condvar_t *cvp, void ddekit_condvar_signal(ddekit_condvar_t *cvp) { - condition_signal (&cvp->cond); + pthread_cond_signal (&cvp->cond); } void ddekit_condvar_broadcast(ddekit_condvar_t *cvp) { - condition_broadcast (&cvp->cond); + pthread_cond_broadcast (&cvp->cond); } diff --git a/libddekit/lock.c b/libddekit/lock.c index e534bebe..26d5cfc8 100644 --- a/libddekit/lock.c +++ b/libddekit/lock.c @@ -1,38 +1,39 @@ -#include +#include #include "ddekit/lock.h" #include "ddekit/memory.h" +#include "ddekit/thread.h" #define DDEKIT_DEBUG_LOCKS 0 struct ddekit_lock { - struct mutex lock; - cthread_t helder; + pthread_mutex_t lock; + ddekit_thread_t *helder; }; void _ddekit_lock_init(struct ddekit_lock **mtx) { struct ddekit_lock *lock; lock = (struct ddekit_lock *) ddekit_simple_malloc (sizeof *lock); - mutex_init (&lock->lock); + pthread_mutex_init (&lock->lock, NULL); lock->helder = NULL; *mtx = lock; } void _ddekit_lock_deinit(struct ddekit_lock **mtx) { - mutex_free (*mtx); + ddekit_simple_free (*mtx); *mtx = NULL; } void _ddekit_lock_lock(struct ddekit_lock **mtx) { - mutex_lock (&(*mtx)->lock); - (*mtx)->helder = cthread_self (); + pthread_mutex_lock (&(*mtx)->lock); + (*mtx)->helder = ddekit_thread_myself (); } /* returns 0 on success, != 0 if it would block */ int _ddekit_lock_try_lock(struct ddekit_lock **mtx) { - if (mutex_try_lock (&(*mtx)->lock)) { /* lock succeessfully */ - (*mtx)->helder = cthread_self (); + if (!pthread_mutex_trylock (&(*mtx)->lock)) { /* lock succeessfully */ + (*mtx)->helder = ddekit_thread_myself (); return 0; } return -1; @@ -41,7 +42,7 @@ int _ddekit_lock_try_lock(struct ddekit_lock **mtx) { void _ddekit_lock_unlock(struct ddekit_lock **mtx) { // TODO I wonder if it can cause any trouble. (*mtx)->helder = NULL; - mutex_unlock (&(*mtx)->lock); + pthread_mutex_unlock (&(*mtx)->lock); } diff --git a/libddekit/pgtab.c b/libddekit/pgtab.c index e7a94599..81138108 100644 --- a/libddekit/pgtab.c +++ b/libddekit/pgtab.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "ddekit/pgtab.h" #include "util.h" @@ -35,7 +35,7 @@ static struct entry *regions; static int num_regions; /* The size of the array REGIONS */ static int capability; -static struct mutex lock; +static pthread_mutex_t lock; #define INIT_SIZE 128 /***************************** @@ -78,15 +78,15 @@ static struct entry *get_entry_from_virt (const ddekit_addr_t virt) ddekit_addr_t ddekit_pgtab_get_physaddr(const void *virtual) { struct entry *e; - mutex_lock (&lock); + pthread_mutex_lock (&lock); e = get_entry_from_virt ((ddekit_addr_t) virtual); if (e) { ddekit_addr_t phys = e->physical + (virtual - e->virtual); - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); return phys; } - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); ddekit_printf ("a virtual address %p doesn't exist.\n", virtual); return -1; @@ -102,16 +102,16 @@ ddekit_addr_t ddekit_pgtab_get_virtaddr(const ddekit_addr_t physical) { struct entry *e; - mutex_lock (&lock); + pthread_mutex_lock (&lock); e = get_entry_from_phys (physical); if (e) { ddekit_addr_t virt = (ddekit_addr_t) e->virtual + (physical - e->physical); - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); return virt; } - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); ddekit_printf ("a physical address %p doesn't exist.\n", physical); @@ -139,15 +139,15 @@ int ddekit_pgtab_get_type(const void *virtual) int ddekit_pgtab_get_size(const void *virtual) { struct entry *e; - mutex_lock (&lock); + pthread_mutex_lock (&lock); e = get_entry_from_virt ((ddekit_addr_t) virtual); if (e) { int size = e->size; - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); return size; } - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); return 0; } @@ -162,14 +162,14 @@ void ddekit_pgtab_clear_region(void *virtual, int type) { struct entry *e; - mutex_lock (&lock); + pthread_mutex_lock (&lock); e = get_entry_from_virt ((ddekit_addr_t) virtual); if (e) { *e = regions[num_regions - 1]; num_regions--; } - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); } @@ -188,7 +188,7 @@ void ddekit_pgtab_set_region(void *virtual, ddekit_addr_t physical, int pages, i void ddekit_pgtab_set_region_with_size(void *virt, ddekit_addr_t phys, int size, int type) { - mutex_lock (&lock); + pthread_mutex_lock (&lock); if (num_regions == capability) { capability *= 2; @@ -201,13 +201,13 @@ void ddekit_pgtab_set_region_with_size(void *virt, ddekit_addr_t phys, int size, regions[num_regions].size = size; regions[num_regions].type = type; num_regions++; - mutex_unlock (&lock); + pthread_mutex_unlock (&lock); } int pgtab_init () { capability = INIT_SIZE; regions = malloc (sizeof (struct entry) * capability); - mutex_init (&lock); + pthread_mutex_init (&lock, NULL); return 0; } diff --git a/libddekit/thread.c b/libddekit/thread.c index 10b86de8..8f7b3ed9 100644 --- a/libddekit/thread.c +++ b/libddekit/thread.c @@ -1,8 +1,9 @@ #include #include -#include +#include #include #include +#include #include #include #include @@ -26,39 +27,30 @@ struct _ddekit_private_data { }; struct ddekit_thread { - struct cthread thread; + pthread_t thread; + char *name; + struct _ddekit_private_data *private; + void *user; }; struct ddekit_sem { - spin_lock_t lock; + pthread_spinlock_t lock; /* A list of thread waiting for the semaphore. */ struct list head; int value; }; -static struct mutex global_lock = MUTEX_INITIALIZER; +static __thread struct ddekit_thread *thread_self; static void _thread_cleanup () { - const char *name; - struct _ddekit_private_data *data; - cthread_t t = cthread_self (); - - /* I have to free the sleep condition variable - * before the thread exits. */ - mutex_lock (&global_lock); - data = cthread_ldata (t); - cthread_set_ldata (t, NULL); - mutex_unlock (&global_lock); mach_port_destroy (mach_task_self (), - data->wakeupmsg.msgh_remote_port); - ddekit_condvar_deinit (data->sleep_cond); - ddekit_simple_free (data); - - name = cthread_name (t); - cthread_set_name (t, NULL); - ddekit_simple_free ((char *) name); + thread_self->private->wakeupmsg.msgh_remote_port); + ddekit_condvar_deinit (thread_self->private->sleep_cond); + ddekit_simple_free (thread_self->private); + ddekit_simple_free (thread_self->name); + ddekit_simple_free (thread_self); } /* Prepare a wakeup message. */ @@ -105,15 +97,9 @@ static void setup_thread (struct ddekit_thread *t, const char *name) { else strcpy (cpy, name); - cthread_set_name (&t->thread, cpy); + t->name = cpy; } - /* - * ldata isn't used by cthread. Since cthread isn't exposed to - * the user of this library. It's very safe to store - * the condition variable in ldata. - */ - private_data = (struct _ddekit_private_data *) ddekit_simple_malloc (sizeof (*private_data)); @@ -126,15 +112,13 @@ static void setup_thread (struct ddekit_thread *t, const char *name) { if (err) error (1, err, "_create_wakeupmsg"); - mutex_lock (&global_lock); - cthread_set_ldata (&t->thread, private_data); - mutex_unlock (&global_lock); + t->private = private_data; } ddekit_thread_t *ddekit_thread_setup_myself(const char *name) { - ddekit_thread_t *td = ddekit_thread_myself(); - + ddekit_thread_t *td = (ddekit_thread_t *) malloc (sizeof (*td)); setup_thread (td, name); + thread_self = td; return td; } @@ -142,54 +126,58 @@ typedef struct { void (*fun)(void *); void *arg; - struct condition cond; - struct mutex lock; + struct ddekit_thread *td; + pthread_cond_t cond; + pthread_mutex_t lock; int status; } priv_arg_t; static void* _priv_fun (void *arg) { priv_arg_t *priv_arg = arg; + thread_self = priv_arg->td; /* We wait until the initialization of the thread is finished. */ - mutex_lock (&priv_arg->lock); + pthread_mutex_lock (&priv_arg->lock); while (!priv_arg->status) - condition_wait (&priv_arg->cond, &priv_arg->lock); - mutex_unlock (&priv_arg->lock); + pthread_cond_wait (&priv_arg->cond, &priv_arg->lock); + pthread_mutex_unlock (&priv_arg->lock); priv_arg->fun(priv_arg->arg); + free (priv_arg->arg); _thread_cleanup (); return NULL; } ddekit_thread_t *ddekit_thread_create(void (*fun)(void *), void *arg, const char *name) { - ddekit_thread_t *td; - priv_arg_t *priv_arg = (priv_arg_t *) malloc (sizeof (*priv_arg)); + ddekit_thread_t *td = (ddekit_thread_t *) malloc (sizeof (*td)); + setup_thread (td, name); + priv_arg_t *priv_arg = (priv_arg_t *) malloc (sizeof (*priv_arg)); priv_arg->fun = fun; priv_arg->arg = arg; - condition_init (&priv_arg->cond); - mutex_init (&priv_arg->lock); + priv_arg->td = td; + pthread_cond_init (&priv_arg->cond, NULL); + pthread_mutex_init (&priv_arg->lock, NULL); priv_arg->status = 0; - td = (ddekit_thread_t *) cthread_fork (_priv_fun, priv_arg); - cthread_detach (&td->thread); - setup_thread (td, name); + pthread_create (&td->thread, NULL, _priv_fun, priv_arg); + pthread_detach (td->thread); /* Tell the new thread that initialization has been finished. */ - mutex_lock (&priv_arg->lock); + pthread_mutex_lock (&priv_arg->lock); priv_arg->status = 1; - cond_signal (&priv_arg->cond); - mutex_unlock (&priv_arg->lock); + pthread_cond_signal (&priv_arg->cond); + pthread_mutex_unlock (&priv_arg->lock); return td; } ddekit_thread_t *ddekit_thread_myself(void) { - return (ddekit_thread_t *) cthread_self (); + return thread_self; } void ddekit_thread_set_data(ddekit_thread_t *thread, void *data) { - cthread_set_data ((cthread_t) thread, data); + thread->user = data; } void ddekit_thread_set_my_data(void *data) { @@ -197,7 +185,7 @@ void ddekit_thread_set_my_data(void *data) { } void *ddekit_thread_get_data(ddekit_thread_t *thread) { - return cthread_data ((cthread_t) thread); + return thread->user; } void *ddekit_thread_get_my_data() { @@ -239,47 +227,36 @@ void ddekit_thread_nsleep(unsigned long nsecs) { } void ddekit_thread_sleep(ddekit_lock_t *lock) { - struct _ddekit_private_data *data; - - mutex_lock (&global_lock); - data= cthread_ldata (cthread_self ()); - mutex_unlock (&global_lock); - - // TODO condition_wait cannot guarantee that the thread is + // TODO pthread_cond_wait cannot guarantee that the thread is // woke up by another thread, maybe by signals. // Does it matter here? - ddekit_condvar_wait (data->sleep_cond, lock); + // If it does, use pthread_hurd_cond_wait_np. + ddekit_condvar_wait (thread_self->private->sleep_cond, lock); } void ddekit_thread_wakeup(ddekit_thread_t *td) { - struct _ddekit_private_data *data; - - mutex_lock (&global_lock); - data = cthread_ldata (&td->thread); - mutex_unlock (&global_lock); - - if (data == NULL) + if (td->private == NULL) return; - ddekit_condvar_signal (data->sleep_cond); + ddekit_condvar_signal (td->private->sleep_cond); } void ddekit_thread_exit() { _thread_cleanup (); - cthread_exit (0); + pthread_exit (NULL); } const char *ddekit_thread_get_name(ddekit_thread_t *thread) { - return cthread_name ((cthread_t) thread); + return thread->name; } void ddekit_thread_schedule(void) { - cthread_yield(); + swtch_pri (0); } void ddekit_yield(void) { - cthread_yield(); + swtch_pri (0); } void ddekit_init_threads() { @@ -324,34 +301,29 @@ static void _block (struct _ddekit_private_data *data) static int _sem_timedwait_internal (ddekit_sem_t *restrict sem, const int timeout) { - struct _ddekit_private_data *self_private_data; - - spin_lock (&sem->lock); + pthread_spin_lock (&sem->lock); if (sem->value > 0) { /* Successful down. */ sem->value --; - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); return 0; } if (timeout < 0) { + pthread_spin_unlock (&sem->lock); errno = EINVAL; return -1; } /* Add ourselves to the queue. */ - mutex_lock (&global_lock); - self_private_data = cthread_ldata (cthread_self ()); - mutex_unlock (&global_lock); - - add_entry_head (&sem->head, (struct list *) self_private_data); - spin_unlock (&sem->lock); + add_entry_head (&sem->head, &thread_self->private->list); + pthread_spin_unlock (&sem->lock); /* Block the thread. */ if (timeout) { error_t err; - err = _timedblock (self_private_data, timeout); + err = _timedblock (thread_self->private, timeout); if (err) { /* We timed out. We may need to disconnect ourself from the waiter queue. @@ -361,16 +333,16 @@ static int _sem_timedwait_internal (ddekit_sem_t *restrict sem, block. */ assert (err == ETIMEDOUT); - spin_lock (&sem->lock); - remove_entry ((struct list *) self_private_data); - spin_unlock (&sem->lock); + pthread_spin_lock (&sem->lock); + remove_entry (&thread_self->private->list); + pthread_spin_unlock (&sem->lock); errno = err; return -1; } } else - _block (self_private_data); + _block (thread_self->private); return 0; } @@ -390,7 +362,7 @@ ddekit_sem_t *ddekit_sem_init(int value) { ddekit_sem_t *sem = (ddekit_sem_t *) ddekit_simple_malloc (sizeof (*sem)); - sem->lock = SPIN_LOCK_INITIALIZER; + sem->lock = PTHREAD_SPINLOCK_INITIALIZER; sem->head.prev = &sem->head; sem->head.next = &sem->head; sem->value = value; @@ -411,14 +383,14 @@ void ddekit_sem_down(ddekit_sem_t *sem) { /* returns 0 on success, != 0 when it would block */ int ddekit_sem_down_try(ddekit_sem_t *sem) { - spin_lock (&sem->lock); + pthread_spin_lock (&sem->lock); if (sem->value > 0) { /* Successful down. */ sem->value --; - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); return 0; } - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); return -1; } @@ -432,19 +404,19 @@ int ddekit_sem_down_timed(ddekit_sem_t *sem, int timo) { void ddekit_sem_up(ddekit_sem_t *sem) { struct _ddekit_private_data *wakeup; - spin_lock (&sem->lock); + pthread_spin_lock (&sem->lock); if (sem->value > 0) { /* Do a quick up. */ assert (EMPTY_LIST (&sem->head)); sem->value ++; - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); return; } if (EMPTY_LIST (&sem->head)) { /* No one waiting. */ sem->value = 1; - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); return; } @@ -455,7 +427,7 @@ void ddekit_sem_up(ddekit_sem_t *sem) { struct _ddekit_private_data, list); /* Then drop the lock and transfer control. */ - spin_unlock (&sem->lock); + pthread_spin_unlock (&sem->lock); if (wakeup) _thread_wakeup (wakeup); } diff --git a/libddekit/timer.c b/libddekit/timer.c index a8a91a85..169f867c 100644 --- a/libddekit/timer.c +++ b/libddekit/timer.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "ddekit/lock.h" @@ -322,12 +321,12 @@ void ddekit_init_timers(void) { error_t err; struct timeval tp; - static boolean_t initialized = FALSE; + static int initialized = 0; if (initialized) return; - initialized = TRUE; + initialized = 1; err = maptime_map (0, 0, &mapped_time); if (err) error (2, err, "cannot map time device"); diff --git a/libhurd-slab/Makefile b/libhurd-slab/Makefile index f109f59b..925f70c1 100644 --- a/libhurd-slab/Makefile +++ b/libhurd-slab/Makefile @@ -26,7 +26,7 @@ installhdrs = slab.h MIGSTUBS = OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS)) -HURDLIBS = threads +OTHERLIBS = -lpthread MIGCOMSFLAGS = diff --git a/libhurd-slab/slab.c b/libhurd-slab/slab.c index b20a8e74..5a12a43a 100644 --- a/libhurd-slab/slab.c +++ b/libhurd-slab/slab.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include "slab.h" @@ -337,7 +337,7 @@ hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, - sizeof (union hurd_bufctl))) return EINVAL; - err = mutex_init (&space->lock); + err = pthread_mutex_init (&space->lock, NULL); if (err) return err; @@ -393,11 +393,11 @@ hurd_slab_destroy (hurd_slab_space_t space) /* The caller wants to destroy the slab. It can not be destroyed if there are any outstanding memory allocations. */ - mutex_lock (&space->lock); + pthread_mutex_lock (&space->lock); err = reap (space); if (err) { - mutex_unlock (&space->lock); + pthread_mutex_unlock (&space->lock); return err; } @@ -405,7 +405,7 @@ hurd_slab_destroy (hurd_slab_space_t space) { /* There are still slabs, i.e. there is outstanding allocations. Return EBUSY. */ - mutex_unlock (&space->lock); + pthread_mutex_unlock (&space->lock); return EBUSY; } @@ -436,7 +436,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) error_t err; union hurd_bufctl *bufctl; - mutex_lock (&space->lock); + pthread_mutex_lock (&space->lock); /* If there is no slabs with free buffer, the cache has to be expanded with another slab. If the slab space has not yet been @@ -446,7 +446,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) err = grow (space); if (err) { - mutex_unlock (&space->lock); + pthread_mutex_unlock (&space->lock); return err; } } @@ -477,7 +477,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) space->first_free = new_first; } *buffer = ((void *) bufctl) - (space->size - sizeof *bufctl); - mutex_unlock (&space->lock); + pthread_mutex_unlock (&space->lock); return 0; } @@ -501,7 +501,7 @@ hurd_slab_dealloc (hurd_slab_space_t space, void *buffer) assert (space->initialized); - mutex_lock (&space->lock); + pthread_mutex_lock (&space->lock); bufctl = (buffer + (space->size - sizeof *bufctl)); put_on_slab_list (slab = bufctl->slab, bufctl); @@ -514,5 +514,5 @@ hurd_slab_dealloc (hurd_slab_space_t space, void *buffer) || slab->refcount < space->first_free->refcount) space->first_free = slab; - mutex_unlock (&space->lock); + pthread_mutex_unlock (&space->lock); } diff --git a/libhurd-slab/slab.h b/libhurd-slab/slab.h index d42fd4c3..6eeb8e48 100644 --- a/libhurd-slab/slab.h +++ b/libhurd-slab/slab.h @@ -24,7 +24,7 @@ #include #include -#include +#include /* Allocate a buffer in *PTR of size SIZE which must be a power of 2 @@ -67,7 +67,7 @@ struct hurd_slab_space /* Protects this structure, along with all the slabs. No need to delay initialization of this field. */ - struct mutex lock; + pthread_mutex_t lock; /* The size and alignment of objects allocated using this slab space. These to fields are used to calculate the final object diff --git a/libmachdev/Makefile b/libmachdev/Makefile index ad090cae..728fe82e 100644 --- a/libmachdev/Makefile +++ b/libmachdev/Makefile @@ -25,7 +25,8 @@ LCLHDRS = dev_hdr.h device_emul.h ds_routines.h vm_param.h \ util.h queue.h io_req.h if_ether.h machdev.h linux-errno.h \ errno-base.h installhdrs = machdev.h -HURDLIBS = ports threads trivfs ddekit bpf +HURDLIBS = ports trivfs ddekit bpf +OTHERLIBS = -lpthread OBJS = $(SRCS:.c=.o) $(MIGSTUBS) include ../Makeconf diff --git a/libmachdev/dev_hdr.h b/libmachdev/dev_hdr.h index f6394256..79edc43a 100644 --- a/libmachdev/dev_hdr.h +++ b/libmachdev/dev_hdr.h @@ -59,7 +59,7 @@ #include #include #include -#include +#include #include "device_emul.h" @@ -127,7 +127,7 @@ boolean_t dev_map(boolean_t (*)(), mach_port_t); /* * To lock and unlock state and open-count */ -#define device_lock(device) mutex_lock(&(device)->lock) -#define device_unlock(device) mutex_unlock(&(device)->lock) +#define device_lock(device) pthread_mutex_lock(&(device)->lock) +#define device_unlock(device) pthread_mutex_unlock(&(device)->lock) #endif /* _DEVICE_DEV_HDR_H_ */ diff --git a/libmachdev/ds_routines.c b/libmachdev/ds_routines.c index 6b8d1d4d..63457553 100644 --- a/libmachdev/ds_routines.c +++ b/libmachdev/ds_routines.c @@ -59,7 +59,6 @@ #include #include -#include #include @@ -467,7 +466,7 @@ void reg_dev_emul (struct device_emulation_ops *ops) emulation_list[num_emul++] = ops; } -void ds_server() +void * ds_server(void *arg) { /* This thread calls Linux functions, * so I need to make it known to the Linux environment. */ @@ -478,4 +477,6 @@ void ds_server() { ports_manage_port_operations_one_thread (port_bucket, demuxer, 0); } while (1); + + return NULL; } diff --git a/libmachdev/if_hdr.h b/libmachdev/if_hdr.h index 32497206..b20f7e35 100644 --- a/libmachdev/if_hdr.h +++ b/libmachdev/if_hdr.h @@ -61,7 +61,7 @@ #define _IF_HDR_ #include -#include +#include #include #if 0 @@ -94,8 +94,8 @@ struct ifnet { char *if_address; /* pointer to hardware address */ // struct ifqueue if_snd; /* output queue */ if_filter_list_t port_list; - struct mutex if_rcv_port_list_lock;/* lock for input filter list */ - struct mutex if_snd_port_list_lock;/* lock for output filter list */ + pthread_mutex_t if_rcv_port_list_lock;/* lock for input filter list */ + pthread_mutex_t if_snd_port_list_lock;/* lock for output filter list */ /* statistics */ int if_ipackets; /* packets received */ int if_ierrors; /* input errors */ diff --git a/libmachdev/io_req.h b/libmachdev/io_req.h index df8d743c..9c810542 100644 --- a/libmachdev/io_req.h +++ b/libmachdev/io_req.h @@ -32,7 +32,7 @@ #define _IO_REQ_ #include -#include +#include #include "dev_hdr.h" @@ -72,7 +72,7 @@ struct io_req { struct io_req * io_rlink; /* reverse link (for driver header) */ // vm_map_copy_t io_copy; /* vm_map_copy obj. for this op. */ long io_total; /* total op size, for write */ - struct mutex io_req_lock; + pthread_mutex_t io_req_lock; // decl_simple_lock_data(,io_req_lock) /* Lock for this structure */ long io_physrec; /* mapping to the physical block @@ -90,8 +90,8 @@ struct io_req { * happen simultaneously on different processors. */ -#define ior_lock(ior) mutex_lock(&(ior)->io_req_lock) -#define ior_unlock(ior) mutex_unlock(&(ior)->io_req_lock) +#define ior_lock(ior) pthread_mutex_lock(&(ior)->io_req_lock) +#define ior_unlock(ior) pthread_mutex_unlock(&(ior)->io_req_lock) /* * Flags and operations @@ -123,7 +123,7 @@ void iodone(io_req_t); #define io_req_alloc(ior,size) \ MACRO_BEGIN \ (ior) = (io_req_t)malloc(sizeof(struct io_req)); \ - mutex_init(&(ior)->io_req_lock); \ + pthread_mutex_init(&(ior)->io_req_lock, NULL); \ MACRO_END #define io_req_free(ior) \ diff --git a/libmachdev/machdev.h b/libmachdev/machdev.h index cfa4b2d4..b9186fba 100644 --- a/libmachdev/machdev.h +++ b/libmachdev/machdev.h @@ -23,7 +23,7 @@ #ifndef __MACHDEV_H__ #define __MACHDEV_H__ -void ds_server(void); +void * ds_server(void *); void mach_device_init(void); void register_net(void); void register_block(void); diff --git a/libmachdev/net.c b/libmachdev/net.c index ed52f0e4..4b4cfe7c 100644 --- a/libmachdev/net.c +++ b/libmachdev/net.c @@ -288,8 +288,8 @@ void if_init_queues(ifp) // IFQ_INIT(&ifp->if_snd); queue_init(&ifp->port_list.if_rcv_port_list); queue_init(&ifp->port_list.if_snd_port_list); - mutex_init(&ifp->if_rcv_port_list_lock); - mutex_init(&ifp->if_snd_port_list_lock); + pthread_mutex_init(&ifp->if_rcv_port_list_lock, NULL); + pthread_mutex_init(&ifp->if_snd_port_list_lock, NULL); } static io_return_t diff --git a/libmachdev/queue.h b/libmachdev/queue.h index 0637dede..86ef74dc 100644 --- a/libmachdev/queue.h +++ b/libmachdev/queue.h @@ -35,7 +35,7 @@ #ifndef _KERN_QUEUE_H_ #define _KERN_QUEUE_H_ -#include +#include /* * Queue of abstract objects. Queue is maintained @@ -337,7 +337,7 @@ void insque(queue_entry_t, queue_entry_t); */ struct mpqueue_head { struct queue_entry head; /* header for queue */ - struct mutex lock; /* lock for queue */ + pthread_mutex_t lock; /* lock for queue */ }; typedef struct mpqueue_head mpqueue_head_t; @@ -347,21 +347,21 @@ typedef struct mpqueue_head mpqueue_head_t; #define mpqueue_init(q) \ { \ queue_init(&(q)->head); \ - mutex_init(&(q)->lock); \ + pthread_mutex_init(&(q)->lock, NULL); \ } #define mpenqueue_tail(q, elt) \ - mutex_lock(&(q)->lock); \ + pthread_mutex_lock(&(q)->lock); \ enqueue_tail(&(q)->head, elt); \ - mutex_unlock(&(q)->lock); + pthread_mutex_unlock(&(q)->lock); #define mpdequeue_head(q, elt) \ - mutex_lock(&(q)->lock); \ + pthread_mutex_lock(&(q)->lock); \ if (queue_empty(&(q)->head)) \ *(elt) = 0; \ else \ *(elt) = dequeue_head(&(q)->head); \ - mutex_unlock(&(q)->lock); + pthread_mutex_unlock(&(q)->lock); /* * Old queue stuff, will go away soon. -- cgit v1.2.3 From f5bb8136206edbbd390542717e10b6e854aac68c Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sun, 25 Nov 2012 22:50:26 +0100 Subject: Move random to pthreads Makefiles, headers, types, macros and function calls are renamed where appropriate. * random.c: Switch from cthreads to pthreads. * Makefile: Likewise. --- random.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/random.c b/random.c index 0ae31f5f..5ef814f4 100644 --- a/random.c +++ b/random.c @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include @@ -39,8 +39,8 @@ struct trivfs_control *fsys; int read_blocked; /* For read and select. */ -struct condition wait; /* For read and select. */ -struct condition select_alert; /* For read and select. */ +pthread_cond_t wait; /* For read and select. */ +pthread_cond_t select_alert; /* For read and select. */ /* The quality of randomness we provide. @@ -105,7 +105,7 @@ gather_random( void (*add)(const void*, size_t, int), int requester, const char *argp_program_version = STANDARD_HURD_VERSION (random); /* This lock protects the GnuPG code. */ -static struct mutex global_lock; +static pthread_mutex_t global_lock; /* Trivfs hooks. */ int trivfs_fstype = FSTYPE_MISC; @@ -148,7 +148,7 @@ trivfs_S_io_read (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (amount > 0) { @@ -156,13 +156,13 @@ trivfs_S_io_read (struct trivfs_protid *cred, { if (cred->po->openmodes & O_NONBLOCK) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EWOULDBLOCK; } read_blocked = 1; - if (hurd_condition_wait (&wait, &global_lock)) + if (pthread_hurd_cond_wait_np (&wait, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } /* See term/users.c for possible race? */ @@ -179,7 +179,7 @@ trivfs_S_io_read (struct trivfs_protid *cred, /* Set atime, see term/users.c */ - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -207,7 +207,7 @@ trivfs_S_io_write (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_WRITE)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (i < datalen) { @@ -222,10 +222,11 @@ trivfs_S_io_write (struct trivfs_protid *cred, if (datalen > 0 && read_blocked) { read_blocked = 0; - condition_broadcast (&wait); + pthread_cond_broadcast (&wait); + pthread_cond_broadcast (&select_alert); } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -243,13 +244,13 @@ trivfs_S_io_readable (struct trivfs_protid *cred, else if (! (cred->po->openmodes & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); /* XXX: Before initialization, the amount depends on the amount we want to read. Assume some medium value. */ *amount = readable_pool (POOLSIZE/2, level); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -275,7 +276,7 @@ trivfs_S_io_select (struct trivfs_protid *cred, if (*type == 0) return 0; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (1) { @@ -285,17 +286,17 @@ trivfs_S_io_select (struct trivfs_protid *cred, if (avail != 0 || *type & SELECT_WRITE) { *type = (avail ? SELECT_READ : 0) | (*type & SELECT_WRITE); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } ports_interrupt_self_on_port_death (cred, reply); read_blocked = 1; - 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; } } @@ -473,7 +474,7 @@ trivfs_append_args (struct trivfs_control *fsys, error_t err = 0; char *opt; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); switch (level) { case 0: @@ -505,7 +506,7 @@ trivfs_append_args (struct trivfs_control *fsys, free (opt); } } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return err; } @@ -591,13 +592,12 @@ main (int argc, char **argv) /* Initialize the lock that will protect everything. We must do this before argp_parse, because parse_opt (above) will use the lock. */ - mutex_init (&global_lock); + pthread_mutex_init (&global_lock, NULL); /* The conditions are used to implement proper read/select behaviour. */ - condition_init (&wait); - condition_init (&select_alert); - condition_implies (&wait, &select_alert); + pthread_cond_init (&wait, NULL); + pthread_cond_init (&select_alert, NULL); /* We use the same argp for options available at startup as for options we'll accept in an fsys_set_options RPC. */ -- cgit v1.2.3