diff options
author | Loïc Hoguin <[email protected]> | 2014-04-08 10:59:57 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-04-08 11:01:03 +0200 |
commit | 424cf7c72829a39f10f1d5e6975118e4348c0379 (patch) | |
tree | 2a6aae87f9daf2a856e87bd0a85c772ced32f48a /c_src | |
parent | f5ecbb3b0282637423b236b2532d3e312cb8b291 (diff) | |
download | esdl2-424cf7c72829a39f10f1d5e6975118e4348c0379.tar.gz esdl2-424cf7c72829a39f10f1d5e6975118e4348c0379.tar.bz2 esdl2-424cf7c72829a39f10f1d5e6975118e4348c0379.zip |
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.
Diffstat (limited to 'c_src')
-rw-r--r-- | c_src/sdl.c | 70 |
1 files changed, 53 insertions, 17 deletions
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); } |