Switch Context::grants to RwLock
This commit is contained in:
@@ -74,7 +74,7 @@ pub fn inner_physmap(physical_address: usize, size: usize, flags: PhysmapFlags)
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
|
||||
let mut grants = context.grants.lock();
|
||||
let mut grants = context.grants.write();
|
||||
|
||||
let from_address = (physical_address/4096) * 4096;
|
||||
let offset = physical_address - from_address;
|
||||
@@ -128,7 +128,7 @@ pub fn inner_physunmap(virtual_address: usize) -> Result<usize> {
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
|
||||
let mut grants = context.grants.lock();
|
||||
let mut grants = context.grants.write();
|
||||
|
||||
if let Some(region) = grants.contains(VirtualAddress::new(virtual_address)).map(Region::from) {
|
||||
grants.take(®ion).unwrap().unmap();
|
||||
|
||||
+2
-2
@@ -455,7 +455,7 @@ pub fn funmap_old(virtual_address: usize) -> Result<usize> {
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
|
||||
let mut grants = context.grants.lock();
|
||||
let mut grants = context.grants.write();
|
||||
|
||||
if let Some(region) = grants.contains(VirtualAddress::new(virtual_address)).map(Region::from) {
|
||||
let mut grant = grants.take(®ion).unwrap();
|
||||
@@ -503,7 +503,7 @@ pub fn funmap(virtual_address: usize, length: usize) -> Result<usize> {
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
|
||||
let mut grants = context.grants.lock();
|
||||
let mut grants = context.grants.write();
|
||||
|
||||
let conflicting: Vec<Region> = grants.conflicts(requested).map(Region::from).collect();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use alloc::{
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ops::DerefMut;
|
||||
use core::{intrinsics, mem};
|
||||
use spin::{RwLock, Mutex};
|
||||
use spin::RwLock;
|
||||
|
||||
use crate::context::file::FileDescriptor;
|
||||
use crate::context::{ContextId, WaitpidKey};
|
||||
@@ -224,11 +224,11 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
grants = Arc::clone(&context.grants);
|
||||
} else {
|
||||
let mut grants_set = UserGrants::default();
|
||||
for grant in context.grants.lock().iter() {
|
||||
for grant in context.grants.read().iter() {
|
||||
let start = VirtualAddress::new(grant.start_address().data() + crate::USER_TMP_GRANT_OFFSET - crate::USER_GRANT_OFFSET);
|
||||
grants_set.insert(grant.secret_clone(start));
|
||||
}
|
||||
grants = Arc::new(Mutex::new(grants_set));
|
||||
grants = Arc::new(RwLock::new(grants_set));
|
||||
}
|
||||
|
||||
if flags.contains(CLONE_VM) {
|
||||
@@ -275,7 +275,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
|
||||
// If not cloning virtual memory, use fmap to re-obtain every grant where possible
|
||||
if !flags.contains(CLONE_VM) {
|
||||
let mut grants = grants.lock();
|
||||
let mut grants = grants.write();
|
||||
|
||||
let mut to_remove = BTreeSet::new();
|
||||
|
||||
@@ -395,7 +395,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
context.image = image;
|
||||
|
||||
// Copy grant mapping
|
||||
if ! grants.lock().is_empty() {
|
||||
if ! grants.read().is_empty() {
|
||||
let frame = active_table.p4()[crate::USER_GRANT_PML4].pointed_frame().expect("user grants not mapped");
|
||||
let flags = active_table.p4()[crate::USER_GRANT_PML4].flags();
|
||||
active_table.with(&mut new_table, &mut temporary_page, |mapper| {
|
||||
@@ -441,7 +441,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
|
||||
// Move grants
|
||||
{
|
||||
let mut grants = grants.lock();
|
||||
let mut grants = grants.write();
|
||||
let old_grants = mem::replace(&mut *grants, UserGrants::default());
|
||||
|
||||
for mut grant in old_grants.inner.into_iter() {
|
||||
@@ -558,7 +558,7 @@ fn empty(context: &mut context::Context, reaping: bool) {
|
||||
drop(context.tls.take());
|
||||
}
|
||||
|
||||
let mut grants = context.grants.lock();
|
||||
let mut grants = context.grants.write();
|
||||
if Arc::strong_count(&context.grants) == 1 {
|
||||
let grants = mem::replace(&mut *grants, UserGrants::default());
|
||||
for grant in grants.inner.into_iter() {
|
||||
|
||||
Reference in New Issue
Block a user