Skip to content

Commit d913cbe

Browse files
committed
[CHORE] Shorten six comments to the voice of the surrounding file
Five blocks in http_operation_curl.cc and one in curl_http_test.cc stated the same invariants in more lines than the code they describe. They now name the function that holds each invariant and stop, which is what dbarker asked for on open-telemetry#4327 and what ThomsonTan asked for on open-telemetry#4618. No behaviour change: curl_http_test passes 46 of 46 and clang-format 18.1.8 is clean on both files. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
1 parent d1e3804 commit d913cbe

2 files changed

Lines changed: 15 additions & 31 deletions

File tree

‎ext/src/http/client/curl/http_operation_curl.cc‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,8 @@ int HttpOperation::OnProgressCallback(void *clientp,
401401
}
402402
#endif
403403

404-
// The atomic member is only free of layout cost while it stays the size and alignment of the
405-
// enum it replaced. The standard does not promise that, so it is checked here rather than
406-
// asserted in prose: a toolchain where it does not hold changes an installed type and should say
407-
// so at build time.
404+
// A toolchain where std::atomic<SessionState> is wider or more aligned than the enum would
405+
// change the layout of an installed type, so check it at build time rather than assume it.
408406
static_assert(sizeof(std::atomic<opentelemetry::ext::http::client::SessionState>) ==
409407
sizeof(opentelemetry::ext::http::client::SessionState),
410408
"std::atomic<SessionState> grew, which changes the layout of HttpOperation");
@@ -415,14 +413,10 @@ static_assert(
415413

416414
namespace
417415
{
418-
// Which operations the calling thread is currently inside a callback for. A handler is allowed to
419-
// call FinishSession() on the request it is being told about, and that call must not wait for a
420-
// completion only the thread it is running on can publish.
421-
// A stack of scopes linked through the scopes themselves, so entering one allocates nothing. Each
422-
// lives on the stack frame that dispatches the callback, which is exactly as long as the entry
423-
// needs to be there. A container here would put a heap allocation on every event, and would put
424-
// it inside a noexcept constructor, where running out of memory calls std::terminate rather than
425-
// reaching whoever asked for the request.
416+
// The operations this thread is inside a callback for. A handler may call FinishSession() on the
417+
// request it is being told about, and that must not wait for a completion only this thread
418+
// publishes. An intrusive stack rather than a container: entering allocates nothing, which a
419+
// noexcept constructor needs, since a failed allocation there would call std::terminate.
426420
class CallbackScope
427421
{
428422
public:
@@ -544,9 +538,8 @@ HttpOperation::~HttpOperation()
544538
case opentelemetry::ext::http::client::SessionState::Connecting:
545539
case opentelemetry::ext::http::client::SessionState::Connected:
546540
case opentelemetry::ext::http::client::SessionState::Sending: {
547-
// Not while inside a callback this operation dispatched: a handler that destroys the
548-
// operation it is being told about would be waiting for a completion that only the thread
549-
// running the handler can publish.
541+
// Not inside a callback this operation dispatched: the handler's own thread is the one
542+
// that publishes the completion it would wait for.
550543
if (async_data_ && async_data_->result_future.valid() &&
551544
!CallbackScope::InsideCallbackFor(this))
552545
{
@@ -1546,10 +1539,8 @@ CURLcode HttpOperation::SendAsync(Session *session, std::function<void(HttpOpera
15461539
async_data_->result_future = async_data_->result_promise.get_future();
15471540
async_data_->is_promise_running.store(true, std::memory_order_release);
15481541

1549-
// Last, and the only thing that makes this operation reachable from the IO thread: an abort is
1550-
// queued through this route, so nothing can bring the operation there before the callback and
1551-
// the completion above exist. Cleanup is therefore the only thing that ever fulfils the promise,
1552-
// at its tail, once the terminal event and the completion callback have run.
1542+
// Last: this store is what makes the operation reachable from the IO thread, so the callback
1543+
// and the promise above are published first. Cleanup() fulfils the promise, at its tail.
15531544
async_data_->session.store(session, std::memory_order_release);
15541545

15551546
DispatchEvent(opentelemetry::ext::http::client::SessionState::Connecting);
@@ -1625,15 +1616,9 @@ void HttpOperation::Abort()
16251616

16261617
void HttpOperation::FinishUnscheduled(const char *reason)
16271618
{
1628-
// The event first, because the operation holds the handler as a bare pointer and the only
1629-
// strong reference to it is the one the completion callback captured. Cleanup() takes that
1630-
// callback and lets it go, so an event dispatched afterwards can be talking to a handler
1631-
// nothing owns any more. A handler calling FinishSession() from here is inside a callback for
1632-
// this operation, so Finish() returns rather than waiting on a promise this thread has not
1633-
// published yet, which is what used to make the other order necessary.
1634-
//
1635-
// DispatchEvent stores the state before it calls the handler, so the cleanup below sees a
1636-
// terminal state and does not report a manual cancel for something nobody cancelled.
1619+
// Before Cleanup(), which releases the completion callback holding the only strong reference
1620+
// to the handler. DispatchEvent stores the terminal state first, so the Cleanup() below does
1621+
// not report a cancel as well.
16371622
DispatchEvent(opentelemetry::ext::http::client::SessionState::CreateFailed,
16381623
nullptr != reason ? reason : "");
16391624

‎ext/test/http/curl_http_test.cc‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,8 @@ bool WaitFor(Predicate ready, std::chrono::milliseconds budget)
17221722
}
17231723
} // namespace
17241724

1725-
// A handler is allowed to finish the request it is being told about. On the IO thread's events
1726-
// that used to be a deadlock, because Finish() waited on a promise only the thread running the
1727-
// handler goes on to fulfil. Fixes #4402.
1725+
// A handler may finish the request it is being told about, including on an IO thread event,
1726+
// where Finish() must not wait on a promise only this thread will fulfil. Fixes #4402.
17281727
TEST_F(BasicCurlHttpTests, FinishSessionFromAnEventTheIoThreadDelivers)
17291728
{
17301729
auto session_manager = std::make_shared<http_client::curl::HttpCurlClientFactory>()->Create();

0 commit comments

Comments
 (0)