## run-at--premicrothread.api
#
# Schedule hook fns (i.e., arbitrary code) to be
# run at various times, in particular system
# startup and shutdown time.
#
# Most of this stuff is only needed because of our kludge
# of building a heap image by starting up all the packages
# and then dumping to disk and later restarting -- this
# heap save/reload breaks various things which must then
# be fixed.
# For example open file descriptors become stale and
# must be re-opend, kernel resources like mutexes evaporate
# and must be re-allocated, and cached environmental data
# like current date and ip address need to be re-cached.
#
# Compare to:
#
src/lib/src/lib/thread-kit/src/core-thread-kit/run-at.api# Compiled by:
#
src/lib/std/src/standard-core.sublib### "The man who is a pessimist before forty-eight knows too much;
### if he is an optimist after it, he knows too little."
###
### -- Mark Twain
# Run_At__Premicrothread is implemented in:
#
#
src/lib/std/src/nj/run-at--premicrothread.pkg#
api Run_At__Premicrothread {
#
#
When = SPAWN_TO_DISK # Run by:
src/lib/std/src/nj/save-heap-to-disk.pkg # Run by:
src/lib/src/lib/thread-kit/src/glue/thread-scheduler-control-g.pkg # Not used in default configuration; reserved for users.
| FORK_TO_DISK
# Not used in default configuration; reserved for users.
###################################################################
# Following hooks are all run (only) by
#
#
src/lib/std/src/nj/save-heap-to-disk.pkg #
#
| STARTUP_PHASE_1_RESET_STATE_VARIABLES
# Run for:
src/lib/src/lib/thread-kit/src/core-thread-kit/thread-scheduler-is-running.pkg
| STARTUP_PHASE_2_REOPEN_MYTHRYL_LOG
# Run for:
src/lib/std/src/io/winix-text-file-for-os-g--premicrothread.pkg
| STARTUP_PHASE_3_REOPEN_USER_LOGS
# Unused by default, available for users.
| STARTUP_PHASE_4_MAKE_STDIN_STDOUT_AND_STDERR
# Run for:
src/lib/std/src/io/winix-text-file-for-os-g--premicrothread.pkg
| STARTUP_PHASE_5_CLOSE_STALE_OUTPUT_STREAMS
# Run for:
src/lib/std/src/io/io-startup-and-shutdown--premicrothread.pkg #
| STARTUP_PHASE_6_INITIALIZE_POSIX_INTERPROCESS_SIGNAL_HANDLER_TABLE
# Run for:
src/lib/std/src/nj/interprocess-signals.pkg
| STARTUP_PHASE_7_RESET_POSIX_INTERPROCESS_SIGNAL_HANDLER_TABLE
# Run for:
src/lib/std/src/nj/interprocess-signals.pkg #
| STARTUP_PHASE_8_RESET_COMPILER_STATISTICS
# Run for:
src/lib/compiler/front/basics/stats/compile-statistics.pkg
| STARTUP_PHASE_9_RESET_CPU_AND_WALLCLOCK_TIMERS
# Run for:
src/lib/std/src/nj/runtime-internals.pkg
| STARTUP_PHASE_10_START_NEW_DLOPEN_ERA
# Run for:
src/lib/c-glue-lib/ram/linkage-dlopen.pkg #
| STARTUP_PHASE_11_START_SUPPORT_HOSTTHREADS
# Run for:
src/lib/src/lib/thread-kit/src/core-thread-kit/microthread-preemptive-scheduler.pkg
| STARTUP_PHASE_12_START_THREAD_SCHEDULER
# ======= CURRENTLY UNUSED ======= Likely will run for:
src/lib/src/lib/thread-kit/src/glue/thread-scheduler-control-g.pkg
| STARTUP_PHASE_13_REDIRECT_SYSCALLS
# Run for:
src/lib/src/lib/thread-kit/src/glue/redirect-slow-syscalls-via-support-hostthreads.pkg #
| STARTUP_PHASE_14_START_BASE_IMPS
# Unused by default, reserved for future.
| STARTUP_PHASE_15_START_XKIT_IMPS
#
| STARTUP_PHASE_16_OF_HEAP_MADE_BY_SPAWN_TO_DISK
# Unused by default, available for users.
| STARTUP_PHASE_16_OF_HEAP_MADE_BY_FORK_TO_DISK
# Unused by default, available for users.
| STARTUP_PHASE_17_USER_HOOKS
# unused by default, available for users.
###################################################################
# Following hooks are all run (only) by
#
#
src/lib/std/src/nj/save-heap-to-disk.pkg #
src/lib/std/src/posix/winix-process--premicrothread.pkg #
| SHUTDOWN_PHASE_1_USER_HOOKS
# Unused by default, available for users.
#
| SHUTDOWN_PHASE_2_UNREDIRECT_SYSCALLS
# Run for:
src/lib/src/lib/thread-kit/src/glue/redirect-slow-syscalls-via-support-hostthreads.pkg
| SHUTDOWN_PHASE_3_STOP_THREAD_SCHEDULER
# ======= CURRENTLY UNUSED ======= Likely will run for:
src/lib/src/lib/thread-kit/src/glue/thread-scheduler-control-g.pkg
| SHUTDOWN_PHASE_4_STOP_SUPPORT_HOSTTHREADS
# Run for:
src/lib/src/lib/thread-kit/src/core-thread-kit/microthread-preemptive-scheduler.pkg #
| SHUTDOWN_PHASE_5_ZERO_COMPILE_STATISTICS
# Run for:
src/lib/compiler/front/basics/stats/compile-statistics.pkg #
| SHUTDOWN_PHASE_6_CLOSE_OPEN_FILES
# Run for:
src/lib/std/src/io/io-startup-and-shutdown--premicrothread.pkg
| SHUTDOWN_PHASE_6_FLUSH_OPEN_FILES
# Run for:
src/lib/std/src/io/io-startup-and-shutdown--premicrothread.pkg #
| SHUTDOWN_PHASE_7_CLEAR_POSIX_INTERPROCESS_SIGNAL_HANDLER_TABLE
# Run for:
src/lib/std/src/nj/interprocess-signals.pkg
| NEVER_RUN
# Never run, unused by default, occasionally useful.
;
# Add a named at-function.
# This returns the previous definition, or NULL:
#
schedule
:
( String, # Arbitrary string label for at-function.
List( When ), # Times at which to execute it.
When -> Void # The function itself.
)
->
Null_Or ((List( When ), (When -> Void)));
# Remove and return the named at-function.
# Return NULL if it is not found:
#
deschedule
:
String
->
Null_Or ((List( When ), When -> Void));
# Run the at-functions for the specified time.
#
# NB: This function should only be called if you
# really know what you are doing!!
#
run_functions_scheduled_to_run: When -> Void;
when_to_string: When -> String; # Maps FORK_TO_DISK -> "FORK_TO_DISK" etc.
when_to_int: When -> Int; # Imposes a roughly chronological ordering on when values.
when_compare: (When, When) -> Order; # Compares according to above mapping, used for sorting.
when_gt: (When, When) -> Bool; # Compares according to above mapping, used for sorting.
get_schedule: Void -> List( (String, List(When)) ); # List elements are (fn-label, times-to-run)
}; # package run_at__premicrothread
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.