MCPcopy Create free account
hub / github.com/angular/angular / with_buf

Method with_buf

packages/compiler-cli/preprocessor/ng-analyze/src/perf/layer.rs:388–401  ·  view source on GitHub ↗

Runs `f` on this thread's buffer. Only `take` contends for the lock.

(&self, f: impl FnOnce(&mut ThreadBuf))

Source from the content-addressed store, hash-verified

386
387 /// Runs `f` on this thread's buffer. Only `take` contends for the lock.
388 fn with_buf(&self, f: impl FnOnce(&mut ThreadBuf)) {
389 // `try_with`: spans may still close while thread-locals are being destroyed.
390 let _ = THREAD_BUF.try_with(|slot| {
391 let mut slot = slot.borrow_mut();
392 // The `Weak` keeps the allocation, so the address can't be reused by another layer.
393 if !matches!(&*slot, Some((state, _)) if state.as_ptr() == Arc::as_ptr(&self.0)) {
394 let buf = Arc::new(Mutex::new(self.new_thread_buf()));
395 self.0.threads.lock().unwrap().push(buf.clone());
396 *slot = Some((Arc::downgrade(&self.0), buf));
397 }
398 let (_, buf) = slot.as_ref().unwrap();
399 f(&mut buf.lock().unwrap());
400 });
401 }
402
403 fn new_thread_buf(&self) -> ThreadBuf {
404 let tid = match POOL_INDEX.with(Cell::get) {

Callers 6

countMethod · 0.80
count_cache_hitMethod · 0.80
on_new_spanMethod · 0.80
on_enterMethod · 0.80
on_exitMethod · 0.80
on_closeMethod · 0.80

Calls 5

new_thread_bufMethod · 0.80
as_refMethod · 0.80
unwrapMethod · 0.65
cloneMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected