summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dde26_test/Makefile2
-rw-r--r--dde_e100/Makefile2
-rw-r--r--dde_e100/main.c5
-rw-r--r--dde_e1000/Makefile2
-rw-r--r--dde_e1000/main.c5
-rw-r--r--dde_ne2k_pci/Makefile2
-rw-r--r--dde_ne2k_pci/main.c5
-rw-r--r--dde_pcnet32/Makefile2
-rw-r--r--dde_pcnet32/main.c5
-rw-r--r--dde_pcnet32_test/Makefile2
-rw-r--r--dde_rtl8139/Makefile2
-rw-r--r--dde_rtl8139/main.c5
-rw-r--r--libbpf/Makefile2
-rw-r--r--libddekit/Makefile3
-rw-r--r--libddekit/condvar.c24
-rw-r--r--libddekit/lock.c21
-rw-r--r--libddekit/pgtab.c32
-rw-r--r--libddekit/thread.c160
-rw-r--r--libddekit/timer.c5
-rw-r--r--libhurd-slab/Makefile2
-rw-r--r--libhurd-slab/slab.c20
-rw-r--r--libhurd-slab/slab.h4
-rw-r--r--libmachdev/Makefile3
-rw-r--r--libmachdev/dev_hdr.h6
-rw-r--r--libmachdev/ds_routines.c5
-rw-r--r--libmachdev/if_hdr.h6
-rw-r--r--libmachdev/io_req.h10
-rw-r--r--libmachdev/machdev.h2
-rw-r--r--libmachdev/net.c4
-rw-r--r--libmachdev/queue.h14
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 <tf13@os.inf.tu-dresden.de>
*/
-#include <cthreads.h>
+#include <pthread.h>
+#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 <cthreads.h>
+#include <pthread.h>
#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 <error.h>
#include <errno.h>
#include <mach.h>
-#include <cthreads.h>
+#include <pthread.h>
#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 <stdio.h>
#include <string.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <time.h>
#include <error.h>
+#include <mach.h>
#include <hurd.h>
#include <sys/time.h>
#include <assert.h>
@@ -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 <error.h>
#include <maptime.h>
-#include <cthreads.h>
#include <stdio.h>
#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 <assert.h>
#include <string.h>
#include <unistd.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <stdint.h>
#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 <errno.h>
#include <stdbool.h>
-#include <cthreads.h>
+#include <pthread.h>
/* 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 <mach.h>
#include <hurd.h>
#include <hurd/ports.h>
-#include <cthreads.h>
+#include <pthread.h>
#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 <hurd.h>
#include <mach.h>
-#include <cthreads.h>
#include <ddekit/thread.h>
@@ -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 <queue.h>
-#include <cthreads.h>
+#include <pthread.h>
#include <hurd/bpf_impl.h>
#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 <mach.h>
-#include <cthreads.h>
+#include <pthread.h>
#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 <cthreads.h>
+#include <pthread.h>
/*
* 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.