diff options
author | Zheng Da <zhengda1936@gmail.com> | 2010-05-28 13:20:41 +0200 |
---|---|---|
committer | Zheng Da <zhengda1936@gmail.com> | 2010-05-28 13:20:41 +0200 |
commit | d7cdbff7c6ce2723ac74ee59dfc8c15222b83c73 (patch) | |
tree | e2078839e1d7af7243a41bf6cea16213e4c6b2a6 /libhurd-slab | |
parent | f23a1dec7638dad40438d8ca948b3276a22ca527 (diff) |
Use cthreads in hurd-slab.
Diffstat (limited to 'libhurd-slab')
-rw-r--r-- | libhurd-slab/slab.c | 22 | ||||
-rw-r--r-- | libhurd-slab/slab.h | 4 |
2 files changed, 12 insertions, 14 deletions
diff --git a/libhurd-slab/slab.c b/libhurd-slab/slab.c index 375df6d9..51261e21 100644 --- a/libhurd-slab/slab.c +++ b/libhurd-slab/slab.c @@ -27,7 +27,7 @@ #include <assert.h> #include <string.h> #include <unistd.h> -#include <pthread.h> +#include <cthreads.h> #include <stdint.h> #include "slab.h" @@ -332,7 +332,7 @@ hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, - sizeof (union hurd_bufctl))) return EINVAL; - err = pthread_mutex_init (&space->lock, NULL); + err = mutex_init (&space->lock); if (err) return err; @@ -388,11 +388,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. */ - pthread_mutex_lock (&space->lock); + mutex_lock (&space->lock); err = reap (space); if (err) { - pthread_mutex_unlock (&space->lock); + mutex_unlock (&space->lock); return err; } @@ -400,14 +400,12 @@ hurd_slab_destroy (hurd_slab_space_t space) { /* There are still slabs, i.e. there is outstanding allocations. Return EBUSY. */ - pthread_mutex_unlock (&space->lock); + mutex_unlock (&space->lock); return EBUSY; } /* FIXME: Remove slab space from pager's reap functionality. */ - /* The only resource that needs to be deallocated is the mutex. */ - pthread_mutex_destroy (&space->lock); return 0; } @@ -433,7 +431,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) error_t err; union hurd_bufctl *bufctl; - pthread_mutex_lock (&space->lock); + 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 @@ -443,7 +441,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) err = grow (space); if (err) { - pthread_mutex_unlock (&space->lock); + mutex_unlock (&space->lock); return err; } } @@ -474,7 +472,7 @@ hurd_slab_alloc (hurd_slab_space_t space, void **buffer) space->first_free = new_first; } *buffer = ((void *) bufctl) - (space->size - sizeof *bufctl); - pthread_mutex_unlock (&space->lock); + mutex_unlock (&space->lock); return 0; } @@ -498,7 +496,7 @@ hurd_slab_dealloc (hurd_slab_space_t space, void *buffer) assert (space->initialized); - pthread_mutex_lock (&space->lock); + mutex_lock (&space->lock); bufctl = (buffer + (space->size - sizeof *bufctl)); put_on_slab_list (slab = bufctl->slab, bufctl); @@ -511,5 +509,5 @@ hurd_slab_dealloc (hurd_slab_space_t space, void *buffer) || slab->refcount < space->first_free->refcount) space->first_free = slab; - pthread_mutex_unlock (&space->lock); + mutex_unlock (&space->lock); } diff --git a/libhurd-slab/slab.h b/libhurd-slab/slab.h index 6eeb8e48..d42fd4c3 100644 --- a/libhurd-slab/slab.h +++ b/libhurd-slab/slab.h @@ -24,7 +24,7 @@ #include <errno.h> #include <stdbool.h> -#include <pthread.h> +#include <cthreads.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. */ - pthread_mutex_t lock; + struct mutex lock; /* The size and alignment of objects allocated using this slab space. These to fields are used to calculate the final object |