diff options
-rw-r--r-- | sys/uvm/uvm_map.h | 84 | ||||
-rw-r--r-- | sys/uvm/uvm_map_i.h | 4 |
2 files changed, 26 insertions, 62 deletions
diff --git a/sys/uvm/uvm_map.h b/sys/uvm/uvm_map.h index fcc6711d0e2..7de3f38393b 100644 --- a/sys/uvm/uvm_map.h +++ b/sys/uvm/uvm_map.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_map.h,v 1.36 2007/03/25 13:02:51 thib Exp $ */ +/* $OpenBSD: uvm_map.h,v 1.37 2007/04/04 18:02:59 art Exp $ */ /* $NetBSD: uvm_map.h,v 1.24 2001/02/18 21:19:08 chs Exp $ */ /* @@ -70,17 +70,11 @@ #ifndef _UVM_UVM_MAP_H_ #define _UVM_UVM_MAP_H_ -/* - * uvm_map.h - */ +#include <sys/rwlock.h> #ifdef _KERNEL /* - * macros - */ - -/* * UVM_MAP_CLIP_START: ensure that the entry begins at or after * the starting address, if it doesn't we split the entry. * @@ -219,7 +213,7 @@ struct vm_map_entry { */ struct vm_map { struct pmap * pmap; /* Physical map */ - lock_data_t lock; /* Lock for map data */ + struct rwlock lock; /* Lock for map data */ RB_HEAD(uvm_tree, vm_map_entry) rbhead; /* Tree for entries */ struct vm_map_entry header; /* List of entries */ int nentries; /* Number of entries */ @@ -389,18 +383,17 @@ static __inline void vm_map_lock(vm_map_t); extern const char vmmapbsy[]; static __inline boolean_t -vm_map_lock_try(map) - vm_map_t map; +vm_map_lock_try(struct vm_map *map) { boolean_t rv; - if (map->flags & VM_MAP_INTRSAFE) - rv = simple_lock_try(&map->lock.lk_interlock); - else { + if (map->flags & VM_MAP_INTRSAFE) { + rv = TRUE; + } else { if (map->flags & VM_MAP_BUSY) { return (FALSE); } - rv = (lockmgr(&map->lock, LK_EXCLUSIVE|LK_NOWAIT, NULL) == 0); + rv = (rw_enter(&map->lock, RW_WRITE|RW_NOSLEEP) == 0); } if (rv) @@ -410,67 +403,38 @@ vm_map_lock_try(map) } static __inline void -vm_map_lock(map) - vm_map_t map; +vm_map_lock(struct vm_map *map) { - int error; - - if (map->flags & VM_MAP_INTRSAFE) { - simple_lock(&map->lock.lk_interlock); + if (map->flags & VM_MAP_INTRSAFE) return; - } - try_again: - while (map->flags & VM_MAP_BUSY) { - map->flags |= VM_MAP_WANTLOCK; - ltsleep(&map->flags, PVM, (char *)vmmapbsy, 0, NULL); - } - - error = lockmgr(&map->lock, LK_EXCLUSIVE|LK_SLEEPFAIL, NULL); - - if (error) { - goto try_again; - } + do { + while (map->flags & VM_MAP_BUSY) { + map->flags |= VM_MAP_WANTLOCK; + tsleep(&map->flags, PVM, (char *)vmmapbsy, 0); + } + } while (rw_enter(&map->lock, RW_WRITE|RW_SLEEPFAIL) != 0); - (map)->timestamp++; + map->timestamp++; } -#ifdef DIAGNOSTIC -#define vm_map_lock_read(map) \ -do { \ - if (map->flags & VM_MAP_INTRSAFE) \ - panic("vm_map_lock_read: intrsafe map"); \ - (void) lockmgr(&(map)->lock, LK_SHARED, NULL); \ -} while (0) -#else -#define vm_map_lock_read(map) \ - (void) lockmgr(&(map)->lock, LK_SHARED, NULL) -#endif +#define vm_map_lock_read(map) rw_enter_read(&(map)->lock) #define vm_map_unlock(map) \ do { \ - if ((map)->flags & VM_MAP_INTRSAFE) \ - simple_unlock(&(map)->lock.lk_interlock); \ - else \ - (void) lockmgr(&(map)->lock, LK_RELEASE, NULL); \ + if (((map)->flags & VM_MAP_INTRSAFE) == 0) \ + rw_exit(&(map)->lock); \ } while (0) -#define vm_map_unlock_read(map) \ - (void) lockmgr(&(map)->lock, LK_RELEASE, NULL) +#define vm_map_unlock_read(map) rw_exit_read(&(map)->lock) -#define vm_map_downgrade(map) \ - (void) lockmgr(&(map)->lock, LK_DOWNGRADE, NULL) +#define vm_map_downgrade(map) rw_enter(&(map)->lock, RW_DOWNGRADE) -#ifdef DIAGNOSTIC #define vm_map_upgrade(map) \ do { \ - if (lockmgr(&(map)->lock, LK_UPGRADE, NULL) != 0) \ - panic("vm_map_upgrade: failed to upgrade lock"); \ + rw_exit_read(&(map)->lock); \ + rw_enter_write(&(map)->lock); \ } while (0) -#else -#define vm_map_upgrade(map) \ - (void) lockmgr(&(map)->lock, LK_UPGRADE, NULL) -#endif #define vm_map_busy(map) \ do { \ diff --git a/sys/uvm/uvm_map_i.h b/sys/uvm/uvm_map_i.h index 65b01852445..21bc39cea41 100644 --- a/sys/uvm/uvm_map_i.h +++ b/sys/uvm/uvm_map_i.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_map_i.h,v 1.19 2007/03/25 13:02:51 thib Exp $ */ +/* $OpenBSD: uvm_map_i.h,v 1.20 2007/04/04 18:02:59 art Exp $ */ /* $NetBSD: uvm_map_i.h,v 1.18 2000/11/27 08:40:04 chs Exp $ */ /* @@ -125,7 +125,7 @@ uvm_map_setup(map, min, max, flags) map->first_free = &map->header; map->hint = &map->header; map->timestamp = 0; - lockinit(&map->lock, PVM, "vmmaplk", 0, 0); + rw_init(&map->lock, "vmmaplk"); simple_lock_init(&map->ref_lock); simple_lock_init(&map->hint_lock); |