diff options
author | Pino Toscano <toscano.pino@tiscali.i> | 2013-03-14 17:32:04 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2013-03-15 02:17:51 +0100 |
commit | 2961fbd036c40e8390b4af3b6f7d570d6945c86c (patch) | |
tree | 1e5e6ed1ddca29f240e3e6374d12e7703521da97 /update.c | |
parent | 64dfa4e12d93c13b676d1cd7d86f4f4004ebfafa (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.
Diffstat (limited to 'update.c')
-rw-r--r-- | update.c | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -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"); } |