Created
August 28, 2017 23:27
-
-
Save kumpera/dbe1b3a1a28314160532dc07cf5b041a to your computer and use it in GitHub Desktop.
emscripten test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//first file | |
#include <emscripten.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
void* mono_native_tls_get_value(int key); | |
void mono_native_tls_set_value(int key, void *value); | |
void mono_threads_platform_exit (int exit_code); | |
#define G_STMT_START do | |
#define G_STMT_END while (0) | |
#define G_GNUC_NORETURN __attribute__((__noreturn__)) | |
#define G_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0)) | |
void g_assertion_message (const char *format, ...) G_GNUC_NORETURN; | |
#define g_assert(x) G_STMT_START { if (G_UNLIKELY (!(x))) g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x); } G_STMT_END | |
typedef struct { | |
int value; | |
} MonoThreadInfo; | |
#define THREADS_DEBUG(...) | |
static int mono_threads_inited, thread_exited_key, thread_info_key; | |
static void | |
unregister_thread (void *arg) | |
{ | |
g_assert (arg); | |
mono_native_tls_set_value (thread_exited_key, (void*)1); | |
} | |
void | |
mono_thread_info_detach (void) | |
{ | |
MonoThreadInfo *info; | |
g_assert (mono_threads_inited); | |
info = (MonoThreadInfo *) mono_native_tls_get_value (thread_info_key); | |
if (info) { | |
THREADS_DEBUG ("detaching %p\n", info); | |
unregister_thread (info); | |
} | |
} | |
EMSCRIPTEN_KEEPALIVE | |
void | |
mono_thread_info_exit (int exit_code) | |
{ | |
mono_thread_info_detach (); | |
mono_threads_platform_exit (0); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
void | |
mono_threads_init (void) | |
{ | |
thread_exited_key = 99; | |
thread_info_key= 22; | |
mono_threads_inited = 1; | |
} | |
//second file | |
#include <stdio.h> | |
#include <stdlib.h> | |
void g_log (const char *log_domain, int log_level, const char *format, ...); | |
#define g_error(format, ...)do { g_log (NULL, 1 << 2, format); for (;;); } while (0) | |
void | |
mono_threads_platform_exit (int exit_code) | |
{ | |
g_error ("WASM doesn't support threading"); | |
} | |
static void *tls[1000]; | |
void* mono_native_tls_get_value(int key) { | |
return tls [key]; | |
} | |
void | |
mono_native_tls_set_value(int key, void *value) | |
{ | |
tls [key] = value; | |
} | |
//third file | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
void | |
g_assertion_message (const char *format, ...) | |
{ | |
char *ret; | |
va_list args; | |
int n; | |
va_start (args, format); | |
n = vasprintf (&ret, format, args); | |
va_end (args); | |
printf ("hello %s\n", ret); | |
abort (); | |
} | |
void g_log (const char *log_domain, int log_level, const char *format, ...) | |
{ | |
char *ret; | |
va_list args; | |
int n; | |
va_start (args, format); | |
n = vasprintf (&ret, format, args); | |
va_end (args); | |
printf ("hello %s\n", ret); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment