Add new mju_threadpool API function, and delete old threading API.

PiperOrigin-RevId: 922838541
Change-Id: Id9f7e0fb298ffde61fcc49a802dc78971858ce51
This commit is contained in:
Kyle Bayes
2026-05-28 10:09:07 -07:00
committed by Copybara-Service
parent a22fc2423a
commit b935d4153c
47 changed files with 576 additions and 1755 deletions
+3
View File
@@ -725,6 +725,9 @@ PYBIND11_MODULE(_functions, pymodule) {
Def<traits::mj_version>(pymodule);
Def<traits::mj_versionString>(pymodule);
// Thread pool
Def<traits::mju_threadpool>(pymodule);
// Ray collision
Def<traits::mj_multiRay>(
pymodule,
-10
View File
@@ -609,16 +609,6 @@ ENUMS: Mapping[str, EnumDecl] = dict([
('mjS_AWAKE', 1),
]),
)),
('mjtTaskStatus',
EnumDecl(
name='mjtTaskStatus',
declname='enum mjtTaskStatus_',
values=dict([
('mjTASK_NEW', 0),
('mjTASK_QUEUED', 1),
('mjTASK_COMPLETED', 2),
]),
)),
('mjtGeomInertia',
EnumDecl(
name='mjtGeomInertia',
+5 -83
View File
@@ -9985,23 +9985,9 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc='Find the decoder for a resource and return the decoded spec. The caller takes ownership of the spec and is responsible for cleaning it up.', # pylint: disable=line-too-long
)),
('mju_threadPoolCreate',
('mju_threadpool',
FunctionDecl(
name='mju_threadPoolCreate',
return_type=PointerType(
inner_type=ValueType(name='mjThreadPool'),
),
parameters=(
FunctionParameterDecl(
name='number_of_threads',
type=ValueType(name='size_t'),
),
),
doc='Create a thread pool with the specified number of threads running.', # pylint: disable=line-too-long
)),
('mju_bindThreadPool',
FunctionDecl(
name='mju_bindThreadPool',
name='mju_threadpool',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
@@ -10011,75 +9997,11 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
),
FunctionParameterDecl(
name='thread_pool',
type=PointerType(
inner_type=ValueType(name='void'),
),
name='nthread',
type=ValueType(name='int'),
),
),
doc='Adds a thread pool to mjData and configures it for multi-threaded use.', # pylint: disable=line-too-long
)),
('mju_threadPoolEnqueue',
FunctionDecl(
name='mju_threadPoolEnqueue',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='thread_pool',
type=PointerType(
inner_type=ValueType(name='mjThreadPool'),
),
),
FunctionParameterDecl(
name='task',
type=PointerType(
inner_type=ValueType(name='mjTask'),
),
),
),
doc='Enqueue a task in a thread pool.',
)),
('mju_threadPoolDestroy',
FunctionDecl(
name='mju_threadPoolDestroy',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='thread_pool',
type=PointerType(
inner_type=ValueType(name='mjThreadPool'),
),
),
),
doc='Destroy a thread pool.',
)),
('mju_defaultTask',
FunctionDecl(
name='mju_defaultTask',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='task',
type=PointerType(
inner_type=ValueType(name='mjTask'),
),
),
),
doc='Initialize an mjTask.',
)),
('mju_taskJoin',
FunctionDecl(
name='mju_taskJoin',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='task',
type=PointerType(
inner_type=ValueType(name='mjTask'),
),
),
),
doc='Wait for a task to complete.',
doc='Create a thread pool with nthread worker threads.',
)),
('mjs_attach',
FunctionDecl(
+10 -49
View File
@@ -5104,42 +5104,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
),
)),
('mjThreadPool',
StructDecl(
name='mjThreadPool',
declname='struct mjThreadPool_',
fields=(
StructFieldDecl(
name='nworker',
type=ValueType(name='int'),
doc='number of workers in the pool',
),
),
)),
('mjTask',
StructDecl(
name='mjTask',
declname='struct mjTask_',
fields=(
StructFieldDecl(
name='func',
type=ValueType(name='mjfTask'),
doc='pointer to the function that implements the task',
),
StructFieldDecl(
name='args',
type=PointerType(
inner_type=ValueType(name='void'),
),
doc='arguments to func',
),
StructFieldDecl(
name='status',
type=ValueType(name='int', is_volatile=True),
doc='status of the task',
),
),
)),
('mjPreContact',
StructDecl(
name='mjPreContact',
@@ -5422,19 +5386,21 @@ STRUCTS: Mapping[str, StructDecl] = dict([
type=ValueType(name='size_t'),
doc='first available byte in arena',
),
StructFieldDecl(
name='threadpool',
type=ValueType(name='uintptr_t'),
doc='thread pool pointer',
),
StructFieldDecl(
name='threadlock',
type=ValueType(name='mjtBool'),
doc='disable stack freeing during threaded execution',
),
StructFieldDecl(
name='maxuse_stack',
type=ValueType(name='mjtSize'),
doc='maximum stack allocation in bytes (mutable)',
),
StructFieldDecl(
name='maxuse_threadstack',
type=ArrayType(
inner_type=ValueType(name='mjtSize'),
extents=(128,),
),
doc='maximum stack allocation per thread in bytes',
),
StructFieldDecl(
name='maxuse_arena',
type=ValueType(name='mjtSize'),
@@ -6903,11 +6869,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
doc='constraint force',
array_extent=('nidof',),
),
StructFieldDecl(
name='threadpool',
type=ValueType(name='uintptr_t'),
doc='thread pool pointer',
),
StructFieldDecl(
name='signature',
type=ValueType(name='uint64_t'),