summaryrefslogtreecommitdiff
path: root/libpipe
diff options
context:
space:
mode:
Diffstat (limited to 'libpipe')
-rw-r--r--libpipe/Makefile3
-rw-r--r--libpipe/pipe.c76
-rw-r--r--libpipe/pipe.h40
3 files changed, 60 insertions, 59 deletions
diff --git a/libpipe/Makefile b/libpipe/Makefile
index a7625d6c..35e27adf 100644
--- a/libpipe/Makefile
+++ b/libpipe/Makefile
@@ -25,7 +25,8 @@ installhdrs = pipe.h pq.h
SRCS = pq.c dgram.c pipe.c stream.c seqpack.c addr.c pq-funcs.c pipe-funcs.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS=threads ports
+HURDLIBS= ports
+LDLIBS += -lpthread
include ../Makeconf
diff --git a/libpipe/pipe.c b/libpipe/pipe.c
index 85aac0e6..dd306f60 100644
--- a/libpipe/pipe.c
+++ b/libpipe/pipe.c
@@ -35,7 +35,7 @@ timestamp (time_value_t *stamp)
}
/* Hold this lock before attempting to lock multiple pipes. */
-struct mutex pipe_multiple_lock = MUTEX_INITIALIZER;
+pthread_mutex_t pipe_multiple_lock = PTHREAD_MUTEX_INITIALIZER;
/* ---------------------------------------------------------------- */
@@ -60,12 +60,12 @@ pipe_create (struct pipe_class *class, struct pipe **pipe)
bzero (&new->read_time, sizeof (new->read_time));
bzero (&new->write_time, sizeof (new->write_time));
- condition_init (&new->pending_reads);
- condition_init (&new->pending_read_selects);
- condition_init (&new->pending_writes);
- condition_init (&new->pending_write_selects);
+ pthread_cond_init (&new->pending_reads, NULL);
+ pthread_cond_init (&new->pending_read_selects, NULL);
+ pthread_cond_init (&new->pending_writes, NULL);
+ pthread_cond_init (&new->pending_write_selects, NULL);
new->pending_selects = NULL;
- mutex_init (&new->lock);
+ pthread_mutex_init (&new->lock, NULL);
pq_create (&new->queue);
@@ -135,7 +135,7 @@ pipe_select_cond_broadcast (struct pipe *pipe)
do
{
- condition_broadcast (&cond->cond);
+ pthread_cond_broadcast (&cond->cond);
cond = cond->next;
}
while (cond != last);
@@ -169,12 +169,12 @@ void _pipe_no_readers (struct pipe *pipe)
if (pipe->writers)
/* Wake up writers for the bad news... */
{
- condition_broadcast (&pipe->pending_writes);
- condition_broadcast (&pipe->pending_write_selects);
+ pthread_cond_broadcast (&pipe->pending_writes);
+ pthread_cond_broadcast (&pipe->pending_write_selects);
pipe_select_cond_broadcast (pipe);
}
}
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
}
@@ -192,12 +192,12 @@ void _pipe_no_writers (struct pipe *pipe)
if (pipe->readers)
/* Wake up readers for the bad news... */
{
- condition_broadcast (&pipe->pending_reads);
- condition_broadcast (&pipe->pending_read_selects);
+ pthread_cond_broadcast (&pipe->pending_reads);
+ pthread_cond_broadcast (&pipe->pending_read_selects);
pipe_select_cond_broadcast (pipe);
}
}
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
}
@@ -217,15 +217,15 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
if (*select_type == SELECT_READ)
{
- mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
err = pipe_select_readable (rpipe, data_only);
- mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
}
else if (*select_type == SELECT_WRITE)
{
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
err = pipe_select_writable (wpipe);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
else
/* ugh */
@@ -233,18 +233,18 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
int rpipe_blocked, wpipe_blocked;
struct pipe_select_cond pending_select;
size_t wlimit = wpipe->write_limit;
- struct mutex *lock =
+ pthread_mutex_t *lock =
(wpipe == rpipe ? &rpipe->lock : &pipe_multiple_lock);
- condition_init (&pending_select.cond);
+ pthread_cond_init (&pending_select.cond, NULL);
- mutex_lock (lock);
+ pthread_mutex_lock (lock);
if (rpipe == wpipe)
pipe_add_select_cond (rpipe, &pending_select);
else
{
- mutex_lock (&rpipe->lock);
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
pipe_add_select_cond (rpipe, &pending_select);
pipe_add_select_cond (wpipe, &pending_select);
}
@@ -257,15 +257,15 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
{
if (rpipe != wpipe)
{
- mutex_unlock (&rpipe->lock);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
- if (hurd_condition_wait (&pending_select.cond, lock))
+ if (pthread_hurd_cond_wait_np (&pending_select.cond, lock))
err = EINTR;
if (rpipe != wpipe)
{
- mutex_lock (&rpipe->lock);
- mutex_lock (&wpipe->lock);
+ pthread_mutex_lock (&rpipe->lock);
+ pthread_mutex_lock (&wpipe->lock);
}
rpipe_blocked =
! ((rpipe->flags & PIPE_BROKEN)
@@ -289,10 +289,10 @@ pipe_pair_select (struct pipe *rpipe, struct pipe *wpipe,
{
pipe_remove_select_cond (rpipe, &pending_select);
pipe_remove_select_cond (wpipe, &pending_select);
- mutex_unlock (&rpipe->lock);
- mutex_unlock (&wpipe->lock);
+ pthread_mutex_unlock (&rpipe->lock);
+ pthread_mutex_unlock (&wpipe->lock);
}
- mutex_unlock (lock);
+ pthread_mutex_unlock (lock);
}
return err;
@@ -357,14 +357,14 @@ pipe_send (struct pipe *pipe, int noblock, void *source,
timestamp (&pipe->write_time);
/* And wakeup anyone that might be interested in it. */
- condition_broadcast (&pipe->pending_reads);
- mutex_unlock (&pipe->lock);
+ pthread_cond_broadcast (&pipe->pending_reads);
+ pthread_mutex_unlock (&pipe->lock);
- mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
+ pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
/* Only wakeup selects if there's still data available. */
if (pipe_is_readable (pipe, 0))
{
- condition_broadcast (&pipe->pending_read_selects);
+ pthread_cond_broadcast (&pipe->pending_read_selects);
pipe_select_cond_broadcast (pipe);
/* We leave PIPE locked here, assuming the caller will soon unlock
it and allow others access. */
@@ -459,14 +459,14 @@ pipe_recv (struct pipe *pipe, int noblock, unsigned *flags, void **source,
timestamp (&pipe->read_time);
/* And wakeup anyone that might be interested in it. */
- condition_broadcast (&pipe->pending_writes);
- mutex_unlock (&pipe->lock);
+ pthread_cond_broadcast (&pipe->pending_writes);
+ pthread_mutex_unlock (&pipe->lock);
- mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
+ pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
/* Only wakeup selects if there's still writing space available. */
if (pipe_readable (pipe, 1) < pipe->write_limit)
{
- condition_broadcast (&pipe->pending_write_selects);
+ pthread_cond_broadcast (&pipe->pending_write_selects);
pipe_select_cond_broadcast (pipe);
/* We leave PIPE locked here, assuming the caller will soon unlock
it and allow others access. */
diff --git a/libpipe/pipe.h b/libpipe/pipe.h
index a3590fc4..b8e70681 100644
--- a/libpipe/pipe.h
+++ b/libpipe/pipe.h
@@ -23,7 +23,7 @@
#define EWOULDBLOCK EAGAIN /* XXX */
-#include <cthreads.h> /* For conditions & mutexes */
+#include <pthread.h> /* For conditions & mutexes */
#include <features.h>
#ifdef PIPE_DEFINE_EI
@@ -66,7 +66,7 @@ struct pipe_select_cond
{
struct pipe_select_cond *next;
struct pipe_select_cond *prev;
- struct condition cond;
+ pthread_cond_t cond;
};
/* A unidirectional data pipe; it transfers data from READER to WRITER. */
@@ -89,11 +89,11 @@ struct pipe
time_value_t read_time;
time_value_t write_time;
- struct condition pending_reads;
- struct condition pending_read_selects;
+ pthread_cond_t pending_reads;
+ pthread_cond_t pending_read_selects;
- struct condition pending_writes;
- struct condition pending_write_selects;
+ pthread_cond_t pending_writes;
+ pthread_cond_t pending_write_selects;
struct pipe_select_cond *pending_selects;
@@ -104,7 +104,7 @@ struct pipe
/* Write requests of less than this much are always done atomically. */
size_t write_atomic;
- struct mutex lock;
+ pthread_mutex_t lock;
/* A queue of incoming packets, of type either PACKET_TYPE_DATA or
PACKET_TYPE_CONTROL. Each data packet represents one datagram for
@@ -177,7 +177,7 @@ pipe_wait_readable (struct pipe *pipe, int noblock, int data_only)
{
if (noblock)
return EWOULDBLOCK;
- if (hurd_condition_wait (&pipe->pending_reads, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_reads, &pipe->lock))
return EINTR;
}
return 0;
@@ -191,7 +191,7 @@ PIPE_EI error_t
pipe_select_readable (struct pipe *pipe, int data_only)
{
while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN))
- if (hurd_condition_wait (&pipe->pending_read_selects, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_read_selects, &pipe->lock))
return EINTR;
return 0;
}
@@ -209,7 +209,7 @@ pipe_wait_writable (struct pipe *pipe, int noblock)
{
if (noblock)
return EWOULDBLOCK;
- if (hurd_condition_wait (&pipe->pending_writes, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_writes, &pipe->lock))
return EINTR;
if (pipe->flags & PIPE_BROKEN)
return EPIPE;
@@ -225,7 +225,7 @@ pipe_select_writable (struct pipe *pipe)
{
size_t limit = pipe->write_limit;
while (! (pipe->flags & PIPE_BROKEN) && pipe_readable (pipe, 1) >= limit)
- if (hurd_condition_wait (&pipe->pending_writes, &pipe->lock))
+ if (pthread_hurd_cond_wait_np (&pipe->pending_writes, &pipe->lock))
return EINTR;
return 0;
}
@@ -276,7 +276,7 @@ extern void pipe_drain (struct pipe *pipe);
PIPE_EI void
pipe_acquire_reader (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe->readers++ == 0)
_pipe_first_reader (pipe);
}
@@ -285,7 +285,7 @@ pipe_acquire_reader (struct pipe *pipe)
PIPE_EI void
pipe_acquire_writer (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
if (pipe->writers++ == 0)
_pipe_first_writer (pipe);
}
@@ -298,7 +298,7 @@ pipe_release_reader (struct pipe *pipe)
if (--pipe->readers == 0)
_pipe_no_readers (pipe);
else
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Decrement PIPE's (which should be locked) writer count and unlock it. If
@@ -309,7 +309,7 @@ pipe_release_writer (struct pipe *pipe)
if (--pipe->writers == 0)
_pipe_no_writers (pipe);
else
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Increment PIPE's reader count. PIPE should be unlocked. */
@@ -317,7 +317,7 @@ PIPE_EI void
pipe_add_reader (struct pipe *pipe)
{
pipe_acquire_reader (pipe);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Increment PIPE's writer count. PIPE should be unlocked. */
@@ -325,7 +325,7 @@ PIPE_EI void
pipe_add_writer (struct pipe *pipe)
{
pipe_acquire_writer (pipe);
- mutex_unlock (&pipe->lock);
+ pthread_mutex_unlock (&pipe->lock);
}
/* Decrement PIPE's (which should be unlocked) reader count and unlock it. If
@@ -333,7 +333,7 @@ pipe_add_writer (struct pipe *pipe)
PIPE_EI void
pipe_remove_reader (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
pipe_release_reader (pipe);
}
@@ -342,7 +342,7 @@ pipe_remove_reader (struct pipe *pipe)
PIPE_EI void
pipe_remove_writer (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
+ pthread_mutex_lock (&pipe->lock);
pipe_release_writer (pipe);
}
@@ -410,7 +410,7 @@ error_t pipe_recv (struct pipe *pipe, int noblock, unsigned *flags,
pipe_recv (pipe, noblock, 0, source, data, data_len, amount, 0,0,0,0)
/* Hold this lock before attempting to lock multiple pipes. */
-extern struct mutex pipe_multiple_lock;
+extern pthread_mutex_t pipe_multiple_lock;
/* Return when either RPIPE is available for reading (if SELECT_READ is set
in *SELECT_TYPE), or WPIPE is available for writing (if select_write is