## winix-process--premicrothread.pkg
#
# The Posix-based implementation of the
# portable (cross-platform) process control
# interface Winix_Process__Premicrothread from
#
#
src/lib/std/src/winix/winix-process--premicrothread.api#
# This is a subpackage of winix_guts:
#
#
src/lib/std/src/posix/winix-guts.pkg# Compiled by:
#
src/lib/std/src/standard-core.sublib### "Men pass in front of our eyes like butterflies,
### creatures of a brief season. We love them;
### they are brave, proud, beautiful, clever;
### and they die almost at once. They die so soon
### that our hearts are continually racked with pain."
###
### -- Philip Pullman, "The Golden Compass"
stipulate
package at = run_at__premicrothread; # run_at__premicrothread is from
src/lib/std/src/nj/run-at--premicrothread.pkg package u1b = one_byte_unt_guts; # one_byte_unt_guts is from
src/lib/std/src/one-byte-unt-guts.pkg package psx = posixlib; # posixlib is from
src/lib/std/src/psx/posixlib.pkg package is = interprocess_signals; # interprocess_signals is from
src/lib/std/src/nj/interprocess-signals.pkg package tg = time_guts; # time_guts is from
src/lib/std/src/time-guts.pkg package wio = winix_io__premicrothread; # winix_io__premicrothread is from
src/lib/std/src/posix/winix-io--premicrothread.pkg package wt = winix_types; # winix_types is from
src/lib/std/src/posix/winix-types.pkg #
run_functions_scheduled_to_run = at::run_functions_scheduled_to_run;
herein
package winix_process__premicrothread
: (weak) Winix_Process__Premicrothread # Winix_Process__Premicrothread is from
src/lib/std/src/winix/winix-process--premicrothread.api {
# package proc = posixlib; # posixlib is from
src/lib/std/src/psx/posixlib.pkg Status = wt::process::Status; # Int
success = 0;
failure = 1;
fun successful 0 => TRUE;
successful _ => FALSE;
end;
fun bin_sh' command
=
case (psx::fork ())
#
NULL => psx::exec ("/bin/sh", ["sh", "-c", command]) psx::exit 0u127; # exec is from
src/lib/std/src/psx/posix-process.pkg #
THE pid
=>
{ fun save_signal s
=
is::set_signal_handler
(s, is::IGNORE);
save_signal_int = save_signal is::SIGINT;
save_signal_quit = save_signal is::SIGQUIT;
fun restore ()
=
{ is::set_signal_handler (is::SIGINT, save_signal_int);
is::set_signal_handler (is::SIGQUIT, save_signal_quit);
();
};
fun wait ()
=
case (#2 (psx::waitpid (psx::W_CHILD pid, [])))
#
psx::W_EXITED => success;
psx::W_EXITSTATUS w => u1b::to_int w;
psx::W_SIGNALED s => failure; # ??
psx::W_STOPPED s => failure; # this shouldn't happen
esac;
(wait() then restore())
except
any_exception
=
{ restore ();
raise exception any_exception;
};
};
esac;
fun exit_uncleanly_x status
=
psx::exit (u1b::from_int status); # psx::exit is from
src/lib/std/src/psx/posix-process.pkg # psx::exit calls the C-level exit() fn in src/c/lib/posix-process/exit.c
fun exit_uncleanly status
=
{ exit_uncleanly_x status; # Never returns.
(); # Cannot execute; purely to keep typechecker happy.
};
fun exit_x status
=
{
# print "exit_1/SHUTDOWN_PHASE_1 -- winix-process--premicrothread.pkg\n";
run_functions_scheduled_to_run at::SHUTDOWN_PHASE_1_USER_HOOKS;
# Following stuff commented out because I'm not convinced the game is worth the candle: -- 2012-09-23 CrT
# print "exit_1/SHUTDOWN_PHASE_2 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_2_UNREDIRECT_SYSCALLS;
# print "exit_1/SHUTDOWN_PHASE_3 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_3_STOP_THREAD_SCHEDULER;
# print "exit_1/SHUTDOWN_PHASE_4 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_4_STOP_SUPPORT_HOSTTHREADS;
# print "exit_1/SHUTDOWN_PHASE_5 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_5_ZERO_COMPILE_STATISTICS;
# print "exit_1/SHUTDOWN_PHASE_6 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_6_CLOSE_OPEN_FILES;
# print "exit_1/SHUTDOWN_PHASE_7 -- winix-process--premicrothread.pkg\n";
# run_functions_scheduled_to_run at::SHUTDOWN_PHASE_7_CLEAR_POSIX_INTERPROCESS_SIGNAL_HANDLER_TABLE;
# print "exit_x terminating -- src/lib/std/src/posix/winix-process--premicrothread.pkg\n";
#
exit_uncleanly_x status;
};
fun exit status
=
{
exit_x status; # Never returns.
(); # Cannot execute; purely to keep typechecker happy.
};
get_env = psx::getenv;
fun sleep secs
=
{
# print "src/lib/std/src/posix/winix-process--premicrothread.pkg: sleep: Calling src/c/lib/posix-os/select.c\n";
wio::wait_for_io_opportunity
{
wait_requests => [],
timeout => THE (tg::from_float_seconds secs)
};
# print "src/lib/std/src/posix/winix-process--premicrothread.pkg: sleep: Back from src/c/lib/posix-os/select.c\n";
#
();
};
#
# By calling wait_for_io_opportunity() we allow
# sleeping with sub-second accuracy; Calling
# psx::sleep allows sleeping only to a resolution
# of seconds.
get_process_id = psx::get_process_id;
};
end;