]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/safepoints.cpp
audio.engine.test: cleanup using
[factor.git] / vm / safepoints.cpp
index 180074a2d44f673640d58ab65d900be147a4fda6..c23baf3f30b6c5904156034fadd6802d22943202 100644 (file)
@@ -15,27 +15,27 @@ void factor_vm::enqueue_samples(cell samples,
 
   if (!atomic::load(&sampling_profiler_p))
     return;
-  atomic::fetch_add(&sample_counts.sample_count, samples);
+  atomic::fetch_add(&current_sample.sample_count, samples);
 
   if (foreign_thread_p)
-    atomic::fetch_add(&sample_counts.foreign_thread_sample_count, samples);
+    atomic::fetch_add(&current_sample.foreign_thread_sample_count, samples);
   else {
     if (atomic::load(&current_gc_p))
-      atomic::fetch_add(&sample_counts.gc_sample_count, samples);
+      atomic::fetch_add(&current_sample.gc_sample_count, samples);
     if (atomic::load(&current_jit_count) > 0)
-      atomic::fetch_add(&sample_counts.jit_sample_count, samples);
+      atomic::fetch_add(&current_sample.jit_sample_count, samples);
     if (!code->seg->in_segment_p(pc))
-      atomic::fetch_add(&sample_counts.foreign_sample_count, samples);
+      atomic::fetch_add(&current_sample.foreign_sample_count, samples);
   }
   code->set_safepoint_guard(true);
 }
 
+// Allocates memory (record_sample)
 void factor_vm::handle_safepoint(cell pc) {
   code->set_safepoint_guard(false);
   faulting_p = false;
 
   if (atomic::load(&safepoint_fep_p)) {
-    atomic::store(&safepoint_fep_p, false);
     if (atomic::load(&sampling_profiler_p))
       end_sampling_profiler();
     std::cout << "Interrupted\n";
@@ -43,10 +43,12 @@ void factor_vm::handle_safepoint(cell pc) {
       /* Ctrl-Break throws an exception, interrupting the main thread, same
          as the "t" command in the factorbug debugger. But for Ctrl-Break to
          work we don't require the debugger to be activated, or even enabled. */
+      atomic::store(&safepoint_fep_p, false);
       general_error(ERROR_INTERRUPT, false_object, false_object);
       FACTOR_ASSERT(false);
     }
     factorbug();
+    atomic::store(&safepoint_fep_p, false);
   } else if (atomic::load(&sampling_profiler_p)) {
     FACTOR_ASSERT(code->seg->in_segment_p(pc));
     code_block* block = code->code_block_for_address(pc);