From 424cf7c72829a39f10f1d5e6975118e4348c0379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 8 Apr 2014 10:59:57 +0200 Subject: Make the sdl module C code use the main thread All video operations should be on the main thread, including initialization. This makes no difference on my system, but might on others. There is no cost doing this as these functions are very rarely called, and usually before/after everything else. --- c_src/sdl.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 17 deletions(-) (limited to 'c_src') diff --git a/c_src/sdl.c b/c_src/sdl.c index 6a429f3..02e8150 100644 --- a/c_src/sdl.c +++ b/c_src/sdl.c @@ -27,16 +27,33 @@ NIF_LIST_TO_FLAGS_FUNCTION(list_to_init_flags, Uint32, INIT_FLAGS) +// init + +NIF_CALL_HANDLER(thread_init) +{ + if (SDL_Init((long)args[0])) + return sdl_error_tuple(env); + + return atom_ok; +} + NIF_FUNCTION(init) { Uint32 flags = 0; BADARG_IF(!list_to_init_flags(env, argv[0], &flags)); - if (SDL_Init(flags) == 0) - return atom_ok; + return nif_thread_call(env, thread_init, 1, flags); +} + +// init_subsystem + +NIF_CALL_HANDLER(thread_init_subsystem) +{ + if (SDL_InitSubSystem((long)args[0])) + return sdl_error_tuple(env); - return sdl_error_tuple(env); + return atom_ok; } NIF_FUNCTION(init_subsystem) @@ -45,17 +62,26 @@ NIF_FUNCTION(init_subsystem) BADARG_IF(!list_to_init_flags(env, argv[0], &flags)); - if (SDL_InitSubSystem(flags) == 0) - return atom_ok; + return nif_thread_call(env, thread_init_subsystem, 1, flags); +} + +// quit - return sdl_error_tuple(env); +NIF_CAST_HANDLER(thread_quit) +{ + SDL_Quit(); } NIF_FUNCTION(quit) { - SDL_Quit(); + return nif_thread_cast(env, thread_quit, 0);; +} - return atom_ok; +// quit_subsystem + +NIF_CAST_HANDLER(thread_quit_subsystem) +{ + SDL_QuitSubSystem((long)args[0]); } NIF_FUNCTION(quit_subsystem) @@ -64,19 +90,32 @@ NIF_FUNCTION(quit_subsystem) BADARG_IF(!list_to_init_flags(env, argv[0], &flags)); - SDL_QuitSubSystem(flags); - - return atom_ok; + return nif_thread_cast(env, thread_quit_subsystem, 1, flags); } -NIF_FUNCTION(set_main_ready) +// set_main_ready + +NIF_CAST_HANDLER(thread_set_main_ready) { SDL_SetMainReady(); +} - return atom_ok; +NIF_FUNCTION(set_main_ready) +{ + return nif_thread_cast(env, thread_set_main_ready, 0);; } +// was_init // @todo Implement the case where we want to receive a list of everything init. + +NIF_CALL_HANDLER(thread_was_init) +{ + if (SDL_WasInit((long)args[0])) + return atom_true; + + return atom_false; +} + NIF_FUNCTION(was_init) { unsigned int length; @@ -86,8 +125,5 @@ NIF_FUNCTION(was_init) BADARG_IF(length == 0); BADARG_IF(!list_to_init_flags(env, argv[0], &flags)); - if (SDL_WasInit(flags)) - return atom_true; - - return atom_false; + return nif_thread_call(env, thread_was_init, 1, flags); } -- cgit v1.2.3