From 70a712bd6d5bb8236f27bf414dc968366469e1df Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 30 Jul 2014 08:41:46 -0400 Subject: [PATCH] pnacl: redef exit as a top-level Signed-off-by: Jean Privat --- contrib/online_ide/sources/nit/pnacl_nit.nit | 20 +++++------ lib/pnacl.nit | 50 +++++++++++++------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/contrib/online_ide/sources/nit/pnacl_nit.nit b/contrib/online_ide/sources/nit/pnacl_nit.nit index 8274f44..07db5ed 100644 --- a/contrib/online_ide/sources/nit/pnacl_nit.nit +++ b/contrib/online_ide/sources/nit/pnacl_nit.nit @@ -24,17 +24,15 @@ intrude import toolcontext intrude import modelbuilder intrude import standard::file -redef interface Object - # We redefine exit to start a new thread before killing the one that called exit. - redef fun exit(exit_value: Int) - do - var dictionary = new PepperDictionary - dictionary["exit"] = exit_value - dictionary["exit_thread"] = "A new thread has been made available for Nit." - create_thread - app.post_dictionary dictionary - exit_thread exit_value - end +# We redefine exit to start a new thread before killing the one that called exit. +redef fun exit(exit_value: Int) +do + var dictionary = new PepperDictionary + dictionary["exit"] = exit_value + dictionary["exit_thread"] = "A new thread has been made available for Nit." + create_thread + app.post_dictionary dictionary + exit_thread exit_value end #hack realpath. diff --git a/lib/pnacl.nit b/lib/pnacl.nit index 42a6b8c..e9b5407 100644 --- a/lib/pnacl.nit +++ b/lib/pnacl.nit @@ -724,34 +724,32 @@ class PnaclApp end end -redef interface Object - # Creates a new thread for Nit. - # - # This function launches the Nit main on a new thread. - # Its purpose is to allow Nit to be still operational after an exit when needed, - # because reloading the page may not be an option. - # - # Should only be used within the 'exit' before stopping the current thread - # when the Nit execution causes a crash. - # - # REQUIRE: g_nit_thread and WrapperNitMain are set. - fun create_thread `{ - pthread_create(&g_nit_thread, NULL, &WrapperNitMain, NULL); - `} +# Creates a new thread for Nit. +# +# This function launches the Nit main on a new thread. +# Its purpose is to allow Nit to be still operational after an exit when needed, +# because reloading the page may not be an option. +# +# Should only be used within the 'exit' before stopping the current thread +# when the Nit execution causes a crash. +# +# REQUIRE: g_nit_thread and WrapperNitMain are set. +fun create_thread `{ + pthread_create(&g_nit_thread, NULL, &WrapperNitMain, NULL); +`} - # Calls 'pthread_exit on current thread. - fun exit_thread(exit_value: Int) `{ - pthread_exit((void*) exit_value); - `} +# Calls 'pthread_exit on current thread. +fun exit_thread(exit_value: Int) `{ + pthread_exit((void*) exit_value); +`} - # Redef of exit in order to avoid the module to crash by terminating only the Nit thread. - redef fun exit(exit_value: Int) - do - var dictionary = new PepperDictionary - dictionary["exit"] = exit_value - app.post_dictionary dictionary - exit_thread exit_value - end +# Redef of exit in order to avoid the module to crash by terminating only the Nit thread. +redef fun exit(exit_value: Int) +do + var dictionary = new PepperDictionary + dictionary["exit"] = exit_value + app.post_dictionary dictionary + exit_thread exit_value end fun app: PnaclApp do return once new PnaclApp -- 1.7.9.5