2 * Copyright 2017 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 * We keep all the pages in an AVL tree indexed by the offset. This
32 * allows us to do quick offset lookups.
34 * We also keep all the pages on a list, which we use during
42 struct vnode
*vnode
; /* the owner */
46 #define vmobject_add_page_head(o,p) list_insert_head(&(o)->list, (p))
47 #define vmobject_add_page_tail(o,p) list_insert_tail(&(o)->list, (p))
48 #define vmobject_remove_page(o,p) list_remove(&(o)->list, (p))
49 #define vmobject_get_head(o) list_head(&(o)->list)
50 #define vmobject_get_tail(o) list_tail(&(o)->list)
51 #define vmobject_get_prev(o,p) list_prev(&(o)->list, (p))
52 #define vmobject_get_next(o,p) list_next(&(o)->list, (p))
54 static inline struct page
*
55 vmobject_get_prev_loop(struct vmobject
*obj
, struct page
*page
)
59 p
= vmobject_get_prev(obj
, page
);
61 p
= vmobject_get_tail(obj
);
66 static inline struct page
*
67 vmobject_get_next_loop(struct vmobject
*obj
, struct page
*page
)
71 p
= vmobject_get_next(obj
, page
);
73 p
= vmobject_get_head(obj
);
79 vmobject_move_page_tail(struct vmobject
*obj
, struct page
*page
)
81 vmobject_remove_page(obj
, page
);
82 vmobject_add_page_tail(obj
, page
);
85 #define VMOBJECT_LOCKED(obj) MUTEX_HELD(&(obj)->lock)
88 vmobject_lock(struct vmobject
*obj
)
90 mutex_enter(&obj
->lock
);
94 vmobject_trylock(struct vmobject
*obj
)
96 return mutex_tryenter(&obj
->lock
);
100 vmobject_unlock(struct vmobject
*obj
)
102 mutex_exit(&obj
->lock
);
105 extern void vmobject_init(struct vmobject
*obj
, struct vnode
*vnode
);
106 extern void vmobject_fini(struct vmobject
*obj
);