Unverified Commit 48a01714 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Preserve canary task-entry semantics with intrusive locks

Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 6728df44
...@@ -526,9 +526,7 @@ impl Storage { ...@@ -526,9 +526,7 @@ impl Storage {
pub fn access_entry_mut(&self, key: TaskId) -> TaskEntryGuard<'_> { pub fn access_entry_mut(&self, key: TaskId) -> TaskEntryGuard<'_> {
let entry = match self.map.entry(key) { let entry = match self.map.entry(key) {
dashmap::mapref::entry::Entry::Occupied(e) => e, dashmap::mapref::entry::Entry::Occupied(e) => e,
dashmap::mapref::entry::Entry::Vacant(e) => { dashmap::mapref::entry::Entry::Vacant(e) => e.insert_entry(Box::new(TaskSlot::new())),
e.insert_entry(Box::new(TaskStorage::new()))
}
}; };
TaskEntryGuard { TaskEntryGuard {
storage: self, storage: self,
...@@ -579,7 +577,7 @@ impl Storage { ...@@ -579,7 +577,7 @@ impl Storage {
let mut roots = Vec::new(); let mut roots = Vec::new();
let shard = self.map.shards()[index].read(); let shard = self.map.shards()[index].read();
for (task_id, task) in shard.iter() { for (task_id, task) in shard.iter() {
if !task_id.is_transient() && task.gc_is_root() { if !task_id.is_transient() && task.with_lock(TaskStorage::gc_is_root) {
roots.push(*task_id); roots.push(*task_id);
} }
} }
...@@ -793,7 +791,7 @@ impl Storage { ...@@ -793,7 +791,7 @@ impl Storage {
/// removal is no longer a possibility, or call [`Self::discard`] to drop the entry outright. /// removal is no longer a possibility, or call [`Self::discard`] to drop the entry outright.
pub struct TaskEntryGuard<'a> { pub struct TaskEntryGuard<'a> {
storage: &'a Storage, storage: &'a Storage,
entry: dashmap::mapref::entry::OccupiedEntry<'a, TaskId, Box<TaskStorage>>, entry: dashmap::mapref::entry::OccupiedEntry<'a, TaskId, Box<TaskSlot>>,
} }
impl<'a> TaskEntryGuard<'a> { impl<'a> TaskEntryGuard<'a> {
...@@ -804,23 +802,22 @@ impl<'a> TaskEntryGuard<'a> { ...@@ -804,23 +802,22 @@ impl<'a> TaskEntryGuard<'a> {
/// Gives up the ability to remove the entry, yielding an ordinary write guard. /// Gives up the ability to remove the entry, yielding an ordinary write guard.
pub fn into_write_guard(self) -> StorageWriteGuard<'a> { pub fn into_write_guard(self) -> StorageWriteGuard<'a> {
StorageWriteGuard { StorageWriteGuard::new(self.storage, self.entry.into_ref().downgrade().into())
storage: self.storage,
inner: self.entry.into_ref().into(),
}
} }
} }
impl Deref for TaskEntryGuard<'_> { impl Deref for TaskEntryGuard<'_> {
type Target = TaskStorage; type Target = TaskStorage;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.entry.get() // SAFETY: the entry guard holds the shard write lock, so no other task guard can access
// this slot while it is borrowed here.
unsafe { self.entry.get().get() }
} }
} }
impl DerefMut for TaskEntryGuard<'_> { impl DerefMut for TaskEntryGuard<'_> {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
self.entry.get_mut() self.entry.get_mut().get_mut_exclusive()
} }
} }
......
...@@ -127,7 +127,8 @@ impl TaskSlot { ...@@ -127,7 +127,8 @@ impl TaskSlot {
} }
/// # Safety /// # Safety
/// The caller must own this slot's task lock. /// The caller must own this slot's task lock, or hold an exclusive shard write guard that
/// prevents every concurrent access to this slot.
pub(crate) unsafe fn get(&self) -> &TaskStorage { pub(crate) unsafe fn get(&self) -> &TaskStorage {
// SAFETY: Forwarded from the caller. // SAFETY: Forwarded from the caller.
unsafe { &*self.as_ptr() } unsafe { &*self.as_ptr() }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment