lidavidm commented on a change in pull request #10968: URL: https://github.com/apache/arrow/pull/10968#discussion_r695032545
########## File path: cpp/src/arrow/util/async_nursery.h ########## @@ -0,0 +1,157 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef ARROW_ASYNC_NURSERY_H Review comment: nit: I think most other headers we have use `#pragma once` (though its not standard) ########## File path: cpp/src/arrow/util/async_nursery.cc ########## @@ -0,0 +1,130 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/util/async_nursery.h" + +#include "arrow/util/logging.h" + +namespace arrow { +namespace util { + +AsyncCloseable::AsyncCloseable() = default; +AsyncCloseable::AsyncCloseable(AsyncCloseable* parent) { + parent->AddDependentTask(OnClosed()); +} + +AsyncCloseable::~AsyncCloseable() { + // FIXME - Would be awesome if there were a way to enforce this at compile time + DCHECK_NE(nursery_, nullptr) << "An AsyncCloseable must be created with a nursery " + "using MakeSharedCloseable or MakeUniqueCloseable"; +} + +const Future<>& AsyncCloseable::OnClosed() { + // Lazily create the future to save effort if we don't need it + if (!on_closed_.is_valid()) { + on_closed_ = Future<>::Make(); + } Review comment: I'm a bit worried about this being race-prone. So far it looks like it's only used in the one constructor, perhaps it could be inlined there? ########## File path: cpp/src/arrow/util/async_nursery.h ########## @@ -0,0 +1,157 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef ARROW_ASYNC_NURSERY_H +#define ARROW_ASYNC_NURSERY_H + +#include <list> + +#include "arrow/result.h" +#include "arrow/status.h" +#include "arrow/util/future.h" +#include "arrow/util/mutex.h" + +namespace arrow { +namespace util { + +class Nursery; +class AsyncCloseablePimpl; + +template <typename T> +struct DestroyingDeleter { + void operator()(T* p) { p->Destroy(); } Review comment: Don't we still need to delete p? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
