diff options
author | Michael I. Bushnell <mib@gnu.org> | 1994-01-13 20:44:45 +0000 |
---|---|---|
committer | Michael I. Bushnell <mib@gnu.org> | 1994-01-13 20:44:45 +0000 |
commit | d68074b8c460de31fae524b67ff4c19e8e56fc2e (patch) | |
tree | 565c8fa4501dbd6fec2603c1347356f757e6932f /libpager | |
parent | cb92810bfd089c5fbac854b1495c035c7dfd2107 (diff) |
Initial revision
Diffstat (limited to 'libpager')
-rw-r--r-- | libpager/lock-completed.c | 59 | ||||
-rw-r--r-- | libpager/lock-object.c | 82 | ||||
-rw-r--r-- | libpager/object-init.c | 62 |
3 files changed, 203 insertions, 0 deletions
diff --git a/libpager/lock-completed.c b/libpager/lock-completed.c new file mode 100644 index 00000000..de99bf6f --- /dev/null +++ b/libpager/lock-completed.c @@ -0,0 +1,59 @@ +/* Implementation of memory_object_lock_completed for pager library + Copyright (C) 1994 Free Software Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +/* A lock_request has finished. Do our part of the wakeup + process. */ +seqnos_memory_object_lock_completed (mach_port_t object, + mach_port_seqno_t seqno, + mach_port_t control, + vm_offset_t offset, + vm_size_t length) +{ + struct controlinfo *ci; + struct lock_request *lr; + int wakeup; + + if (!(ci = check_port_type (object, pager_port_type))) + { + printf ("Bad lock completed\n"); + return EOPNOTSUPP; + } + + if (control != ci->memobjcntl) + { + printf ("lock_completed: bad control port\n"); + return EPERM; + } + + mach_port_deallocate (mach_task_self (), control); + + mutex_lock (&ci->interlock); + _pager_wait_for_seqno (ci, seqno); + + wakeup = 0; + for (lr = ci->lock_requests; lr; lr = lr->next) + if (lr->start == offset && lr->end == offset + length + && !--lr->locks_pending && !lr->pending_writes) + wakeup = 1; + condition_broadcast (&ci->wakeup); + + _pager_release_seqno (ci); + mutex_unlock (&ci->interlock); + + return 0; +} diff --git a/libpager/lock-object.c b/libpager/lock-object.c new file mode 100644 index 00000000..c00f5170 --- /dev/null +++ b/libpager/lock-object.c @@ -0,0 +1,82 @@ +/* Synchronous wrapper for memory_object_lock_request + Copyright (C) 1993, 1994 Free Software Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +/* Request a lock from the kernel. Parameters are as for + memory_object_lock_request. If SYNC is set, then wait for + the operation to fully complete before returning. */ +void +lock_object (struct pager *p, + vm_offset_t offset, + vm_size_t size, + int should_return, + int should_flush, + vm_prot_t lock_value, + int sync) +{ + struct lock_request *lr = 0; + + mutex_lock (&p->interlock); + if (p->pager_state != NORMAL) + { + mutex_unlock (&p->interlock); + return; + } + + if (sync) + { + for (lr = p->lock_requests; lr; lr = lr->next) + if (lr->start == offset && lr->end == offset + size) + { + lr->locks_pending++; + lr->threads_waiting++; + break; + } + if (!lr) + { + lr = malloc (sizeof (struct lock_request)); + lr->start = offset; + lr->end = offset + size; + lr->pending_writes = 0; + lr->locks_pending = 1; + lr->threads_waiting = 1; + lr->next = p->lock_requests; + if (lr->next) + lr->next->prevp = &lr->next; + lr->prevp = &p->lock_requests; + p->lock_requests = lr; + } + } + + memory_object_lock_request (p->memobjcntl, offset, size, should_return, + should_flush, lock_value, + sync ? p->port.port : MACH_PORT_NULL); + + if (sync) + { + while (lr->locks_pending || lr->pending_writes) + condition_wait (&p->wakeup, &p->interlock); + + if (!--lr->threads_waiting) + { + *lr->prevp = lr->next; + free (lr); + } + } + + mutex_unlock (&p->interlock); +} diff --git a/libpager/object-init.c b/libpager/object-init.c new file mode 100644 index 00000000..7cea9721 --- /dev/null +++ b/libpager/object-init.c @@ -0,0 +1,62 @@ +/* Implementation of memory_object_init for pager library + Copyright (C) 1994 Free Software Foundation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This is called by a kernel to initialize the memory object; + this routine is a dual of seqnos_memory_object_terminate. */ +kern_return_t +seqnos_memory_object_init (mach_port_t object, + mach_port_seqno_t seqno, + mach_port_t control, + mach_port_t name, + vm_size_t pagesize) +{ + struct pager *p; + + if (!(p = check_port_type (object, pager_port_type))) + return EOPNOTSUPP; + + mutex_lock (&p->interlock); + + if (p->pager_state != NOTINIT) + { + printf ("pager dup init"); + goto out; + } + if (pagesize != __vm_page_size) + { + printf ("incg init: bad page size"); + goto out; + } + + _pager_wait_for_seqno (p, seqno); + + p->memobjcntl = control; + p->memobjname = name; + if (p->pagemap || p->pagemapsize) + panic ("pagemap failure"); + + /* Tell the kernel we're ready */ + /* XXX Don't cache for now. */ + memory_object_ready (control, 0, MEMORY_OBJECT_COPY_NONE); + + p->pager_state = NORMAL; + mutex_unlock (&p->interlock); + + out: + _pager_done_with_port (p); + return 0; +} |