File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,14 @@ size_t fu_pool_count_threads_in(fu_pool_t *pool, size_t colocation_index) {
345
345
return std::visit ([=](auto &variant) { return variant.threads_count (colocation_index); }, opaque->variants );
346
346
}
347
347
348
+ size_t fu_pool_locate_thread_in (fu_pool_t *pool, size_t global_thread_index, size_t colocation_index) {
349
+ assert (pool != nullptr );
350
+ opaque_pool_t *opaque = reinterpret_cast <opaque_pool_t *>(pool);
351
+ return std::visit ([=](auto &variant) {
352
+ return variant.thread_local_index (global_thread_index, colocation_index);
353
+ }, opaque->variants );
354
+ }
355
+
348
356
#pragma endregion - Lifetime
349
357
350
358
#pragma region - Primary API
Original file line number Diff line number Diff line change @@ -481,6 +481,15 @@ size_t fu_pool_count_threads(fu_pool_t *pool);
481
481
*/
482
482
size_t fu_pool_count_threads_in (fu_pool_t * pool , size_t colocation_index );
483
483
484
+ /**
485
+ * @brief Converts a global thread index to a local thread index within a colocation.
486
+ * @param[in] pool Thread pool handle, must not be NULL.
487
+ * @param[in] global_thread_index The global thread index to convert.
488
+ * @param[in] colocation_index Index of the colocation, must be < `fu_pool_count_colocations(pool)`.
489
+ * @retval Local thread index within the specified colocation.
490
+ */
491
+ size_t fu_pool_locate_thread_in (fu_pool_t * pool , size_t global_thread_index , size_t colocation_index );
492
+
484
493
#pragma endregion - Lifetime
485
494
486
495
#pragma region - Primary API
Original file line number Diff line number Diff line change @@ -353,6 +353,7 @@ extern "C" {
353
353
fn fu_pool_count_threads ( pool : * mut c_void ) -> usize ;
354
354
fn fu_pool_count_colocations ( pool : * mut c_void ) -> usize ;
355
355
fn fu_pool_count_threads_in ( pool : * mut c_void , colocation_index : usize ) -> usize ;
356
+ fn fu_pool_locate_thread_in ( pool : * mut c_void , global_thread_index : usize , colocation_index : usize ) -> usize ;
356
357
357
358
#[ allow( dead_code) ]
358
359
fn fu_pool_for_threads (
@@ -683,6 +684,24 @@ impl ThreadPool {
683
684
unsafe { fu_pool_count_threads_in ( self . inner , colocation_index) }
684
685
}
685
686
687
+ /// Converts a global thread index to a local thread index within a colocation.
688
+ ///
689
+ /// This is useful for distributed thread pools where threads are grouped into
690
+ /// colocations (NUMA nodes or QoS levels). The local index can be used for
691
+ /// per-colocation data structures or algorithms.
692
+ ///
693
+ /// # Arguments
694
+ ///
695
+ /// * `global_thread_index` - The global thread index to convert
696
+ /// * `colocation_index` - The colocation to get the local index for
697
+ ///
698
+ /// # Returns
699
+ ///
700
+ /// The local thread index within the specified colocation.
701
+ pub fn locate_thread_in ( & self , global_thread_index : usize , colocation_index : usize ) -> usize {
702
+ unsafe { fu_pool_locate_thread_in ( self . inner , global_thread_index, colocation_index) }
703
+ }
704
+
686
705
/// Transitions worker threads to a power-saving sleep state.
687
706
///
688
707
/// This function places worker threads into a low-power sleep state when no work
You can’t perform that action at this time.
0 commit comments