Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
NiceMock for mocks whose behavior is not the focus of a test.
* There are probably a few other things missing from this list. We will add them as they
are brought to our attention.
* [Thread
annotations](https://github.com/abseil/abseil-cpp/blob/master/absl/base/thread_annotations.h),
such as `GUARDED_BY`, should be used for shared state guarded by
locks/mutexes.

# Error handling

Expand Down
6 changes: 6 additions & 0 deletions source/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ envoy_cc_library(
hdrs = ["stl_helpers.h"],
)

envoy_cc_library(
name = "thread_annotations",
hdrs = ["thread_annotations.h"],
external_deps = ["abseil_base"],
)

envoy_cc_library(
name = "thread_lib",
srcs = ["thread.cc"],
Expand Down
11 changes: 11 additions & 0 deletions source/common/common/thread_annotations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

// NOLINT(namespace-envoy)

#include "absl/base/thread_annotations.h"

#ifdef __APPLE__
#undef THREAD_ANNOTATION_ATTRIBUTE__
// See #2571, we get problematic warnings on Clang + OS X.
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
#endif
1 change: 1 addition & 0 deletions source/common/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ envoy_cc_library(
"//include/envoy/thread_local:thread_local_interface",
"//source/common/common:empty_string",
"//source/common/common:linked_object",
"//source/common/common:thread_annotations",
"//source/common/common:thread_lib",
"//source/common/tracing:http_tracer_lib",
],
Expand Down
4 changes: 3 additions & 1 deletion source/common/grpc/google_async_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "common/common/linked_object.h"
#include "common/common/thread.h"
#include "common/common/thread_annotations.h"
#include "common/tracing/http_tracer_impl.h"

#include "grpc++/generic/generic_stub.h"
Expand Down Expand Up @@ -289,7 +290,8 @@ class GoogleAsyncStreamImpl : public AsyncStream,
uint32_t inflight_tags_{};
// Queue of completed (op, ok) passed from completionThread() to
// handleOpCompletion().
std::deque<std::pair<GoogleAsyncTag::Operation, bool>> completed_ops_;
std::deque<std::pair<GoogleAsyncTag::Operation, bool>>
completed_ops_ GUARDED_BY(completed_ops_lock_);
std::mutex completed_ops_lock_;

friend class GoogleAsyncClientImpl;
Expand Down