aboutsummaryrefslogtreecommitdiff
path: root/pflocal
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2012-09-04 00:33:09 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-27 22:58:15 +0100
commit1de0643c9218db536f5b2e294bbfa653c77438e4 (patch)
treef944e1b023cf0353ca559d22e1f7b701bac04c97 /pflocal
parent7648503cd894549874ff13f7ed94a4708cf50f0d (diff)
downloadhurd-1de0643c9218db536f5b2e294bbfa653c77438e4.tar.gz
hurd-1de0643c9218db536f5b2e294bbfa653c77438e4.tar.bz2
hurd-1de0643c9218db536f5b2e294bbfa653c77438e4.zip
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.
Diffstat (limited to 'pflocal')
-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
7 files changed, 125 insertions, 112 deletions
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");
+ }
}
}