Skip to content

Commit

Permalink
Addressed reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulstrackx authored and Vasili Novikov committed Jan 4, 2024
1 parent 6d7aa48 commit 9017716
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 5 additions & 10 deletions intel-sgx/async-usercalls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,11 @@ impl CallbackHandler {
0 => return 0,
n => &returns[..n],
};
// 2. try to lock the mutex, if successful, receive all pending callbacks and put them in the hash map
let mut guard = match self.callbacks.try_lock() {
Ok(mut callbacks) => {
for (id, cb) in self.callback_rx.try_iter() {
callbacks.insert(id, cb);
}
callbacks
}
_ => self.callbacks.lock().unwrap(),
};
// 2. Receive all pending callbacks and put them in the hash map
let mut guard = self.callbacks.lock().unwrap();
for (id, cb) in self.callback_rx.try_iter() {
guard.insert(id, cb);
}
// 3. remove callbacks for returns received in step 1 from the hash map
let mut ret_callbacks = Vec::with_capacity(returns.len());
for ret in returns {
Expand Down
5 changes: 4 additions & 1 deletion intel-sgx/async-usercalls/src/queues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ mod map {
let id = self.next_id;
// We intentionally ignore the overflow here, thus allowing `next_id` to jump back to 0
// after `u32::MAX` number of insertions.
// TODO: We should have a way of limiting the size of this queue to avoid
// potentially checking 2^32 items and huge memory consumption
// https://github.com/fortanix/rust-sgx/issues/550
self.next_id = self.next_id.overflowing_add(1).0;
if !self.map.contains_key(&id) {
self.map.insert(id, value);
Expand All @@ -206,4 +209,4 @@ mod map {
self.map.remove(&id)
}
}
}
}

0 comments on commit 9017716

Please sign in to comment.