Skip to content

Commit

Permalink
SDL: Call multiplayer->update() from the user code thread
Browse files Browse the repository at this point in the history
The multiplayer update scans for messages and passes them in to the
user defined function on_message(). This should be done in the user
code thread for two reasons:

1. Calling it from a different thread means on_message() and update()
are being run in different threads, and therefore all code in both of
them has to be thread safe. This is pretty hard to do with the 32blit
API and not really in the spirit of what this is supposed to be.

2. on_message() is a user-supplied function and so bugs can make it
hang. We can detect hangs in update() and render() thanks to running
them on the user thread (via blit::tick()). Running on_message() on
that thread allows to detect hangs there too.
  • Loading branch information
ali1234 committed Sep 29, 2021
1 parent 3789c78 commit 8618be9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 0 additions & 1 deletion 32blit-sdl/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ void handle_event(SDL_Event &event) {

default:
if(event.type == System::loop_event) {
blit_multiplayer->update();
blit_renderer->update(blit_system);
blit_system->notify_redraw();
blit_renderer->present();
Expand Down
1 change: 1 addition & 0 deletions 32blit-sdl/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ void System::loop()
blit::joystick.y = shadow_joystick[1];
SDL_UnlockMutex(m_input);
blit::tick(::now());
blit_multiplayer->update();
}

Uint32 System::mode() {
Expand Down

0 comments on commit 8618be9

Please sign in to comment.