Repository navigation
Replies: 1 comment 2 replies
|
Why not wrap the calls with your own lock? |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Howdy!
The engine I work on is heavily threaded, including the writing of updates to physics prior to stepping physics. This is a problem for me with calls like
b3Body_SetLinearVelocity,b3Body_SetAngularVelocityandb3Body_SetTargetTransformwhich all MAY wake the body and thus cannot be called in a multi-threaded context. I know one option I could explore is to cache the state changes that are not thread safe and apply them at a thread sync point, but I don't like this approach as it causes a larger single thread bottleneck and duplicates state which increases complexity. I instead took a stab at implementing a user facing locking API directly in box3d that allows for optional thread safety when calling state changing functions. I've put the actual code in a fork, but the gist is the user supplies callbacks for locking (read lock, write lock, read unlock, write unlock and convert read to write) and the internal box3d api aroundworld->lockedis tweaked to grab the appropriate lock type for the work it is doing. If the callbacks are not provided, the behavior is unchanged. I am aware of at least one place missing coverage (b3Body_SetAwake(id, false)+b3Body_GetLinearVelocityon another body in the same island being put to sleep) but it is also not covered by the existingworld->lockedchecking. Is this approach something that could be of interest with some refinement or am I looking at this the wrong way and I should be taking a single threaded approach?All reactions