kou commented on code in PR #48462:
URL: https://github.com/apache/arrow/pull/48462#discussion_r2616661957
##########
c_glib/arrow-glib/thread-pool.cpp:
##########
Review Comment:
Could you rename to `executer.{cpp,h,hpp}`?
`ThreadPool` is one of executors.
##########
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:
We should pass `arrow::internal::ThraedPool` as property instead of setting
directly via `priv` like we did in `GArrowArray`:
```suggestion
auto arrow_thread_pool = *arrow_thread_pool_result;
auto thread_pool =
GARROW_THREAD_POOL(g_object_new(GARROW_TYPE_THREAD_POOL, "thread-pool",
*arrow_thread_pool, nullptr));
```
If you don't know how to do it, can I push some commits to this branch?
##########
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);
Review Comment:
```suggestion
auto arrow_thread_pool_result =
arrow::internal::ThreadPool::Make(n_threads);
```
##########
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)
Review Comment:
```suggestion
garrow_thread_pool_new(guint n_threads, GError **error)
```
##########
c_glib/arrow-glib/compute.cpp:
##########
@@ -327,15 +313,23 @@
garrow_execute_context_class_init(GArrowExecuteContextClass *klass)
/**
* garrow_execute_context_new:
+ * @thread_pool: (nullable): A #GArrowThreadPool or %NULL.
*
* Returns: A newly created #GArrowExecuteContext.
*
* Since: 1.0.0
*/
GArrowExecuteContext *
-garrow_execute_context_new(void)
+garrow_execute_context_new(GArrowThreadPool *thread_pool)
{
auto execute_context = g_object_new(GARROW_TYPE_EXECUTE_CONTEXT, NULL);
+ auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(execute_context);
+
+ auto arrow_thread_pool = garrow_thread_pool_get_raw(thread_pool);
+ priv->thread_pool = arrow_thread_pool;
Review Comment:
We should set `thread_pool` as property.
##########
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.
Review Comment:
GLib uses `n_XXX` style:
```suggestion
* @n_threads: The number of threads in the pool.
```
##########
c_glib/arrow-glib/compute.cpp:
##########
@@ -327,15 +313,23 @@
garrow_execute_context_class_init(GArrowExecuteContextClass *klass)
/**
* garrow_execute_context_new:
+ * @thread_pool: (nullable): A #GArrowThreadPool or %NULL.
*
* Returns: A newly created #GArrowExecuteContext.
*
* Since: 1.0.0
*/
GArrowExecuteContext *
-garrow_execute_context_new(void)
+garrow_execute_context_new(GArrowThreadPool *thread_pool)
{
auto execute_context = g_object_new(GARROW_TYPE_EXECUTE_CONTEXT, NULL);
+ auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(execute_context);
+
+ auto arrow_thread_pool = garrow_thread_pool_get_raw(thread_pool);
+ priv->thread_pool = arrow_thread_pool;
+ new (&priv->context)
+ arrow::compute::ExecContext(arrow::default_memory_pool(),
arrow_thread_pool.get());
Review Comment:
We should not use placement new here. We should do the following in
`_set_property()`:
```cpp
priv->context = arrow::compute::ExecContext(...);
```
--
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]