aboutsummaryrefslogtreecommitdiff
path: root/pflocal
diff options
context:
space:
mode:
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");
+ }
}
}