summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPino Toscano <toscano.pino@tiscali.i>2013-03-14 16:32:04 (GMT)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-03-15 01:17:51 (GMT)
commit2961fbd036c40e8390b4af3b6f7d570d6945c86c (patch)
tree1e5e6ed1ddca29f240e3e6374d12e7703521da97
parent64dfa4e12d93c13b676d1cd7d86f4f4004ebfafa (diff)
Switch from cthreads to pthreads
Makefiles, headers, types, macros and function calls are renamed where appropriate. * Makefile: Switch from cthreads to pthreads. * lib.c: Likewise. * lib.h: Likewise. * lnode.c: Likewise. * lnode.h: Likewise. * ncache.c: Likewise. * ncache.h: Likewise. * netfs.c: Likewise. * node.c: Likewise. * options.c: Likewise. * pattern.c: Likewise. * pattern.h: Likewise. * stow.c: Likewise. * ulfs.c: Likewise. * ulfs.h: Likewise. * update.c: Likewise.
-rw-r--r--Makefile2
-rw-r--r--lib.c5
-rw-r--r--lib.h6
-rw-r--r--lnode.c10
-rw-r--r--lnode.h4
-rw-r--r--ncache.c12
-rw-r--r--ncache.h4
-rw-r--r--netfs.c52
-rw-r--r--node.c16
-rw-r--r--options.c2
-rw-r--r--pattern.c16
-rw-r--r--pattern.h4
-rw-r--r--stow.c26
-rw-r--r--ulfs.c15
-rw-r--r--ulfs.h8
-rw-r--r--update.c43
16 files changed, 120 insertions, 105 deletions
diff --git a/Makefile b/Makefile
index 7ef2100..8f58759 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ MIGCOM = mig -cc cat - /dev/null
CFLAGS += -Wall -g -O2 -D_FILE_OFFSET_BITS=64 -std=gnu99 \
-DDEBUG
-LDFLAGS += -lnetfs -lfshelp -liohelp -lthreads \
+LDFLAGS += -lnetfs -lfshelp -liohelp -lpthread \
-lports -lihash -lshouldbeinlibc -lhurdbugaddr
OBJS = main.o node.o lnode.o ulfs.o ncache.o netfs.o \
lib.o options.o pattern.o stow.o update.o
diff --git a/lib.c b/lib.c
index 0423c1b..05c2da0 100644
--- a/lib.c
+++ b/lib.c
@@ -19,18 +19,19 @@
#define _GNU_SOURCE
-#include <hurd/netfs.h>
+#include <pthread.h>
#include <error.h>
#include <dirent.h>
#include <errno.h>
#include <sys/mman.h>
#include <stddef.h>
+#include <string.h>
#include "lib.h"
/* Lock, which must be held, during printing of debugging
messages. */
-struct mutex debug_msg_lock = MUTEX_INITIALIZER;
+pthread_mutex_t debug_msg_lock = PTHREAD_MUTEX_INITIALIZER;
/* Returns no error if PATH points to a directory. */
error_t check_dir (char *path)
diff --git a/lib.h b/lib.h
index be9a219..095adaa 100644
--- a/lib.h
+++ b/lib.h
@@ -65,17 +65,17 @@ error_t file_lookup (file_t dir, char *name, int flags0, int flags1, int mode,
/* Returns no error if directory. */
error_t check_dir (char *path);
-extern struct mutex debug_msg_lock;
+extern pthread_mutex_t debug_msg_lock;
/* Support for debugging messages. */
#define debug_msg_send(fmt, args...) \
do \
{ \
- mutex_lock (&debug_msg_lock); \
+ pthread_mutex_lock (&debug_msg_lock); \
fprintf (stderr, "%s:%i: ", __FILE__, __LINE__); \
fprintf (stderr, fmt , ## args); \
putc ('\n', stderr); \
- mutex_unlock (&debug_msg_lock); \
+ pthread_mutex_unlock (&debug_msg_lock); \
} \
while (0)
diff --git a/lnode.c b/lnode.c
index 9b242bb..10d32ca 100644
--- a/lnode.c
+++ b/lnode.c
@@ -22,7 +22,7 @@
#define _GNU_SOURCE
-#include <hurd/netfs.h>
+#include <pthread.h>
#include <error.h>
#include <stdlib.h>
#include <string.h>
@@ -66,8 +66,8 @@ lnode_create (char *name, lnode_t **node)
node_new->dir = NULL;
node_new->entries = NULL;
node_new->references = 1;
- mutex_init (&node_new->lock);
- mutex_lock (&node_new->lock);
+ pthread_mutex_init (&node_new->lock, NULL);
+ pthread_mutex_lock (&node_new->lock);
*node = node_new;
}
}
@@ -127,7 +127,7 @@ lnode_ref_remove (lnode_t *node)
lnode_destroy (node);
}
else
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
/* Get a light node by it's name. The looked up node is locked and
@@ -142,7 +142,7 @@ lnode_get (lnode_t *dir, char *name,
for (n = dir->entries; n && strcmp (n->name, name); n = n->next);
if (n)
{
- mutex_lock (&n->lock);
+ pthread_mutex_lock (&n->lock);
lnode_ref_add (n);
*node = n;
}
diff --git a/lnode.h b/lnode.h
index b43b7b2..f5a50f7 100644
--- a/lnode.h
+++ b/lnode.h
@@ -22,7 +22,7 @@
#ifndef INCLUDED_LNODE_H
#define INCLUDED_LNODE_H
-#include <hurd/netfs.h>
+#include <pthread.h>
#include <error.h>
struct lnode
@@ -40,7 +40,7 @@ struct lnode
contained int. */
struct lnode *entries; /* A reference to the list containing
the entries of this light node. */
- struct mutex lock; /* A lock. */
+ pthread_mutex_t lock; /* A lock. */
};
typedef struct lnode lnode_t;
diff --git a/ncache.c b/ncache.c
index 4c83ac0..2ebad57 100644
--- a/ncache.c
+++ b/ncache.c
@@ -43,7 +43,7 @@ ncache_init (int size_max)
ncache.lru = NULL;
ncache.size_max = size_max;
ncache.size_current = 0;
- mutex_init (&ncache.lock);
+ pthread_mutex_init (&ncache.lock, NULL);
}
/* Remove the given node NODE from the cache. */
@@ -70,10 +70,10 @@ ncache_reset (void)
{
node_t *node;
- mutex_lock (&ncache.lock);
+ pthread_mutex_lock (&ncache.lock);
while ((node = ncache.mru))
ncache_node_remove (node);
- mutex_unlock (&ncache.lock);
+ pthread_mutex_unlock (&ncache.lock);
}
/* Lookup the node for the light node LNODE. If it does not exist
@@ -101,7 +101,7 @@ ncache_node_lookup (lnode_t *lnode, node_t **node)
if (! err)
{
- mutex_lock (&n->lock);
+ pthread_mutex_lock (&n->lock);
*node = n;
}
return err;
@@ -112,7 +112,7 @@ ncache_node_lookup (lnode_t *lnode, node_t **node)
void
ncache_node_add (node_t *node)
{
- mutex_lock (&ncache.lock);
+ pthread_mutex_lock (&ncache.lock);
debug_msg ("adding node to cache: %s", node->nn->lnode->name);
@@ -147,5 +147,5 @@ ncache_node_add (node_t *node)
netfs_nrele (lru);
}
- mutex_unlock (&ncache.lock);
+ pthread_mutex_unlock (&ncache.lock);
}
diff --git a/ncache.h b/ncache.h
index 8fa7d10..dd9c330 100644
--- a/ncache.h
+++ b/ncache.h
@@ -21,7 +21,7 @@
#define INCLUDED_NCACHE_H
#include <error.h>
-#include <hurd/netfs.h>
+#include <pthread.h>
#include "node.h"
@@ -35,7 +35,7 @@ typedef struct ncache
cache. */
int size_current; /* Current number of nodes in the
cache. */
- struct mutex lock; /* A lock. */
+ pthread_mutex_t lock; /* A lock. */
} ncache_t;
/* Cache size, may be overwritten by the user. */
diff --git a/netfs.c b/netfs.c
index 9d24f06..d93f896 100644
--- a/netfs.c
+++ b/netfs.c
@@ -292,7 +292,7 @@ netfs_attempt_sync (struct iouser *cred, struct node *np,
/* The index of the currently analyzed filesystem. */
int i;
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
/* Sync every directory associated with `np`.
@@ -320,7 +320,7 @@ netfs_attempt_sync (struct iouser *cred, struct node *np,
++i;
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return final_err;
}
@@ -338,7 +338,7 @@ netfs_attempt_syncfs (struct iouser *cred, int wait)
/* The index of the currently analyzed filesystem. */
int i;
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
/* Sync every unioned directory maintained by unionfs.
@@ -364,7 +364,7 @@ netfs_attempt_syncfs (struct iouser *cred, int wait)
++i;
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return final_err;
}
@@ -507,7 +507,7 @@ error_t
netfs_attempt_mkfile (struct iouser *user, struct node *dir,
mode_t mode, struct node **np)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -519,7 +519,7 @@ error_t
netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **np)
{
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -546,10 +546,10 @@ netfs_attempt_create_file_reduced (struct iouser *user, struct node *dir,
goto exit;
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
err = node_lookup_file (dir, name, flags | O_CREAT,
&p, &statbuf);
- mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir->lock);
if (err)
goto exit;
@@ -590,7 +590,7 @@ netfs_attempt_create_file_reduced (struct iouser *user, struct node *dir,
port_dealloc (p);
exit:
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return err;
}
@@ -682,7 +682,7 @@ netfs_attempt_lookup_improved (struct iouser *user, struct node *dir,
mach_port_t p;
error_t err;
- mutex_lock (&dir->nn->lnode->lock);
+ pthread_mutex_lock (&dir->nn->lnode->lock);
err = fshelp_access (&dir->nn_stat, S_IEXEC, user);
if (err)
@@ -724,14 +724,14 @@ netfs_attempt_lookup_improved (struct iouser *user, struct node *dir,
err = node_update (dir);
/* We have to unlock this node while doing lookups. */
- mutex_unlock (&dir_lnode->lock);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir_lnode->lock);
+ pthread_mutex_unlock (&dir->lock);
err = node_lookup_file (dir, name, flags & ~(O_NOLINK|O_CREAT),
&p, &statbuf);
- mutex_lock (&dir->lock);
- mutex_lock (&dir_lnode->lock);
+ pthread_mutex_lock (&dir->lock);
+ pthread_mutex_lock (&dir_lnode->lock);
if (err)
@@ -820,12 +820,12 @@ netfs_attempt_lookup_improved (struct iouser *user, struct node *dir,
*np = NULL;
else if (*np)
{
- mutex_unlock (&(*np)->lock);
+ pthread_mutex_unlock (&(*np)->lock);
ncache_node_add (*np);
}
- mutex_unlock (&dir->nn->lnode->lock);
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->nn->lnode->lock);
+ pthread_mutex_unlock (&dir->lock);
return err;
}
@@ -880,14 +880,14 @@ netfs_S_dir_lookup (struct protid *diruser,
/* Set things up in the state expected by the code from gotit: on. */
dnp = 0;
np = diruser->po->np;
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
netfs_nref (np);
goto gotit;
}
dnp = diruser->po->np;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
netfs_nref (dnp); /* acquire a reference for later netfs_nput */
@@ -932,7 +932,7 @@ netfs_S_dir_lookup (struct protid *diruser,
if (! lastcomp)
strcpy (retry_name, nextname);
error = 0;
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
goto out;
}
else if (diruser->po->root_parent != MACH_PORT_NULL)
@@ -946,7 +946,7 @@ netfs_S_dir_lookup (struct protid *diruser,
if (!lastcomp)
strcpy (retry_name, nextname);
error = 0;
- mutex_unlock (&dnp->lock);
+ pthread_mutex_unlock (&dnp->lock);
goto out;
}
else
@@ -974,7 +974,7 @@ netfs_S_dir_lookup (struct protid *diruser,
{
mode &= ~(S_IFMT | S_ISPARE | S_ISVTX);
mode |= S_IFREG;
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
error = netfs_attempt_create_file_reduced (diruser->user, dnp,
filename, mode, flags);
@@ -986,7 +986,7 @@ netfs_S_dir_lookup (struct protid *diruser,
that's fine; otherwise, we have to retry the lookup. */
if ((!error) || (error == EEXIST && !excl))
{
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
goto retry_lookup;
}
@@ -999,9 +999,9 @@ netfs_S_dir_lookup (struct protid *diruser,
if (np)
{
- mutex_lock (&np->lock);
+ pthread_mutex_lock (&np->lock);
error = netfs_validate_stat (np, diruser->user);
- mutex_unlock (&np->lock);
+ pthread_mutex_unlock (&np->lock);
if (error)
goto out;
}
@@ -1059,7 +1059,7 @@ netfs_S_dir_lookup (struct protid *diruser,
create = 0;
}
netfs_nput (np);
- mutex_lock (&dnp->lock);
+ pthread_mutex_lock (&dnp->lock);
np = 0;
}
else
diff --git a/node.c b/node.c
index cf9a8b4..6e1b849 100644
--- a/node.c
+++ b/node.c
@@ -93,7 +93,7 @@ node_destroy (node_t *node)
debug_msg ("node destroy: %s", node->nn->lnode->name);
assert (! (node->nn->ncache_next || node->nn->ncache_prev));
node_ulfs_free (node);
- mutex_lock (&node->nn->lnode->lock);
+ pthread_mutex_lock (&node->nn->lnode->lock);
node->nn->lnode->node = NULL;
lnode_ref_remove (node->nn->lnode);
free (node->nn);
@@ -118,12 +118,12 @@ node_update (node_t *node)
if (node_is_root (node))
return err;
- mutex_lock (&netfs_root_node->lock);
+ pthread_mutex_lock (&netfs_root_node->lock);
err = lnode_path_construct (node->nn->lnode, &path);
if (err)
{
- mutex_unlock (&netfs_root_node->lock);
+ pthread_mutex_unlock (&netfs_root_node->lock);
return err;
}
@@ -178,7 +178,7 @@ node_update (node_t *node)
free (path);
node->nn->flags |= FLAG_NODE_ULFS_UPTODATE;
- mutex_unlock (&netfs_root_node->lock);
+ pthread_mutex_unlock (&netfs_root_node->lock);
return err;
}
@@ -500,7 +500,7 @@ node_create_root (node_t **root_node)
return err;
}
- mutex_unlock (&lnode->lock);
+ pthread_mutex_unlock (&lnode->lock);
*root_node = node;
return err;
}
@@ -515,12 +515,12 @@ node_init_root (node_t *node)
ulfs_t *ulfs;
int i = 0;
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
err = node_ulfs_init (node);
if (err)
{
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return err;
}
@@ -550,6 +550,6 @@ node_init_root (node_t *node)
i++;
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return err;
}
diff --git a/options.c b/options.c
index 2d3a11f..37b5d4a 100644
--- a/options.c
+++ b/options.c
@@ -79,7 +79,7 @@ argp_parse_common_options (int key, char *arg, struct argp_state *state)
ulfs_match = 0, ulfs_priority = 0;
static struct patternlist ulfs_patternlist =
{
- .lock = MUTEX_INITIALIZER,
+ .lock = PTHREAD_MUTEX_INITIALIZER,
.head = NULL
};
error_t err = 0;
diff --git a/pattern.c b/pattern.c
index 68a0791..7ec94e1 100644
--- a/pattern.c
+++ b/pattern.c
@@ -58,7 +58,7 @@ patternlist_add (struct patternlist *list, char *pattern)
listentry->pattern = dup;
- mutex_lock (& (list->lock));
+ pthread_mutex_lock (& (list->lock));
if (list->head == NULL) /* List is empty. */
{
list->head = listentry;
@@ -69,7 +69,7 @@ patternlist_add (struct patternlist *list, char *pattern)
listentry->next = list->head;
list->head = listentry;
}
- mutex_unlock (& (list->lock));
+ pthread_mutex_unlock (& (list->lock));
return err;
}
@@ -84,7 +84,7 @@ patternlist_match (struct patternlist *list, char *string)
ptr = list->head;
- mutex_lock (&list->lock);
+ pthread_mutex_lock (&list->lock);
while (ptr != NULL)
{
err = fnmatch (ptr->pattern, string, FNM_FILE_NAME);
@@ -94,7 +94,7 @@ patternlist_match (struct patternlist *list, char *string)
ptr = ptr->next;
}
- mutex_unlock (&list->lock);
+ pthread_mutex_unlock (&list->lock);
return err;
}
@@ -105,7 +105,7 @@ patternlist_destroy (struct patternlist *list)
{
struct pattern *next, *ptr = list->head;
- mutex_lock (& (list->lock));
+ pthread_mutex_lock (& (list->lock));
while (ptr != NULL)
{
next = ptr->next;
@@ -114,7 +114,7 @@ patternlist_destroy (struct patternlist *list)
ptr = next;
}
- mutex_unlock (& (list->lock));
+ pthread_mutex_unlock (& (list->lock));
}
/* Return nonzero if *PATTERNLIST is empty. */
@@ -123,9 +123,9 @@ patternlist_isempty (struct patternlist *list)
{
int ret;
- mutex_lock (& (list->lock));
+ pthread_mutex_lock (& (list->lock));
ret = (list->head == NULL);
- mutex_unlock (& (list->lock));
+ pthread_mutex_unlock (& (list->lock));
return ret;
}
diff --git a/pattern.h b/pattern.h
index 1bab993..e5b1835 100644
--- a/pattern.h
+++ b/pattern.h
@@ -22,7 +22,7 @@
#ifndef _PATTERN_H
#define _PATTERN_H
-#include <hurd/netfs.h> /* For mutex stuff. */
+#include <pthread.h>
struct pattern
{
@@ -33,7 +33,7 @@ struct pattern
struct patternlist
{
- struct mutex lock;
+ pthread_mutex_t lock;
struct pattern *head;
};
diff --git a/stow.c b/stow.c
index fa99747..fa52e66 100644
--- a/stow.c
+++ b/stow.c
@@ -35,7 +35,7 @@ struct stow_privdata
struct patternlist *patternlist;
int flags;
int priority;
- struct mutex lock;
+ pthread_mutex_t lock;
};
static error_t
@@ -78,7 +78,7 @@ _stow_scanstowentry (char *arg, char *dirpath, void *priv)
free (tmp);
}
- mutex_lock (&privdata->lock);
+ pthread_mutex_lock (&privdata->lock);
if (patternlist_isempty (privdata->patternlist))
{
@@ -86,7 +86,7 @@ _stow_scanstowentry (char *arg, char *dirpath, void *priv)
err = ulfs_register (filepath, privdata->flags, privdata->priority);
if (err)
{
- mutex_unlock (&privdata->lock);
+ pthread_mutex_unlock (&privdata->lock);
return err;
}
@@ -96,21 +96,20 @@ _stow_scanstowentry (char *arg, char *dirpath, void *priv)
err = for_each_subdir_priv (filepath, _stow_registermatchingdirs, priv);
if (err)
{
- mutex_unlock (&privdata->lock);
+ pthread_mutex_unlock (&privdata->lock);
free (filepath);
return err;
}
}
free (filepath);
- mutex_unlock (&privdata->lock);
+ pthread_mutex_unlock (&privdata->lock);
return err;
}
/* Implement server for fs_notify. */
-#include <cthreads.h>
#include <hurd/port.h>
#include "stow-priv.h"
@@ -227,8 +226,8 @@ stow_S_dir_changed (stow_notify_t notify, natural_t tickno,
}
/* This is the server thread waiting for dir_changed messages. */
-static void
-_stow_notify_thread()
+static void *
+_stow_notify_thread(void *arg)
{
int stow_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp)
{
@@ -247,6 +246,8 @@ _stow_notify_thread()
0);
}
while (1);
+
+ return NULL;
}
@@ -294,7 +295,7 @@ stow_diradd (char *dir, int flags, struct patternlist *patternlist,
mypriv->patternlist = patternlist;
mypriv->flags = flags;
mypriv->priority = priority;
- mutex_init (&mypriv->lock);
+ pthread_mutex_init (&mypriv->lock, NULL);
err = for_each_subdir_priv (dir, _stow_scanstowentry, (void *)mypriv);
if (err)
@@ -313,6 +314,7 @@ error_t
stow_init (void)
{
error_t err = 0;
+ pthread_t thread;
stow_port_bucket = ports_create_bucket ();
if (!stow_port_bucket)
@@ -322,7 +324,11 @@ stow_init (void)
if (!stow_port_class)
return errno;
- cthread_detach (cthread_fork ( (cthread_fn_t)_stow_notify_thread, 0));
+ err = pthread_create (&thread, NULL, _stow_notify_thread, NULL);
+ if (err)
+ return err;
+
+ pthread_detach (thread);
return err;
}
diff --git a/ulfs.c b/ulfs.c
index 3c565a5..c0a1464 100644
--- a/ulfs.c
+++ b/ulfs.c
@@ -21,7 +21,6 @@
#define _GNU_SOURCE
-#include <hurd/netfs.h>
#include <stdlib.h>
#include <error.h>
#include <string.h>
@@ -43,7 +42,7 @@ ulfs_t *ulfs_chain_end;
unsigned int ulfs_num;
/* The lock protecting the ulfs data structures. */
-struct mutex ulfs_lock = MUTEX_INITIALIZER;
+pthread_mutex_t ulfs_lock = PTHREAD_MUTEX_INITIALIZER;
/* Create a new ulfs element. */
static error_t
@@ -226,7 +225,7 @@ ulfs_register (char *path, int flags, int priority)
return err;
}
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
err = ulfs_create (path, &ulfs);
if (! err)
{
@@ -235,7 +234,7 @@ ulfs_register (char *path, int flags, int priority)
ulfs_install (ulfs);
ulfs_num++;
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return err;
}
@@ -254,7 +253,7 @@ ulfs_check ()
struct ulfs_destroy *next;
} *ulfs_destroy_q = NULL;
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
u = ulfs_chain_start;
while (u)
@@ -296,7 +295,7 @@ ulfs_check ()
free (ptr);
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
}
@@ -307,7 +306,7 @@ ulfs_unregister (char *path)
ulfs_t *ulfs;
error_t err;
- mutex_lock (&ulfs_lock);
+ pthread_mutex_lock (&ulfs_lock);
err = ulfs_get_path (path, &ulfs);
if (! err)
{
@@ -315,7 +314,7 @@ ulfs_unregister (char *path)
ulfs_destroy (ulfs);
ulfs_num--;
}
- mutex_unlock (&ulfs_lock);
+ pthread_mutex_unlock (&ulfs_lock);
return err;
}
diff --git a/ulfs.h b/ulfs.h
index 532e3c7..a39a7f7 100644
--- a/ulfs.h
+++ b/ulfs.h
@@ -22,6 +22,8 @@
#ifndef INCLUDED_ULFS_H
#define INCLUDED_ULFS_H
+#include <pthread.h>
+
/* The structure for each registered underlying filesystem. */
typedef struct ulfs
{
@@ -47,7 +49,7 @@ extern ulfs_t *ulfs_chain_end;
extern unsigned int ulfs_num;
/* The lock protecting the ulfs data structures. */
-extern struct mutex ulfs_lock;
+extern pthread_mutex_t ulfs_lock;
/* Register a new underlying filesystem. */
error_t ulfs_register (char *path, int flags, int priority);
@@ -62,9 +64,9 @@ error_t ulfs_get_num (int num, ulfs_t **ulfs);
void ulfs_check (void);
#define ulfs_iterate \
- for (ulfs_t *ulfs = (mutex_lock (&ulfs_lock), \
+ for (ulfs_t *ulfs = (pthread_mutex_lock (&ulfs_lock), \
ulfs_chain_start); \
- ulfs || (mutex_unlock (&ulfs_lock), 0); \
+ ulfs || (pthread_mutex_unlock (&ulfs_lock), 0); \
ulfs = ulfs->next)
#define ulfs_iterate_unlocked \
diff --git a/update.c b/update.c
index 8ec6688..cba9924 100644
--- a/update.c
+++ b/update.c
@@ -24,8 +24,6 @@
#include <errno.h>
#include <string.h>
-#include <cthreads.h>
-#include <rwlock.h>
#include "ncache.h"
#include "node.h"
@@ -34,21 +32,21 @@
/* Reader lock is used by threads that are going to
add/remove an ulfs; writer lock is hold by the
update thread. */
-static struct rwlock update_rwlock;
-static struct condition update_wakeup;
-static struct mutex update_lock;
+static pthread_rwlock_t update_rwlock;
+static pthread_cond_t update_wakeup;
+static pthread_mutex_t update_lock;
-static void
-_root_update_thread ()
+static void *
+_root_update_thread (void *arg)
{
error_t err;
while (1)
{
- if (hurd_condition_wait (&update_wakeup, &update_lock))
- mutex_unlock (&update_lock);
+ if (pthread_hurd_cond_wait_np (&update_wakeup, &update_lock))
+ pthread_mutex_unlock (&update_lock);
- rwlock_writer_lock (&update_rwlock);
+ pthread_rwlock_wrlock (&update_rwlock);
do
{
@@ -64,34 +62,43 @@ _root_update_thread ()
ncache_reset ();
- rwlock_writer_unlock (&update_rwlock);
+ pthread_rwlock_unlock (&update_rwlock);
}
+
+ return NULL;
}
void
root_update_schedule ()
{
- condition_signal (&update_wakeup);
+ pthread_cond_signal (&update_wakeup);
}
void
root_update_disable ()
{
- rwlock_reader_lock (&update_rwlock);
+ pthread_rwlock_rdlock (&update_rwlock);
}
void
root_update_enable ()
{
- rwlock_reader_unlock (&update_rwlock);
+ pthread_rwlock_unlock (&update_rwlock);
}
void
root_update_init()
{
- mutex_init (&update_lock);
- rwlock_init (&update_rwlock);
- condition_init (&update_wakeup);
+ pthread_t thread;
+ error_t err;
+
+ pthread_mutex_init (&update_lock, NULL);
+ pthread_rwlock_init (&update_rwlock, NULL);
+ pthread_cond_init (&update_wakeup, NULL);
- cthread_detach (cthread_fork ( (cthread_fn_t)_root_update_thread, 0));
+ err = pthread_create (&thread, NULL, _root_update_thread, NULL);
+ if (!err)
+ pthread_detach (thread);
+ else
+ perror ("root_update_init/pthread_create");
}