blob: d8dfbac106e3fcf51300fc05dc806179b04c2f5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "quiche/quic/core/quic_connection_context.h"
#include "quiche/common/platform/api/quiche_thread_local.h"
namespace quic {
namespace {
DEFINE_QUICHE_THREAD_LOCAL_POINTER(CurrentContext, QuicConnectionContext);
} // namespace
// static
QuicConnectionContext* QuicConnectionContext::Current() {
return GET_QUICHE_THREAD_LOCAL_POINTER(CurrentContext);
}
QuicConnectionContextSwitcher::QuicConnectionContextSwitcher(
QuicConnectionContext* new_context)
: old_context_(QuicConnectionContext::Current()) {
SET_QUICHE_THREAD_LOCAL_POINTER(CurrentContext, new_context);
if (new_context && new_context->tracer) {
new_context->tracer->Activate();
}
}
QuicConnectionContextSwitcher::~QuicConnectionContextSwitcher() {
QuicConnectionContext* current = QuicConnectionContext::Current();
if (current && current->tracer) {
current->tracer->Deactivate();
}
SET_QUICHE_THREAD_LOCAL_POINTER(CurrentContext, old_context_);
}
} // namespace quic
|