MCPcopy Create free account
hub / github.com/NthTensor/Forte / store_panic

Method store_panic

src/scope.rs:336–376  ·  view source on GitHub ↗
(&self, err: Box<dyn Any + Send + 'static>)

Source from the content-addressed store, hash-verified

334 fn add_reference(&self) {
335 self.count.fetch_add(1, Ordering::Relaxed);
336 }
337
338 /// Removes a reference from the scope's reference counter.
339 ///
340 /// # Safety
341 ///
342 /// The caller must be able to point to a corresponding place where the scope
343 /// counter was incremented by one. This could be through a call to
344 /// `add_reference`, a direct `fetch_add` on the underlying counter, or the
345 /// implicit initial increment the scope starts with.
346 unsafe fn remove_reference(&self) {
347 // This is `Release` so that this job's accesses to the scope are
348 // ordered before the decrement.
349 //
350 // The std-lib's `Arc` has the same basic pattern.
351 let counter = self.count.fetch_sub(1, Ordering::Release);
352 if counter == 1 {
353 // This is the final decrement.
354 //
355 // The `Acquire` fence synchronizes with the release sequence formed
356 // by every other job's `Release` decrement of `count`, so all of
357 // their accesses to the scope happen-before this point. Combined
358 // with the `Release`/`Acquire` handshake in
359 // `Latch::set`/`Latch::check`, this orders every job's use of the
360 // scope before the owner returns from `complete` and frees it.
361 // Without it, remote jobs' atomic ops on `count` (and their reads
362 // and writes of `panic`) would race the owner's deallocation.
363 fence(Ordering::Acquire);
364 // Alerts the owning thread that the scope has completed.
365 //
366 // This should never panic, because the counter can only go to zero
367 // once, when the scope has been dropped and all work has been
368 // completed.
369 //
370 // SAFETY: We meet Variant 2 of the `Latch::set` safety contract:
371 //
372 // * The count reaches zero exactly once, so this branch runs
373 // exactly once, and this is the only place the latch is set. So
374 // no other call to `set` can race with this one, and `set` cannot
375 // have already been called.
376 //
377 // * This latch will not be dropped until `complete` returns, and
378 // `complete` will not return until it observes the signal we are
379 // about to send.

Callers 4

with_scopeFunction · 0.80
spawn_broadcastMethod · 0.80
spawn_scopedMethod · 0.80
pollMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected