-
Notifications
You must be signed in to change notification settings - Fork 73
Conversation
Context holds information specific to an operation, such as a TagMap and Span. Each thread has a currently active Context. Contexts are conceptually immutable: the contents of a Context cannot be modified in-place.
opencensus::context::WithContext wc(std::move(ctx)); | ||
} | ||
|
||
#if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment why 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
opencensus/context/context.h
Outdated
class Context { | ||
public: | ||
// Creates a default Context. | ||
Context(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need this public? Please make it private until we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
// WithContext is an RAII object, only ever stack-allocate it. While it's in | ||
// scope, the execution will happen under a copy of the given Context. | ||
class WithContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need a version of this that accepts a boolean condition to avoid duplicate code:
if (condition) {
WithContext wc(ctx);
... // code
} else {
... // same code
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #202
WithContext& operator=(const WithContext&) = delete; | ||
WithContext& operator=(WithContext&&) = delete; | ||
|
||
Context swapped_context_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on some experience that I have from dealing with other context implementation it is better if we have a way to check that objects are allocated and deallocated on the same thread. I suggest to put this check under the NDEBUG macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #203
Remove guard macro and NC tests that checked for it.
|
||
// Shared pointer to the underlying Span representation. This is nullptr for | ||
// Spans which are not recording events. This is an implementation detail, not | ||
// part of the public API. | ||
const std::shared_ptr<SpanImpl> span_impl_; | ||
std::shared_ptr<SpanImpl> span_impl_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made the shared_ptr non-const (and also the SpanContext above) so that we can use swap()
(L170) and operator=
(#191) to modify a Span object in-place, so that Context can have a Span member (as opposed to pointer to Span).
Also in (#191) we marked all Span methods const because:
- They don't act on the shared_ptr, they act on the pointee.
- In future we can replace the shared_ptr with something like opencensus-java's approach.
Context holds information specific to an operation, such as a TagMap and
Span. Each thread has a currently active Context. Contexts are conceptually
immutable: the contents of a Context cannot be modified in-place.