Skip to content

Commit

Permalink
Merge pull request #5578 from juj/library_js_in_pthreads
Browse files Browse the repository at this point in the history
Multithreading 11/N: src/library.js in pthreads
  • Loading branch information
juj authored Nov 10, 2017
2 parents fb28418 + 6aeea7a commit fec60ff
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 80 deletions.
85 changes: 45 additions & 40 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ LibraryManager.library = {
// ==========================================================================

utime__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
utime__proxy: 'sync',
utime__sig: 'iii',
utime: function(path, times) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_2({{{ cDefine('EM_PROXIED_UTIME') }}}, path, times);
#endif
// int utime(const char *path, const struct utimbuf *times);
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/utime.h.html
var time;
Expand All @@ -82,10 +81,9 @@ LibraryManager.library = {
},

utimes__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
utimes__proxy: 'sync',
utimes__sig: 'iii',
utimes: function(path, times) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_2({{{ cDefine('EM_PROXIED_UTIMES') }}}, path, times);
#endif
var time;
if (times) {
var offset = {{{ C_STRUCTS.timeval.__size__ }}} + {{{ C_STRUCTS.timeval.tv_sec }}};
Expand Down Expand Up @@ -116,21 +114,19 @@ LibraryManager.library = {
},

chroot__deps: ['__setErrNo', '$ERRNO_CODES'],
chroot__proxy: 'sync',
chroot__sig: 'ii',
chroot: function(path) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_CHROOT') }}}, path);
#endif
// int chroot(const char *path);
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/chroot.html
___setErrNo(ERRNO_CODES.EACCES);
return -1;
},

fpathconf__deps: ['__setErrNo', '$ERRNO_CODES'],
fpathconf__proxy: 'sync',
fpathconf__sig: 'iii',
fpathconf: function(fildes, name) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_2({{{ cDefine('EM_PROXIED_FPATHCONF') }}}, fildes, name);
#endif
// long fpathconf(int fildes, int name);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/encrypt.html
// NOTE: The first parameter is ignored, so pathconf == fpathconf.
Expand Down Expand Up @@ -171,10 +167,9 @@ LibraryManager.library = {
pathconf: 'fpathconf',

confstr__deps: ['__setErrNo', '$ERRNO_CODES', '$ENV'],
confstr__proxy: 'sync',
confstr__sig: 'iiii',
confstr: function(name, buf, len) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_3({{{ cDefine('EM_PROXIED_CONFSTR') }}}, name, buf, len);
#endif
// size_t confstr(int name, char *buf, size_t len);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/confstr.html
var value;
Expand Down Expand Up @@ -281,10 +276,9 @@ LibraryManager.library = {
},

sysconf__deps: ['__setErrNo', '$ERRNO_CODES'],
sysconf__proxy: 'sync',
sysconf__sig: 'ii',
sysconf: function(name) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_SYSCONF') }}}, name);
#endif
// long sysconf(int name);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/sysconf.html
switch(name) {
Expand Down Expand Up @@ -599,10 +593,9 @@ LibraryManager.library = {
_exit(-1234);
},

atexit__proxy: 'sync',
atexit__sig: 'ii',
atexit: function(func, arg) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_2({{{ cDefine('EM_PROXIED_ATEXIT') }}}, func, arg);
#endif
__ATEXIT__.unshift({ func: func, arg: arg });
},
__cxa_atexit: 'atexit',
Expand Down Expand Up @@ -684,10 +677,9 @@ LibraryManager.library = {
#endif
$ENV: {},
getenv__deps: ['$ENV'],
getenv__proxy: 'sync',
getenv__sig: 'ii',
getenv: function(name) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_GETENV') }}}, name);
#endif
// char *getenv(const char *name);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/getenv.html
if (name === 0) return 0;
Expand All @@ -699,21 +691,19 @@ LibraryManager.library = {
return _getenv.ret;
},
clearenv__deps: ['$ENV', '__buildEnvironment'],
clearenv: function(name) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_CLEARENV') }}}, name);
#endif
clearenv__proxy: 'sync',
clearenv__sig: 'i',
clearenv: function() {
// int clearenv (void);
// http://www.gnu.org/s/hello/manual/libc/Environment-Access.html#index-clearenv-3107
ENV = {};
___buildEnvironment(ENV);
return 0;
},
setenv__deps: ['$ENV', '__buildEnvironment', '$ERRNO_CODES', '__setErrNo'],
setenv__proxy: 'sync',
setenv__sig: 'iiii',
setenv: function(envname, envval, overwrite) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_3({{{ cDefine('EM_PROXIED_SETENV') }}}, envname, envval, overwrite);
#endif
// int setenv(const char *envname, const char *envval, int overwrite);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/setenv.html
if (envname === 0) {
Expand All @@ -732,10 +722,9 @@ LibraryManager.library = {
return 0;
},
unsetenv__deps: ['$ENV', '__buildEnvironment', '$ERRNO_CODES', '__setErrNo'],
unsetenv__proxy: 'sync',
unsetenv__sig: 'ii',
unsetenv: function(name) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_UNSETENV') }}}, name);
#endif
// int unsetenv(const char *name);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/unsetenv.html
if (name === 0) {
Expand All @@ -754,10 +743,9 @@ LibraryManager.library = {
return 0;
},
putenv__deps: ['$ENV', '__buildEnvironment', '$ERRNO_CODES', '__setErrNo'],
putenv__proxy: 'sync',
putenv__sig: 'ii',
putenv: function(string) {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_1({{{ cDefine('EM_PROXIED_PUTENV') }}}, string);
#endif
// int putenv(char *string);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html
// WARNING: According to the standard (and the glibc implementation), the
Expand Down Expand Up @@ -1653,6 +1641,8 @@ LibraryManager.library = {
},
// void* dlopen(const char* filename, int flag);
dlopen__deps: ['$DLFCN', '$FS', '$ENV'],
dlopen__proxy: 'sync',
dlopen__sig: 'iii',
dlopen: function(filename, flag) {
#if MAIN_MODULE == 0
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking");
Expand Down Expand Up @@ -1773,6 +1763,8 @@ LibraryManager.library = {
},
// int dlclose(void* handle);
dlclose__deps: ['$DLFCN'],
dlclose__proxy: 'sync',
dlclose__sig: 'ii',
dlclose: function(handle) {
// int dlclose(void *handle);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dlclose.html
Expand All @@ -1793,6 +1785,8 @@ LibraryManager.library = {
},
// void* dlsym(void* handle, const char* symbol);
dlsym__deps: ['$DLFCN'],
dlsym__proxy: 'sync',
dlsym__sig: 'iii',
dlsym: function(handle, symbol) {
// void *dlsym(void *restrict handle, const char *restrict name);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html
Expand Down Expand Up @@ -1824,6 +1818,8 @@ LibraryManager.library = {
},
// char* dlerror(void);
dlerror__deps: ['$DLFCN'],
dlerror__proxy: 'sync',
dlerror__sig: 'i',
dlerror: function() {
// char *dlerror(void);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dlerror.html
Expand All @@ -1838,6 +1834,8 @@ LibraryManager.library = {
}
},

dladdr__proxy: 'sync',
dladdr__sig: 'iii',
dladdr: function(addr, info) {
// report all function pointers as coming from this program itself XXX not really correct in any way
var fname = allocate(intArrayFromString(Module['thisProgram'] || './this.program'), 'i8', ALLOC_NORMAL); // XXX leak
Expand Down Expand Up @@ -2072,10 +2070,9 @@ LibraryManager.library = {
timezone: '{{{ makeStaticAlloc(1) }}}',
#endif
tzset__deps: ['tzname', 'daylight', 'timezone'],
tzset__proxy: 'sync',
tzset__sig: 'v',
tzset: function() {
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return _emscripten_sync_run_in_main_thread_0({{{ cDefine('EM_PROXIED_TZSET') }}});
#endif
// TODO: Use (malleable) environment variables instead of system settings.
if (_tzset.called) return;
_tzset.called = true;
Expand Down Expand Up @@ -3508,6 +3505,8 @@ LibraryManager.library = {

// note: lots of leaking here!
gethostbyaddr__deps: ['$DNS', 'gethostbyname', '_inet_ntop4_raw'],
gethostbyaddr__proxy: 'sync',
gethostbyaddr__sig: 'iiii',
gethostbyaddr: function (addr, addrlen, type) {
if (type !== {{{ cDefine('AF_INET') }}}) {
___setErrNo(ERRNO_CODES.EAFNOSUPPORT);
Expand All @@ -3525,6 +3524,8 @@ LibraryManager.library = {
},

gethostbyname__deps: ['$DNS', '_inet_pton4_raw'],
gethostbyname__proxy: 'sync',
gethostbyname__sig: 'ii',
gethostbyname: function(name) {
name = Pointer_stringify(name);

Expand All @@ -3548,6 +3549,8 @@ LibraryManager.library = {
},

gethostbyname_r__deps: ['gethostbyname'],
gethostbyname_r__proxy: 'sync',
gethostbyname_r__sig: 'iiiiiii',
gethostbyname_r: function(name, ret, buf, buflen, out, err) {
var data = _gethostbyname(name);
_memcpy(ret, data, {{{ C_STRUCTS.hostent.__size__ }}});
Expand All @@ -3558,6 +3561,8 @@ LibraryManager.library = {
},

getaddrinfo__deps: ['$Sockets', '$DNS', '_inet_pton4_raw', '_inet_ntop4_raw', '_inet_pton6_raw', '_inet_ntop6_raw', '_write_sockaddr'],
getaddrinfo__proxy: 'sync',
getaddrinfo__sig: 'iiiii',
getaddrinfo: function(node, service, hint, out) {
// Note getaddrinfo currently only returns a single addrinfo with ai_next defaulting to NULL. When NULL
// hints are specified or ai_family set to AF_UNSPEC or ai_socktype or ai_protocol set to 0 then we
Expand Down
Loading

0 comments on commit fec60ff

Please sign in to comment.