Repository navigation
GH-41364: [GLib][Ruby] Allow passing thread pool to ExecutePlan #48462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d5947bb
Add GArrowThreadPool
stenlarsson b3f3ece
Add thread_pool argument to garrow_execute_context_new
stenlarsson 3bb6dad
Add context argument to garrow_execute_plan_new
stenlarsson 240ca70
Rename num_threads n_threads
stenlarsson d5e2612
Pass arrow::internal::ThraedPool as property instead of setting direc…
stenlarsson 902e004
Rename thread-pool.{cpp,h,hpp} to executor.{cpp,h,hpp}
stenlarsson 8766577
Set thread_pool as a property on ExecuteContext
stenlarsson 39e45e2
Use GArrowThreadPool instead of std::shared_ptr<arrow::internal::Thre…
stenlarsson 3846256
Add Executor base class and accept that in ExecuteContext
stenlarsson 1995746
Use std::shared_ptr<arrow::compute::ExecContext> to avoid needless co…
stenlarsson c743876
Fix shared pointer dereference
stenlarsson 9c744fe
Prevent instantiation of Executor base class
stenlarsson de46365
Store shared ptr to thread pool in base class
stenlarsson 75fd0bc
Keep reference to exectuor in execute context to prevent GC
stenlarsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * 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/error.hpp> | ||
| #include <arrow-glib/executor.hpp> | ||
|
|
||
| #include <arrow/util/thread_pool.h> | ||
|
|
||
| G_BEGIN_DECLS | ||
|
|
||
| /** | ||
| * SECTION: executor | ||
| * @section_id: executor-classes | ||
| * @title: Executor classes | ||
| * @include: arrow-glib/arrow-glib.h | ||
| * | ||
| * #GArrowExecutor is the base class for executor implementations. | ||
|
stenlarsson marked this conversation as resolved.
Resolved
|
||
| * | ||
| * #GArrowThreadPool is a class for thread pool management. | ||
| */ | ||
|
|
||
| struct GArrowExecutorPrivate | ||
| { | ||
| std::shared_ptr<arrow::internal::Executor> executor; | ||
| }; | ||
|
|
||
| G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT) | ||
|
|
||
| #define GARROW_EXECUTOR_GET_PRIVATE(obj) \ | ||
| static_cast<GArrowExecutorPrivate *>( \ | ||
| garrow_executor_get_instance_private(GARROW_EXECUTOR(obj))) | ||
|
|
||
| enum { | ||
| PROP_EXECUTOR = 1, | ||
| }; | ||
|
|
||
| static void | ||
| garrow_executor_init(GArrowExecutor *object) | ||
| { | ||
| auto priv = GARROW_EXECUTOR_GET_PRIVATE(object); | ||
| new (&priv->executor) std::shared_ptr<arrow::internal::Executor>; | ||
| } | ||
|
|
||
| static void | ||
| garrow_executor_finalize(GObject *object) | ||
| { | ||
| auto priv = GARROW_EXECUTOR_GET_PRIVATE(object); | ||
| priv->executor.~shared_ptr(); | ||
| G_OBJECT_CLASS(garrow_executor_parent_class)->finalize(object); | ||
| } | ||
|
|
||
| static void | ||
| garrow_executor_set_property(GObject *object, | ||
| guint prop_id, | ||
| const GValue *value, | ||
| GParamSpec *pspec) | ||
| { | ||
| auto priv = GARROW_EXECUTOR_GET_PRIVATE(GARROW_EXECUTOR(object)); | ||
|
|
||
| switch (prop_id) { | ||
| case PROP_EXECUTOR: | ||
| priv->executor = *static_cast<std::shared_ptr<arrow::internal::Executor> *>( | ||
| g_value_get_pointer(value)); | ||
| break; | ||
| default: | ||
| G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| static void | ||
| garrow_executor_class_init(GArrowExecutorClass *klass) | ||
| { | ||
| auto gobject_class = G_OBJECT_CLASS(klass); | ||
|
|
||
| gobject_class->finalize = garrow_executor_finalize; | ||
| gobject_class->set_property = garrow_executor_set_property; | ||
|
|
||
| GParamSpec *spec; | ||
| spec = g_param_spec_pointer( | ||
| "executor", | ||
| "Executor", | ||
| "The raw std::shared_ptr<arrow::internal::Executor> *", | ||
| static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); | ||
| g_object_class_install_property(gobject_class, PROP_EXECUTOR, spec); | ||
| } | ||
|
|
||
| G_DEFINE_TYPE(GArrowThreadPool, garrow_thread_pool, GARROW_TYPE_EXECUTOR) | ||
|
|
||
| static void | ||
| garrow_thread_pool_init(GArrowThreadPool *object) | ||
| { | ||
| } | ||
|
|
||
| static void | ||
| garrow_thread_pool_class_init(GArrowThreadPoolClass *klass) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * garrow_thread_pool_new: | ||
| * @n_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 n_threads, GError **error) | ||
| { | ||
| auto arrow_thread_pool_result = arrow::internal::ThreadPool::Make(n_threads); | ||
| if (garrow::check(error, arrow_thread_pool_result, "[thread-pool][new]")) { | ||
| auto arrow_thread_pool = *arrow_thread_pool_result; | ||
| auto thread_pool = GARROW_THREAD_POOL( | ||
| g_object_new(GARROW_TYPE_THREAD_POOL, "executor", &arrow_thread_pool, nullptr)); | ||
| return thread_pool; | ||
| } else { | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| G_END_DECLS | ||
|
|
||
| std::shared_ptr<arrow::internal::Executor> | ||
| garrow_executor_get_raw(GArrowExecutor *executor) | ||
| { | ||
| if (!executor) | ||
| return nullptr; | ||
|
|
||
| auto priv = GARROW_EXECUTOR_GET_PRIVATE(executor); | ||
| return priv->executor; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you rename to
executer.{cpp,h,hpp}?ThreadPoolis one of executors.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.
I renamed to
executor.{cpp,h,hpp}which is what I assume you meant.On that note, perhaps we should create a base class
Executor, and haveExecuteContextaccept that instead of aThreadPool?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.
Oh, sorry. You're right.
Yes. It's better.
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.
Add Executor base class.