summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-26 00:03:30 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-26 00:03:30 +0000
commiteaa76a8dee2236d7f3f493ada113576d0e47f453 (patch)
treec7be406c4f644834b7be5a1d8de338f04a979818
parent0fd99adfaf0255df26a540817e9eb09a456aeb45 (diff)
parent393b762d63721cfb68e7efe54578370c18c7d0d3 (diff)
Merge branch 'upstream-merged'
-rwxr-xr-xconfigure2
-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
-rw-r--r--procfs/Makefile2
-rw-r--r--procfs/netfs.c8
-rw-r--r--procfs/process.c15
-rw-r--r--random/Makefile3
-rw-r--r--random/random.c50
-rw-r--r--ufs/Makefile3
-rw-r--r--ufs/alloc.c38
-rw-r--r--ufs/dir.c8
-rw-r--r--ufs/hyper.c10
-rw-r--r--ufs/inode.c44
-rw-r--r--ufs/main.c10
-rw-r--r--ufs/pager.c105
-rw-r--r--ufs/pokeloc.c14
-rw-r--r--ufs/sizes.c47
-rw-r--r--ufs/ufs.h13
46 files changed, 392 insertions, 342 deletions
diff --git a/configure b/configure
index 79671e64..35850108 100755
--- a/configure
+++ b/configure
@@ -5174,7 +5174,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $XKB_BASE" >&5
$as_echo "$XKB_BASE" >&6; }
else
- XKB_BASE="$datadir/X11/xkb"
+ XKB_BASE="$datadir/share/X11/xkb"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: (default) $XKB_BASE" >&5
$as_echo "(default) $XKB_BASE" >&6; }
fi
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 eaed375f..1f3c4c03 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 -lz -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path)
+LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lz -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 fecd94d4..e0a1524b 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 -lz -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path)
+LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lz -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 5bb27da9..932d5ad0 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 -lz -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path)
+LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lz -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 0268d80b..e228a619 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 -lz -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path)
+LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lz -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 0a9b1b71..91a7df93 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 -lz -lthreads -lshouldbeinlibc -lports $(libslab_path) $(libbpf_path)
+LIBS += $(libmachdev_path) -ldde_linux26.o -ldde_linux26_net $(libddekit_path) -lfshelp -ltrivfs -lpciaccess -lz -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 4f6e8aaa..59f75095 100644
--- a/libddekit/Makefile
+++ b/libddekit/Makefile
@@ -40,7 +40,8 @@ LCLHDRS = $(installhdrs) \
MIGSTUBS = experimentalUser.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.
diff --git a/procfs/Makefile b/procfs/Makefile
index a397522f..c69cb206 100644
--- a/procfs/Makefile
+++ b/procfs/Makefile
@@ -1,7 +1,7 @@
TARGET = procfs
OBJS = procfs.o netfs.o procfs_dir.o \
process.o proclist.o rootdir.o dircat.o main.o
-LIBS = -lnetfs -lps
+LIBS = -lnetfs -lps -lfshelp
CC = gcc
CFLAGS = -Wall -g
diff --git a/procfs/netfs.c b/procfs/netfs.c
index 24a6603f..a4d9f9c2 100644
--- a/procfs/netfs.c
+++ b/procfs/netfs.c
@@ -208,10 +208,10 @@ error_t netfs_attempt_lookup (struct iouser *user, struct node *dir,
error_t err;
err = procfs_lookup (dir, name, np);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
if (! err)
- mutex_lock (&(*np)->lock);
+ pthread_mutex_lock (&(*np)->lock);
return err;
}
@@ -220,12 +220,12 @@ error_t netfs_attempt_lookup (struct iouser *user, struct node *dir,
free all its associated storage. */
void netfs_node_norefs (struct node *np)
{
- spin_unlock (&netfs_node_refcnt_lock);
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
procfs_cleanup (np);
free (np);
- spin_lock (&netfs_node_refcnt_lock);
+ pthread_spin_lock (&netfs_node_refcnt_lock);
}
diff --git a/procfs/process.c b/procfs/process.c
index 17a38ea8..68eb50a0 100644
--- a/procfs/process.c
+++ b/procfs/process.c
@@ -87,6 +87,11 @@ static const char *args_filename (const char *name)
return sp != NULL && *(sp + 1) != '\0' ? sp + 1 : name;
}
+static int args_filename_length (const char *name)
+{
+ return strchrnul (name, ' ') - name;
+}
+
/* Actual content generators */
static ssize_t
@@ -109,11 +114,12 @@ process_file_gc_stat (struct proc_stat *ps, char **contents)
struct procinfo *pi = proc_stat_proc_info (ps);
task_basic_info_t tbi = proc_stat_task_basic_info (ps);
thread_basic_info_t thbi = proc_stat_thread_basic_info (ps);
+ const char *fn = args_filename (proc_stat_args (ps));
/* See proc(5) for more information about the contents of each field for the
Linux procfs. */
return asprintf (contents,
- "%d (%s) %c " /* pid, command, state */
+ "%d (%.*s) %c " /* pid, command, state */
"%d %d %d " /* ppid, pgid, session */
"%d %d " /* controling tty stuff */
"%u " /* flags, as defined by <linux/sched.h> */
@@ -132,7 +138,7 @@ process_file_gc_stat (struct proc_stat *ps, char **contents)
"%u %u " /* RT priority and policy */
"%llu " /* aggregated block I/O delay */
"\n",
- proc_stat_pid (ps), args_filename (proc_stat_args (ps)), state_char (ps),
+ proc_stat_pid (ps), args_filename_length (fn), fn, state_char (ps),
pi->ppid, pi->pgrp, pi->session,
0, 0, /* no such thing as a major:minor for ctty */
0, /* no such thing as CLONE_* flags on Hurd */
@@ -171,9 +177,10 @@ static ssize_t
process_file_gc_status (struct proc_stat *ps, char **contents)
{
task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+ const char *fn = args_filename (proc_stat_args (ps));
return asprintf (contents,
- "Name:\t%s\n"
+ "Name:\t%.*s\n"
"State:\t%s\n"
"Tgid:\t%u\n"
"Pid:\t%u\n"
@@ -184,7 +191,7 @@ process_file_gc_status (struct proc_stat *ps, char **contents)
"VmRSS:\t%8u kB\n"
"VmHWM:\t%8u kB\n" /* ie. resident peak */
"Threads:\t%u\n",
- args_filename (proc_stat_args (ps)),
+ args_filename_length (fn), fn,
state_string (ps),
proc_stat_pid (ps), /* XXX will need more work for threads */
proc_stat_pid (ps),
diff --git a/random/Makefile b/random/Makefile
index 9b3a95dd..0949b637 100644
--- a/random/Makefile
+++ b/random/Makefile
@@ -24,6 +24,7 @@ target = random
SRCS = random.c gnupg-random.c gnupg-rmd160.c
OBJS = $(SRCS:.c=.o) startup_notifyServer.o
LCLHDRS = gnupg-random.h gnupg-rmd.h gnupg-bithelp.h random.h
-HURDLIBS = trivfs threads ports fshelp ihash shouldbeinlibc
+HURDLIBS = trivfs ports fshelp ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/random/random.c b/random/random.c
index 0ae31f5f..5ef814f4 100644
--- a/random/random.c
+++ b/random/random.c
@@ -27,8 +27,8 @@
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
-#include <cthreads.h>
-#include <rwlock.h>
+#include <pthread.h>
+#include <assert.h>
#include <version.h>
@@ -39,8 +39,8 @@
struct trivfs_control *fsys;
int read_blocked; /* For read and select. */
-struct condition wait; /* For read and select. */
-struct condition select_alert; /* For read and select. */
+pthread_cond_t wait; /* For read and select. */
+pthread_cond_t select_alert; /* For read and select. */
/* The quality of randomness we provide.
@@ -105,7 +105,7 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
const char *argp_program_version = STANDARD_HURD_VERSION (random);
/* This lock protects the GnuPG code. */
-static struct mutex global_lock;
+static pthread_mutex_t global_lock;
/* Trivfs hooks. */
int trivfs_fstype = FSTYPE_MISC;
@@ -148,7 +148,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
else if (! (cred->po->openmodes & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
if (amount > 0)
{
@@ -156,13 +156,13 @@ trivfs_S_io_read (struct trivfs_protid *cred,
{
if (cred->po->openmodes & O_NONBLOCK)
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EWOULDBLOCK;
}
read_blocked = 1;
- if (hurd_condition_wait (&wait, &global_lock))
+ if (pthread_hurd_cond_wait_np (&wait, &global_lock))
{
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
/* See term/users.c for possible race? */
@@ -179,7 +179,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
/* Set atime, see term/users.c */
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -207,7 +207,7 @@ trivfs_S_io_write (struct trivfs_protid *cred,
else if (! (cred->po->openmodes & O_WRITE))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (i < datalen)
{
@@ -222,10 +222,11 @@ trivfs_S_io_write (struct trivfs_protid *cred,
if (datalen > 0 && read_blocked)
{
read_blocked = 0;
- condition_broadcast (&wait);
+ pthread_cond_broadcast (&wait);
+ pthread_cond_broadcast (&select_alert);
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -243,13 +244,13 @@ trivfs_S_io_readable (struct trivfs_protid *cred,
else if (! (cred->po->openmodes & O_READ))
return EBADF;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
/* XXX: Before initialization, the amount depends on the amount we
want to read. Assume some medium value. */
*amount = readable_pool (POOLSIZE/2, level);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
@@ -275,7 +276,7 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if (*type == 0)
return 0;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
while (1)
{
@@ -285,17 +286,17 @@ trivfs_S_io_select (struct trivfs_protid *cred,
if (avail != 0 || *type & SELECT_WRITE)
{
*type = (avail ? SELECT_READ : 0) | (*type & SELECT_WRITE);
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return 0;
}
ports_interrupt_self_on_port_death (cred, reply);
read_blocked = 1;
- if (hurd_condition_wait (&select_alert, &global_lock))
+ if (pthread_hurd_cond_wait_np (&select_alert, &global_lock))
{
*type = 0;
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return EINTR;
}
}
@@ -473,7 +474,7 @@ trivfs_append_args (struct trivfs_control *fsys,
error_t err = 0;
char *opt;
- mutex_lock (&global_lock);
+ pthread_mutex_lock (&global_lock);
switch (level)
{
case 0:
@@ -505,7 +506,7 @@ trivfs_append_args (struct trivfs_control *fsys,
free (opt);
}
}
- mutex_unlock (&global_lock);
+ pthread_mutex_unlock (&global_lock);
return err;
}
@@ -591,13 +592,12 @@ main (int argc, char **argv)
/* Initialize the lock that will protect everything.
We must do this before argp_parse, because parse_opt (above) will
use the lock. */
- mutex_init (&global_lock);
+ pthread_mutex_init (&global_lock, NULL);
/* The conditions are used to implement proper read/select
behaviour. */
- condition_init (&wait);
- condition_init (&select_alert);
- condition_implies (&wait, &select_alert);
+ pthread_cond_init (&wait, NULL);
+ pthread_cond_init (&select_alert, NULL);
/* We use the same argp for options available at startup
as for options we'll accept in an fsys_set_options RPC. */
diff --git a/ufs/Makefile b/ufs/Makefile
index a1cfc4c9..b66a6259 100644
--- a/ufs/Makefile
+++ b/ufs/Makefile
@@ -24,7 +24,8 @@ SRCS = alloc.c consts.c dir.c hyper.c inode.c main.c pager.c \
sizes.c subr.c tables.c bmap.c pokeloc.c xinl.c
OBJS = $(SRCS:.c=.o)
-HURDLIBS = diskfs iohelp fshelp store pager threads ports ihash shouldbeinlibc
+HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
+OTHERLIBS = -lpthread
include ../Makeconf
diff --git a/ufs/alloc.c b/ufs/alloc.c
index d8f92255..9056a8b7 100644
--- a/ufs/alloc.c
+++ b/ufs/alloc.c
@@ -64,7 +64,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
extern u_long nextgennumber;
-spin_lock_t alloclock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t alloclock = PTHREAD_SPINLOCK_INITIALIZER;
/* Forward declarations */
static u_long ffs_hashalloc (struct node *, int, long, int,
@@ -244,7 +244,7 @@ ffs_alloc(register struct node *np,
}
assert (cred);
#endif /* DIAGNOSTIC */
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
goto nospace;
if (cred && !idvec_contains (cred->user->uids, 0)
@@ -263,7 +263,7 @@ ffs_alloc(register struct node *np,
bno = (daddr_t)ffs_hashalloc(np, cg, (long)bpref, size,
(u_long (*)())ffs_alloccg);
if (bno > 0) {
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(size);
np->dn_set_ctime = 1;
np->dn_set_mtime = 1;
@@ -278,7 +278,7 @@ ffs_alloc(register struct node *np,
(void) chkdq(ip, (long)-btodb(size), cred, FORCE);
#endif
nospace:
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
printf ("file system full");
/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
@@ -321,7 +321,7 @@ ffs_realloccg(register struct node *np,
panic("ffs_realloccg: missing credential\n");
#endif /* DIAGNOSTIC */
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (!idvec_contains (cred->user->uids, 0)
&& freespace(fs, fs->fs_minfree) <= 0)
@@ -356,7 +356,7 @@ ffs_realloccg(register struct node *np,
bno = ffs_fragextend(np, cg, (long)bprev, osize, nsize);
if (bno) {
assert (bno == bprev);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(nsize - osize);
np->dn_set_ctime = 1;
np->dn_set_mtime = 1;
@@ -430,7 +430,7 @@ ffs_realloccg(register struct node *np,
if (nsize < request)
ffs_blkfree(np, bno + numfrags(fs, nsize),
(long)(request - nsize));
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
np->dn_stat.st_blocks += btodb(nsize - osize);
np->dn_set_mtime = 1;
np->dn_set_ctime = 1;
@@ -457,7 +457,7 @@ nospace:
/*
* no space available
*/
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
printf ("file system full");
/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
@@ -660,11 +660,11 @@ diskfs_alloc_node (struct node *dir,
fs = sblock;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (fs->fs_cstotal.cs_nifree == 0)
{
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
goto noinodes;
}
@@ -678,7 +678,7 @@ diskfs_alloc_node (struct node *dir,
cg = ino_to_cg(fs, ipref);
ino = (ino_t)ffs_hashalloc(dir, cg, (long)ipref,
mode, ffs_nodealloccg);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
if (ino == 0)
goto noinodes;
error = diskfs_cached_lookup (ino, &np);
@@ -694,12 +694,12 @@ diskfs_alloc_node (struct node *dir,
/*
* Set up a new generation number for this inode.
*/
- spin_lock (&gennumberlock);
+ pthread_spin_lock (&gennumberlock);
sex = diskfs_mtime->seconds;
if (++nextgennumber < (u_long)sex)
nextgennumber = sex;
np->dn_stat.st_gen = nextgennumber;
- spin_unlock (&gennumberlock);
+ pthread_spin_unlock (&gennumberlock);
*npp = np;
alloc_sync (np);
@@ -773,11 +773,11 @@ ffs_blkpref(struct node *np,
daddr_t nextblk;
fs = sblock;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
if (lbn < NDADDR) {
cg = ino_to_cg(fs, np->dn->number);
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
/*
@@ -796,19 +796,19 @@ ffs_blkpref(struct node *np,
for (cg = startcg; cg < fs->fs_ncg; cg++)
if (csum[cg].cs_nbfree >= avgbfree) {
fs->fs_cgrotor = cg;
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
for (cg = 0; cg <= startcg; cg++)
if (csum[cg].cs_nbfree >= avgbfree) {
fs->fs_cgrotor = cg;
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return (fs->fs_fpg * cg + fs->fs_frag);
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return 0;
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
/*
* One or more previous blocks have been laid out. If less
* than fs_maxcontig previous blocks are contiguous, the
diff --git a/ufs/dir.c b/ufs/dir.c
index 3c5f152a..c3bd424e 100644
--- a/ufs/dir.c
+++ b/ufs/dir.c
@@ -244,9 +244,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Drop what we *thought* was .. (but isn't any more) and
try *again*. */
diskfs_nput (np);
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
@@ -259,9 +259,9 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
/* Lock them in the proper order, and then
repeat the directory scan to see if this is still
right. */
- mutex_unlock (&dp->lock);
+ pthread_mutex_unlock (&dp->lock);
err = diskfs_cached_lookup (inum, &np);
- mutex_lock (&dp->lock);
+ pthread_mutex_lock (&dp->lock);
if (err)
goto out;
retry_dotdot = inum;
diff --git a/ufs/hyper.c b/ufs/hyper.c
index ece327a2..95013895 100644
--- a/ufs/hyper.c
+++ b/ufs/hyper.c
@@ -280,7 +280,7 @@ diskfs_set_hypermetadata (int wait, int clean)
{
error_t err;
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (csum_dirty)
{
@@ -316,7 +316,7 @@ diskfs_set_hypermetadata (int wait, int clean)
if (err)
{
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
return err;
}
@@ -337,7 +337,7 @@ diskfs_set_hypermetadata (int wait, int clean)
wait = 1; /* must be synchronous */
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
/* Update the superblock if necessary (clean bit was just set). */
copy_sblock ();
@@ -355,7 +355,7 @@ copy_sblock ()
err = diskfs_catch_exception ();
assert_perror (err);
- spin_lock (&alloclock);
+ pthread_spin_lock (&alloclock);
if (sblock_dirty)
{
@@ -386,7 +386,7 @@ copy_sblock ()
sblock_dirty = 0;
}
- spin_unlock (&alloclock);
+ pthread_spin_unlock (&alloclock);
diskfs_end_catch_exception ();
}
diff --git a/ufs/inode.c b/ufs/inode.c
index 77a45edb..066eb1e5 100644
--- a/ufs/inode.c
+++ b/ufs/inode.c
@@ -35,7 +35,7 @@
static struct node *nodehash[INOHSZ];
static error_t read_disknode (struct node *np);
-spin_lock_t gennumberlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t gennumberlock = PTHREAD_SPINLOCK_INITIALIZER;
/* Initialize the inode hash table. */
void
@@ -55,15 +55,15 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
struct node *np;
error_t err;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->dn->number != inum)
continue;
np->references++;
- spin_unlock (&diskfs_node_refcnt_lock);
- mutex_lock (&np->lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_mutex_lock (&np->lock);
*npp = np;
return 0;
}
@@ -74,30 +74,32 @@ diskfs_cached_lookup (ino_t inum, struct node **npp)
dn->dirents = 0;
dn->dir_idx = 0;
- rwlock_init (&dn->allocptrlock);
+ pthread_rwlock_init (&dn->allocptrlock, NULL);
+ pthread_mutex_init (&dn->waitlock, NULL);
+ pthread_cond_init (&dn->waitcond, NULL);
dn->dirty = 0;
dn->fileinfo = 0;
np = diskfs_make_node (dn);
np->cache_id = inum;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
dn->hnext = nodehash[INOHASH(inum)];
if (dn->hnext)
dn->hnext->dn->hprevp = &dn->hnext;
dn->hprevp = &nodehash[INOHASH(inum)];
nodehash[INOHASH(inum)] = np;
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = read_disknode (np);
if (!diskfs_check_readonly () && !np->dn_stat.st_gen)
{
- spin_lock (&gennumberlock);
+ pthread_spin_lock (&gennumberlock);
if (++nextgennumber < diskfs_mtime->seconds)
nextgennumber = diskfs_mtime->seconds;
np->dn_stat.st_gen = nextgennumber;
- spin_unlock (&gennumberlock);
+ pthread_spin_unlock (&gennumberlock);
np->dn_set_ctime = 1;
}
@@ -117,14 +119,14 @@ ifind (ino_t inum)
{
struct node *np;
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
{
if (np->dn->number != inum)
continue;
assert (np->references);
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
return np;
}
assert (0);
@@ -168,7 +170,7 @@ diskfs_lost_hardrefs (struct node *np)
if (np->dn->fileinfo)
{
- spin_lock (&_libports_portrefcntlock);
+ pthread_spin_lock (&_libports_portrefcntlock);
pi = (struct port_info *) np->dn->fileinfo->p;
if (pi->refcnt == 1)
{
@@ -178,7 +180,7 @@ diskfs_lost_hardrefs (struct node *np)
can't happen as long as we hold NP locked. So
we can safely unlock _libports_portrefcntlock for
the following call. */
- spin_unlock (&_libports_portrefcntlock);
+ pthread_spin_unlock (&_libports_portrefcntlock);
/* Right now the node is locked with no hard refs;
this is an anomalous situation. Before messing with
@@ -197,7 +199,7 @@ diskfs_lost_hardrefs (struct node *np)
diskfs_nput (np);
}
else
- spin_unlock (&_libports_portrefcntlock);
+ pthread_spin_unlock (&_libports_portrefcntlock);
}
#endif
}
@@ -440,7 +442,7 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
/* Acquire a reference on all the nodes in the hash table
and enter them into a list on the stack. */
- spin_lock (&diskfs_node_refcnt_lock);
+ pthread_spin_lock (&diskfs_node_refcnt_lock);
for (n = 0; n < INOHSZ; n++)
for (np = nodehash[n]; np; np = np->dn->hnext)
{
@@ -450,16 +452,16 @@ diskfs_node_iterate (error_t (*fun)(struct node *))
i->np = np;
list = i;
}
- spin_unlock (&diskfs_node_refcnt_lock);
+ pthread_spin_unlock (&diskfs_node_refcnt_lock);
err = 0;
for (i = list; i; i = i->next)
{
if (!err)
{
- mutex_lock (&i->np->lock);
+ pthread_mutex_lock (&i->np->lock);
err = (*fun)(i->np);
- mutex_unlock (&i->np->lock);
+ pthread_mutex_unlock (&i->np->lock);
}
diskfs_nrele (i->np);
}
@@ -646,14 +648,14 @@ diskfs_S_file_get_storage_info (struct protid *cred,
return EOPNOTSUPP;
np = cred->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
/* See if this file fits in the direct block pointers. If not, punt
for now. (Reading indir blocks is a pain, and I'm postponing
pain.) XXX */
if (np->allocsize > NDADDR * sblock->fs_bsize)
{
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
return EINVAL;
}
@@ -685,7 +687,7 @@ diskfs_S_file_get_storage_info (struct protid *cred,
}
diskfs_end_catch_exception ();
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (! err)
err = store_clone (store, &file_store);
diff --git a/ufs/main.c b/ufs/main.c
index 242107f4..9fc21f81 100644
--- a/ufs/main.c
+++ b/ufs/main.c
@@ -46,19 +46,19 @@ warp_root (void)
error_t err;
err = diskfs_cached_lookup (2, &diskfs_root_node);
assert (!err);
- mutex_unlock (&diskfs_root_node->lock);
+ pthread_mutex_unlock (&diskfs_root_node->lock);
}
/* XXX */
-struct mutex printf_lock = MUTEX_INITIALIZER;
+pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER;
int printf (const char *fmt, ...)
{
va_list arg;
int done;
va_start (arg, fmt);
- mutex_lock (&printf_lock);
+ pthread_mutex_lock (&printf_lock);
done = vprintf (fmt, arg);
- mutex_unlock (&printf_lock);
+ pthread_mutex_unlock (&printf_lock);
va_end (arg);
return done;
}
@@ -195,7 +195,7 @@ main (int argc, char **argv)
/* SET HOST NAME */
/* And this thread is done with its work. */
- cthread_exit (0);
+ pthread_exit (NULL);
return 0;
}
diff --git a/ufs/pager.c b/ufs/pager.c
index 3038932d..1e3d140c 100644
--- a/ufs/pager.c
+++ b/ufs/pager.c
@@ -21,9 +21,9 @@
#include <unistd.h>
#include <hurd/store.h>
-spin_lock_t node2pagelock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t node2pagelock = PTHREAD_SPINLOCK_INITIALIZER;
-spin_lock_t unlocked_pagein_lock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t unlocked_pagein_lock = PTHREAD_SPINLOCK_INITIALIZER;
#ifdef DONT_CACHE_MEMORY_OBJECTS
#define MAY_CACHE 0
@@ -47,11 +47,11 @@ find_address (struct user_pager_info *upi,
vm_address_t offset,
daddr_t *addr,
int *disksize,
- struct rwlock **nplock,
+ pthread_rwlock_t **nplock,
int isread)
{
error_t err;
- struct rwlock *lock;
+ pthread_rwlock_t *lock;
assert (upi->type == DISK || upi->type == FILE_DATA);
@@ -81,37 +81,49 @@ find_address (struct user_pager_info *upi,
I think this is sufficiently rare to put it off for the time
being.) */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
if (offset >= upi->allow_unlocked_pagein
&& (offset + vm_page_size
<= upi->allow_unlocked_pagein + upi->unlocked_pagein_length))
{
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
*nplock = 0;
goto have_lock;
}
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Block on the rwlock if necessary; but when we wake up,
don't acquire it; check again from the top.
This is mutated inline from rwlock.h. */
lock = &np->dn->allocptrlock;
- mutex_lock (&lock->master);
- if (lock->readers == -1 || lock->writers_waiting)
+ /*
+ TD - Why do we lock first?
+ To prevent this nigh-impossible scenario:
+ 1) trylock - writer has lock
+ 2) switch back to writer before we lock waitlock
+ 3) writer finishes: releases lock and broadcasts
+ 4) we wait for a condition that will never get broadcast
+ With this, either we get the lock, or we get the signal.
+ */
+ pthread_mutex_lock (&np->dn->waitlock);
+ if (pthread_rwlock_tryrdlock (lock))
{
- lock->readers_waiting++;
- condition_wait (&lock->wakeup, &lock->master);
- lock->readers_waiting--;
- mutex_unlock (&lock->master);
+ /*
+ TD - we now don't block on the rwlock. Instead, we wait on a
+ condition that will be signalled when the lock is unlocked,
+ or when it is safe not to lock the page. We don't spin on an
+ invariant, as spurius wakeups can do no harm.
+ */
+ pthread_cond_wait (&np->dn->waitcond, &np->dn->waitlock);
+ pthread_mutex_unlock (&np->dn->waitlock);
goto try_again;
}
- lock->readers++;
- mutex_unlock (&lock->master);
+ pthread_mutex_unlock (&np->dn->waitlock);
*nplock = lock;
}
else
{
- rwlock_reader_lock (&np->dn->allocptrlock);
+ pthread_rwlock_rdlock (&np->dn->allocptrlock);
*nplock = &np->dn->allocptrlock;
}
@@ -120,7 +132,7 @@ find_address (struct user_pager_info *upi,
if (offset >= np->allocsize)
{
if (*nplock)
- rwlock_reader_unlock (*nplock);
+ pthread_rwlock_unlock (*nplock);
if (isread)
return EIO;
else
@@ -138,7 +150,7 @@ find_address (struct user_pager_info *upi,
err = fetch_indir_spec (np, lblkno (sblock, offset), indirs);
if (err && *nplock)
- rwlock_reader_unlock (*nplock);
+ pthread_rwlock_unlock (*nplock);
else
{
if (indirs[0].bno)
@@ -162,7 +174,7 @@ pager_read_page (struct user_pager_info *pager,
int *writelock)
{
error_t err;
- struct rwlock *nplock;
+ pthread_rwlock_t *nplock;
daddr_t addr;
int disksize;
@@ -193,7 +205,7 @@ pager_read_page (struct user_pager_info *pager,
}
if (nplock)
- rwlock_reader_unlock (nplock);
+ pthread_rwlock_unlock (nplock);
return err;
}
@@ -207,7 +219,7 @@ pager_write_page (struct user_pager_info *pager,
{
daddr_t addr;
int disksize;
- struct rwlock *nplock;
+ pthread_rwlock_t *nplock;
error_t err;
err = find_address (pager, page, &addr, &disksize, &nplock, 0);
@@ -226,7 +238,7 @@ pager_write_page (struct user_pager_info *pager,
err = 0;
if (nplock)
- rwlock_reader_unlock (nplock);
+ pthread_rwlock_unlock (nplock);
return err;
}
@@ -268,7 +280,7 @@ pager_unlock_page (struct user_pager_info *pager,
dn = np->dn;
di = dino (dn->number);
- rwlock_writer_lock (&dn->allocptrlock);
+ pthread_rwlock_wrlock (&dn->allocptrlock);
/* If this is the last block, we don't let it get unlocked. */
if (address + __vm_page_size
@@ -276,21 +288,31 @@ pager_unlock_page (struct user_pager_info *pager,
{
printf ("attempt to unlock at last block denied\n");
fflush (stdout);
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ /* Wake up any remaining sleeping readers. Wow, so much work.... */
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
err = fetch_indir_spec (np, lblkno (sblock, address), indirs);
if (err)
{
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
err = diskfs_catch_exception ();
if (err)
{
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return EIO;
}
@@ -421,7 +443,10 @@ pager_unlock_page (struct user_pager_info *pager,
out:
diskfs_end_catch_exception ();
- rwlock_writer_unlock (&dn->allocptrlock);
+ pthread_rwlock_unlock (&dn->allocptrlock);
+ pthread_mutex_lock (&dn->waitlock);
+ pthread_cond_broadcast (&dn->waitcond);
+ pthread_mutex_unlock (&dn->waitlock);
return err;
}
@@ -452,10 +477,10 @@ pager_clear_user_data (struct user_pager_info *upi)
/* XXX Do the right thing for the disk pager here too. */
if (upi->type == FILE_DATA)
{
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
if (upi->np->dn->fileinfo == upi)
upi->np->dn->fileinfo = 0;
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
diskfs_nrele_light (upi->np);
}
free (upi);
@@ -491,11 +516,11 @@ diskfs_file_update (struct node *np,
struct dirty_indir *d, *tmp;
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -522,11 +547,11 @@ flush_node_pager (struct node *node)
struct disknode *dn = node->dn;
struct dirty_indir *dirty = dn->dirty;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -558,7 +583,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
&& (!direct_symlink_extension
|| np->dn_stat.st_size >= sblock->fs_maxsymlinklen)));
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
do
if (!np->dn->fileinfo)
{
@@ -575,7 +600,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
{
diskfs_nrele_light (np);
free (upi);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
return MACH_PORT_NULL;
}
np->dn->fileinfo = upi;
@@ -596,7 +621,7 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
}
while (right == MACH_PORT_NULL);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
mach_port_insert_right (mach_task_self (), right, right,
MACH_MSG_TYPE_MAKE_SEND);
@@ -611,11 +636,11 @@ drop_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (MAY_CACHE && upi)
pager_change_attributes (upi->p, 0, MEMORY_OBJECT_COPY_DELAY, 0);
@@ -630,11 +655,11 @@ allow_pager_softrefs (struct node *np)
{
struct user_pager_info *upi;
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (MAY_CACHE && upi)
pager_change_attributes (upi->p, 1, MEMORY_OBJECT_COPY_DELAY, 0);
diff --git a/ufs/pokeloc.c b/ufs/pokeloc.c
index 267aa106..e1d5ffcb 100644
--- a/ufs/pokeloc.c
+++ b/ufs/pokeloc.c
@@ -28,7 +28,7 @@ struct pokeloc
};
struct pokeloc *pokelist;
-spin_lock_t pokelistlock = SPIN_LOCK_INITIALIZER;
+pthread_spinlock_t pokelistlock = PTHREAD_SPINLOCK_INITIALIZER;
/* Remember that data here on the disk has been modified. */
void
@@ -41,10 +41,10 @@ record_poke (void *loc, vm_size_t length)
pl->offset = trunc_page (offset);
pl->length = round_page (offset + length) - pl->offset;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
pl->next = pokelist;
pokelist = pl;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
}
/* Get rid of any outstanding pokes. */
@@ -53,10 +53,10 @@ flush_pokes ()
{
struct pokeloc *pl;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
pl = pokelist;
pokelist = 0;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
while (pl)
{
@@ -72,7 +72,7 @@ sync_disk (int wait)
{
struct pokeloc *pl, *tmp;
- spin_lock (&pokelistlock);
+ pthread_spin_lock (&pokelistlock);
for (pl = pokelist; pl; pl = tmp)
{
pager_sync_some (diskfs_disk_pager, pl->offset, pl->length, wait);
@@ -80,6 +80,6 @@ sync_disk (int wait)
free (pl);
}
pokelist = 0;
- spin_unlock (&pokelistlock);
+ pthread_spin_unlock (&pokelistlock);
}
diff --git a/ufs/sizes.c b/ufs/sizes.c
index 58cbfc98..e3d51b7d 100644
--- a/ufs/sizes.c
+++ b/ufs/sizes.c
@@ -91,11 +91,11 @@ diskfs_truncate (struct node *np,
immediately. (We are implicitly changing the data to zeros
and doing it without the kernel's immediate knowledge;
accordingl we must help out the kernel thusly.) */
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
@@ -115,7 +115,7 @@ diskfs_truncate (struct node *np,
ports_port_deref (upi->p);
}
- rwlock_writer_lock (&np->dn->allocptrlock);
+ pthread_rwlock_wrlock (&np->dn->allocptrlock);
/* Update the size on disk; fsck will finish freeing blocks if necessary
should we crash. */
@@ -250,7 +250,13 @@ diskfs_truncate (struct node *np,
np->dn_set_ctime = 1;
diskfs_node_update (np, 1);
- rwlock_writer_unlock (&np->dn->allocptrlock);
+ pthread_rwlock_unlock (&np->dn->allocptrlock);
+ /* Wake up any remaining sleeping readers.
+ This sequence of three calls is now necessary whenever we acquire a write
+ lock on allocptrlock. If we do not, we may leak some readers. */
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
/* At this point the last block (as defined by np->allocsize)
might not be allocated. We need to allocate it to maintain
@@ -275,11 +281,11 @@ diskfs_truncate (struct node *np,
diskfs_end_catch_exception ();
/* Now we can permit delayed copies again. */
- spin_lock (&node2pagelock);
+ pthread_spin_lock (&node2pagelock);
upi = np->dn->fileinfo;
if (upi)
ports_port_ref (upi->p);
- spin_unlock (&node2pagelock);
+ pthread_spin_unlock (&node2pagelock);
if (upi)
{
pager_change_attributes (upi->p, MAY_CACHE,
@@ -415,15 +421,23 @@ block_extended (struct node *np,
assert_perror (err);
/* Allow these pageins to occur even though we're holding the lock */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
np->dn->fileinfo->allow_unlocked_pagein = lbn * sblock->fs_bsize;
np->dn->fileinfo->unlocked_pagein_length = round_page (old_size);
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Make sure all waiting pageins see this change. */
- mutex_lock (&np->dn->allocptrlock.master);
- condition_broadcast (&np->dn->allocptrlock.wakeup);
- mutex_unlock (&np->dn->allocptrlock.master);
+ /* BDD - Is this sane? */
+ /* TD - No... no it wasn't. But, it looked right. */
+ /*
+ This new code should, SHOULD, behave as the original code did.
+ This will wake up all readers waiting on the lock. This code favors
+ strongly writers, but, as of making this change, pthreads favors
+ writers, and cthreads did favor writers.
+ */
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
/* Force the pages in core and make sure they are dirty */
for (pokeaddr = (int *)mapaddr;
@@ -432,10 +446,10 @@ block_extended (struct node *np,
*pokeaddr = *pokeaddr;
/* Turn off the special pagein permission */
- spin_lock (&unlocked_pagein_lock);
+ pthread_spin_lock (&unlocked_pagein_lock);
np->dn->fileinfo->allow_unlocked_pagein = 0;
np->dn->fileinfo->unlocked_pagein_length = 0;
- spin_unlock (&unlocked_pagein_lock);
+ pthread_spin_unlock (&unlocked_pagein_lock);
/* Undo mapping */
mach_port_deallocate (mach_task_self (), mapobj);
@@ -497,7 +511,7 @@ diskfs_grow (struct node *np,
if (size == 0)
size = sblock->fs_bsize;
- rwlock_writer_lock (&np->dn->allocptrlock);
+ pthread_rwlock_wrlock (&np->dn->allocptrlock);
/* The old last block of the file. */
olbn = lblkno (sblock, np->allocsize - 1);
@@ -680,7 +694,10 @@ diskfs_grow (struct node *np,
np->allocsize = newallocsize;
}
- rwlock_writer_unlock (&np->dn->allocptrlock);
+ pthread_rwlock_unlock (&np->dn->allocptrlock);
+ pthread_mutex_lock (&np->dn->waitlock);
+ pthread_cond_broadcast (&np->dn->waitcond);
+ pthread_mutex_unlock (&np->dn->waitlock);
if (need_sync)
diskfs_file_update (np, 1);
diff --git a/ufs/ufs.h b/ufs/ufs.h
index f59784d5..0a79f560 100644
--- a/ufs/ufs.h
+++ b/ufs/ufs.h
@@ -25,6 +25,7 @@
#include <hurd/diskfs.h>
#include <sys/mman.h>
#include <assert.h>
+#include <pthread.h>
#include <features.h>
#include "fs.h"
#include "dinode.h"
@@ -54,7 +55,9 @@ struct disknode
/* Links on hash list. */
struct node *hnext, **hprevp;
- struct rwlock allocptrlock;
+ pthread_rwlock_t allocptrlock;
+ pthread_mutex_t waitlock;
+ pthread_cond_t waitcond;
struct dirty_indir *dirty;
@@ -112,14 +115,14 @@ extern struct csum *csum;
int sblock_dirty;
int csum_dirty;
-spin_lock_t node2pagelock;
+pthread_spinlock_t node2pagelock;
-spin_lock_t alloclock;
+pthread_spinlock_t alloclock;
-spin_lock_t gennumberlock;
+pthread_spinlock_t gennumberlock;
u_long nextgennumber;
-spin_lock_t unlocked_pagein_lock;
+pthread_spinlock_t unlocked_pagein_lock;
/* The compat_mode specifies whether or not we write
extensions onto the disk. */