Primiano Tucci | 9564d91 | 2019-05-21 23:53:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Primiano Tucci | 2c5488f | 2019-06-01 03:27:28 +0100 | [diff] [blame] | 17 | #include "perfetto/tracing/internal/tracing_tls.h" |
| 18 | #include "perfetto/tracing/tracing.h" |
| 19 | #include "perfetto/tracing/tracing_backend.h" |
Primiano Tucci | 9564d91 | 2019-05-21 23:53:18 +0100 | [diff] [blame] | 20 | |
| 21 | // This translation unit contains the definitions for the destructor of pure |
| 22 | // virtual interfaces for the src/public:public target. The alternative would be |
| 23 | // introducing a one-liner .cc file for each pure virtual interface, which is |
| 24 | // overkill. This is for compliance with -Wweak-vtables. |
| 25 | |
| 26 | namespace perfetto { |
| 27 | namespace internal { |
| 28 | |
Sami Kyostila | 2d79020 | 2021-05-08 01:47:55 +0000 | [diff] [blame] | 29 | TracingTLS::~TracingTLS() { |
| 30 | // Avoid entering trace points while the thread is being torn down. |
Primiano Tucci | ad111e4 | 2021-05-19 21:34:12 +0100 | [diff] [blame] | 31 | // This is the problem: when a thread exits, the at-thread-exit destroys the |
| 32 | // TracingTLS. As part of that the various TraceWriter for the active data |
| 33 | // sources are destroyd. A TraceWriter dtor will issue a PostTask on the IPC |
| 34 | // thread to issue a final flush and unregister its ID with the service. |
| 35 | // The PostTask, in chromium, might have a trace event that will try to |
| 36 | // re-enter the tracing system. |
| 37 | // We fix this by resetting the TLS key to the TracingTLS object that is |
| 38 | // being destroyed in the platform impl (platform_posix.cc, |
| 39 | // platform_windows.cc, chromium's platform.cc). We carefully rely on the fact |
| 40 | // that all the tracing path that will be invoked during thread exit will |
| 41 | // early out if |is_in_trace_point| == true and will not depend on the other |
| 42 | // TLS state that has been destroyed. |
Sami Kyostila | 2d79020 | 2021-05-08 01:47:55 +0000 | [diff] [blame] | 43 | is_in_trace_point = true; |
| 44 | } |
Primiano Tucci | 9564d91 | 2019-05-21 23:53:18 +0100 | [diff] [blame] | 45 | |
| 46 | } // namespace internal |
| 47 | |
Daniele Di Proietto | 3faa5fd | 2023-02-16 17:36:01 +0000 | [diff] [blame] | 48 | TracingProducerBackend::~TracingProducerBackend() = default; |
| 49 | TracingConsumerBackend::~TracingConsumerBackend() = default; |
Primiano Tucci | 9564d91 | 2019-05-21 23:53:18 +0100 | [diff] [blame] | 50 | TracingBackend::~TracingBackend() = default; |
Primiano Tucci | 9564d91 | 2019-05-21 23:53:18 +0100 | [diff] [blame] | 51 | |
| 52 | } // namespace perfetto |