kou commented on code in PR #48462: URL: https://github.com/apache/arrow/pull/48462#discussion_r2616826938
########## c_glib/arrow-glib/thread-pool.cpp: ########## @@ -0,0 +1,102 @@ +/* + * 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-glib/thread-pool.hpp> +#include <arrow-glib/error.hpp> + +G_BEGIN_DECLS + +/** + * SECTION: thread-pool + * @section_id: thread-pool-classes + * @title: Thread pool classes + * @include: arrow-glib/arrow-glib.h + * + * #GArrowThreadPool is a class for thread pool management. + */ + +typedef struct GArrowThreadPoolPrivate_ +{ + std::shared_ptr<arrow::internal::ThreadPool> thread_pool; +} GArrowThreadPoolPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE(GArrowThreadPool, garrow_thread_pool, G_TYPE_OBJECT) + +#define GARROW_THREAD_POOL_GET_PRIVATE(obj) \ + static_cast<GArrowThreadPoolPrivate *>( \ + garrow_thread_pool_get_instance_private(GARROW_THREAD_POOL(obj))) + +static void +garrow_thread_pool_finalize(GObject *object) +{ + auto priv = GARROW_THREAD_POOL_GET_PRIVATE(object); + priv->thread_pool.~shared_ptr(); + G_OBJECT_CLASS(garrow_thread_pool_parent_class)->finalize(object); +} + +static void +garrow_thread_pool_init(GArrowThreadPool *object) +{ + auto priv = GARROW_THREAD_POOL_GET_PRIVATE(object); + new (&priv->thread_pool) std::shared_ptr<arrow::internal::ThreadPool>; +} + +static void +garrow_thread_pool_class_init(GArrowThreadPoolClass *klass) +{ + auto gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->finalize = garrow_thread_pool_finalize; +} + +/** + * garrow_thread_pool_new: + * @num_threads: The number of threads in the pool. + * @error: (nullable): Return location for a #GError or %NULL. + * + * Returns: (nullable): A newly created #GArrowThreadPool on success, + * %NULL on error. + * + * Since: 23.0.0 + */ +GArrowThreadPool * +garrow_thread_pool_new(guint num_threads, GError **error) +{ + auto arrow_thread_pool_result = arrow::internal::ThreadPool::Make(num_threads); + if (garrow::check(error, arrow_thread_pool_result, "[thread-pool][new]")) { + auto thread_pool = GARROW_THREAD_POOL(g_object_new(GARROW_TYPE_THREAD_POOL, NULL)); + auto priv = GARROW_THREAD_POOL_GET_PRIVATE(thread_pool); + priv->thread_pool = *arrow_thread_pool_result; Review Comment: It's for sub class. If we do it in constructor, sub class needs to re-implement it in sub class' constructor. If we do it in property setter, sub class can reuse it. > For example the property `memory-pool` appears in the documentation, which I find confusing: https://arrow.apache.org/docs/c_glib/arrow-glib/property.MemoryPool.memory-pool.html We need the documentation for it. It should say that this is for advanced users who use C++/GLib/sub class/.... -- 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]
