PreviousUpNext

15.4.931  src/lib/src/lib/thread-kit/src/core-thread-kit/thread-scheduler-is-running.pkg

## thread-scheduler-is-running.pkg
#
# Track whether the thread scheduler is running.
#
# This gets set and cleared in    thread_scheduler_control_g
# but other modules need to test it.
#
# Because we save heap images to disk and later revive them,
# we have the usual problem that our state-flag might wind
# up out of date, which as usual we deal with by tracking
# the process id -- if it has changed since we last checked,
# we've been restarted and the flag is stale.

# Compiled by:
#     src/lib/std/standard.lib




###         "You can outdistance that which is running after you,
###          but not what is running inside you."
###
###                                -- Rwandan proverb


stipulate
    package at  =  run_at__premicrothread;                                      # run_at__premicrothread                is from   src/lib/std/src/nj/run-at--premicrothread.pkg
    package wxp =  winix__premicrothread::process;                              # winix__premicrothread::process        is from   src/lib/std/src/posix/winix-process--premicrothread.pkg
herein

    package thread_scheduler_is_running {
        #
        thread_scheduler_is_running_as_pid                                      # This will be   NULL     when the thread scheduler is not running
            =                                                                   # and  will be   THE pid  when the thread scheduler is running, where pid is our unix process identifier.
            REF (NULL: Null_Or(Int));

        started_thread_scheduler_shutdown                                       # This gets set in      src/lib/src/lib/thread-kit/src/glue/thread-scheduler-control-g.pkg
            =                                                                   # and                   src/lib/src/lib/thread-kit/src/glue/threadkit-base-for-os-g.pkg
            REF FALSE;                                                          # The idea is just to avoid redundantly starting a shutdown sequence when we're already doing one.

        fun thread_scheduler_is_running ()
            =
            case *thread_scheduler_is_running_as_pid
                #
                NULL    =>  FALSE;
                THE pid =>  pid == wxp::get_process_id ();
            esac;

                                                                        my _ =  # Needed because only declarations are syntactically legal here.
        at::schedule
          (
            "thread-scheduler-is-running.pkg: Clear state vars",                # Arbitrary label for debugging displays.
            #
            [ at::STARTUP_PHASE_1_RESET_STATE_VARIABLES ],                      # When to run the function.
            #
            \\ _ = {                                                            # Ignored arg is at::STARTUP_PHASE_1_RESET_STATE_VARIABLES
                thread_scheduler_is_running_as_pid    :=  NULL;
                started_thread_scheduler_shutdown     :=  FALSE;
            }
          );
    };
end;


## COPYRIGHT (c) 1997 Bell Labs, Lucent Technologies.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext