Skip to content

Commit

Permalink
Cleanup examples (removed extra thread execution).
Browse files Browse the repository at this point in the history
svn path=/trunk/mono/; revision=38700
  • Loading branch information
illupus committed Jan 11, 2005
1 parent f946dec commit 11f7e37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
32 changes: 7 additions & 25 deletions samples/embed/test-invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
* ./test-invoke invoke.exe
*/

typedef struct
{
MonoDomain *domain;
const char *file;
int argc;
char **argv;
} MainThreadArgs;

static void
access_valuetype_field (MonoObject *obj)
{
Expand Down Expand Up @@ -298,36 +290,32 @@ create_object (MonoDomain *domain, MonoImage *image)
more_methods (domain);
}

static void main_thread_handler (gpointer user_data)
static void main_function (MonoDomain *domain, const char *file, int argc, char **argv)
{
MainThreadArgs *main_args=(MainThreadArgs *)user_data;
MonoAssembly *assembly;

/* Loading an assembly makes the runtime setup everything
* needed to execute it. If we're just interested in the metadata
* we'd use mono_image_load (), instead and we'd get a MonoImage*.
*/
assembly = mono_domain_assembly_open (main_args->domain,
main_args->file);
assembly = mono_domain_assembly_open (domain, file);
if (!assembly)
exit (2);
/*
* mono_jit_exec() will run the Main() method in the assembly.
* The return value needs to be looked up from
* System.Environment.ExitCode.
*/
mono_jit_exec (main_args->domain, assembly, main_args->argc,
main_args->argv);
mono_jit_exec (domain, assembly, argc, argv);

create_object (main_args->domain, mono_assembly_get_image (assembly));
create_object (domain, mono_assembly_get_image (assembly));
}

int
main (int argc, char* argv[]) {
MonoDomain *domain;
const char *file;
int retval;
MainThreadArgs main_args;

if (argc < 2){
fprintf (stderr, "Please provide an assembly to load\n");
Expand All @@ -340,15 +328,9 @@ main (int argc, char* argv[]) {
*/
domain = mono_jit_init (file);

main_args.domain=domain;
main_args.file=file;
main_args.argc=argc-1;
main_args.argv=argv+1;

mono_runtime_exec_managed_code (domain, main_thread_handler,
&main_args);

retval=mono_environment_exitcode_get ();
main_function (domain, file, argc - 1, argv + 1);

retval = mono_environment_exitcode_get ();

mono_jit_cleanup (domain);
return retval;
Expand Down
28 changes: 5 additions & 23 deletions samples/embed/teste.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,19 @@ gimme () {
return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
}

typedef struct
static void main_function (MonoDomain *domain, const char *file, int argc, char** argv)
{
MonoDomain *domain;
const char *file;
int argc;
char **argv;
} MainThreadArgs;

static void main_thread_handler (gpointer user_data)
{
MainThreadArgs *main_args=(MainThreadArgs *)user_data;
MonoAssembly *assembly;

assembly = mono_domain_assembly_open (main_args->domain,
main_args->file);
assembly = mono_domain_assembly_open (domain, file);
if (!assembly)
exit (2);
/*
* mono_jit_exec() will run the Main() method in the assembly.
* The return value needs to be looked up from
* System.Environment.ExitCode.
*/
mono_jit_exec (main_args->domain, assembly, main_args->argc,
main_args->argv);
mono_jit_exec (domain, assembly, argc, argv);
}


Expand All @@ -47,7 +36,6 @@ main(int argc, char* argv[]) {
MonoDomain *domain;
const char *file;
int retval;
MainThreadArgs main_args;

if (argc < 2){
fprintf (stderr, "Please provide an assembly to load");
Expand All @@ -65,15 +53,9 @@ main(int argc, char* argv[]) {
*/
mono_add_internal_call ("MonoEmbed::gimme", gimme);

main_args.domain=domain;
main_args.file=file;
main_args.argc=argc-1;
main_args.argv=argv+1;

mono_runtime_exec_managed_code (domain, main_thread_handler,
&main_args);
main_function (domain, file, argc - 1, argv + 1);

retval=mono_environment_exitcode_get ();
retval = mono_environment_exitcode_get ();

mono_jit_cleanup (domain);
return retval;
Expand Down

0 comments on commit 11f7e37

Please sign in to comment.