Make OnThread{Start,Stop} idempotent.

This allows multiple callers to call OnThread{Start,Stop} safely without coordination, which may be needed (or making things easier) on some platforms.

PiperOrigin-RevId: 985263765
diff --git a/centipede/sancov_state.cc b/centipede/sancov_state.cc
index 8adedee..abcaffe 100644
--- a/centipede/sancov_state.cc
+++ b/centipede/sancov_state.cc
@@ -121,6 +121,7 @@
 }
 
 void ThreadLocalSancovState::OnThreadStart() {
+  if (tls.started) return;
   termination_detector.EnsureAlive();
   tls.started = true;
   // Always trace threads by default. Internal threads that do not want tracing
@@ -145,6 +146,11 @@
 }
 
 void ThreadLocalSancovState::OnThreadStop() {
+  if (tls.sancov_lowest_sp == nullptr) {
+    // This can happen only before OnTheadStart() or after OnThreadStop() -
+    // nothing to do if that's the case.
+    return;
+  }
   tls.traced = false;
   LockGuard lock(sancov_state->tls_list_mu);
   const size_t sancov_lowest_sp = *tls.sancov_lowest_sp;