%DEFINE cma$t_integer LONG %DEFINE cma$t_interval SINGLE %DEFINE cma$t_key LONG %DEFINE cma$t_status LONG %DEFINE cma$t_priority LONG %DEFINE cma$t_address LONG %DEFINE cma$t_start_routine LONG %DEFINE cma$t_mutex cma$t_handle %DEFINE cma$t_attr cma$t_handle %DEFINE cma$t_thread cma$t_handle %DEFINE cma$t_cond cma$t_handle %DEFINE cma$t_stack_np cma$t_handle %DEFINE cma$t_exit_status LONG %DEFINE cma$t_sched_inherit LONG %DEFINE cma$t_sched_policy LONG %DEFINE cma$t_mutex_kind LONG %DEFINE cma$t_init_routine LONG %DEFINE cma$t_destructor LONG %DEFINE cma$t_call_routine LONG %DEFINE cma$lib_t_attr cma$t_handle %DEFINE cma$lib_t_queue cma$t_handle ! *** PREDECLARED TYPES %IF %DECLARED ( %BASIC$QUADWORD_DECLARED ) = 0 %THEN RECORD BASIC$QUADWORD LONG FILL ( 2 ) END RECORD %LET %BASIC$QUADWORD_DECLARED = 1 %END %IF %IF %DECLARED ( %BASIC$OCTAWORD_DECLARED ) = 0 %THEN RECORD BASIC$OCTAWORD LONG FILL ( 4 ) END RECORD %LET %BASIC$OCTAWORD_DECLARED = 1 %END %IF %IF %DECLARED ( %BASIC$HFLOAT_AXP_DECLARED ) = 0 %THEN RECORD BASIC$HFLOAT_AXP LONG FILL ( 4 ) END RECORD %LET %BASIC$HFLOAT_AXP_DECLARED = 1 %END %IF %IF %DECLARED ( %BASIC$F_FLOATING_COMPLEX_DECL ) = 0 %THEN RECORD BASIC$F_FLOATING_COMPLEX SINGLE REAL_PART SINGLE IMAGINARY_PART END RECORD %LET %BASIC$F_FLOATING_COMPLEX_DECL = 1 %END %IF %IF %DECLARED ( %BASIC$D_FLOATING_COMPLEX_DECL ) = 0 %THEN RECORD BASIC$D_FLOATING_COMPLEX DOUBLE REAL_PART DOUBLE IMAGINARY_PART END RECORD %LET %BASIC$D_FLOATING_COMPLEX_DECL = 1 %END %IF %IF %DECLARED ( %BASIC$G_FLOATING_COMPLEX_DECL ) = 0 %THEN RECORD BASIC$G_FLOATING_COMPLEX GFLOAT REAL_PART GFLOAT IMAGINARY_PART END RECORD %LET %BASIC$G_FLOATING_COMPLEX_DECL = 1 %END %IF %IF %DECLARED ( %BASIC$H_FLOAT_AXP_CMPLX_DCL ) = 0 %THEN RECORD BASIC$H_FLOATING_COMPLEX_AXP BASIC$HFLOAT_AXP REAL_PART BASIC$HFLOAT_AXP IMAGINARY_PART END RECORD %LET %BASIC$H_FLOAT_AXP_CMPLX_DCL = 1 %END %IF ! ! FACILITY: ! ! Common Multithread Architecture (CMA) services ! ! ABSTRACT: ! ! External definitions for CMA services ! ! AUTHORS: ! ! Dave Butenhof (-Original) ! Paul Curtin (-Generic/SDL) ! ! CREATION DATE: ! ! 2 November 1988 (-Original) ! 7 September 1990 (-Generic/SDL) ! ! MODIFIED BY: ! ! Dave Butenhof ! Paul Curtin ! Gerald Feldman ! Brian Keane ! Webb Scales ! ! ! Define a symbol which client code can test to determine whether the ! underlying threads package is DECthreads or not. This is especially ! important to clients of the Pthreads interface who may want to use ! certain DECthreads extensions, such as the global lock and non-real-time ! scheduling policies, on the DECthreads platform while maintaining ! portability to a "vanilla" pthreads implementation. ! DECLARE LONG CONSTANT DECTHREADS_ = 1 DECLARE LONG CONSTANT cma$c_prio_fifo_min = 16 DECLARE LONG CONSTANT cma$c_prio_fifo_mid = 24 DECLARE LONG CONSTANT cma$c_prio_fifo_max = 31 DECLARE LONG CONSTANT cma$c_prio_rr_min = 16 DECLARE LONG CONSTANT cma$c_prio_rr_mid = 24 DECLARE LONG CONSTANT cma$c_prio_rr_max = 31 DECLARE LONG CONSTANT cma$c_prio_through_min = 8 DECLARE LONG CONSTANT cma$c_prio_through_mid = 12 DECLARE LONG CONSTANT cma$c_prio_through_max = 15 DECLARE LONG CONSTANT cma$c_prio_back_min = 0 DECLARE LONG CONSTANT cma$c_prio_back_mid = 4 DECLARE LONG CONSTANT cma$c_prio_back_max = 7 DECLARE LONG CONSTANT cma$c_prio_ada_low_min = 0 DECLARE LONG CONSTANT cma$c_prio_ada_low_mid = 4 DECLARE LONG CONSTANT cma$c_prio_ada_low_max = 7 DECLARE LONG CONSTANT cma$c_prio_ada_rtb_min = 0 DECLARE LONG CONSTANT cma$c_prio_ada_rtb_mid = 4 DECLARE LONG CONSTANT cma$c_prio_ada_rtb_max = 7 ! ! The implementation of the date_time type should match the "native ! time" of the platform: that allows clients to use the full set of platform ! time operations, rather than just "get_expiration", to compute and ! test timed waits. ! ! This section assumes the platform is either "VMS" or "UNIX-ish". Others ! will require changes. ! DECLARE LONG CONSTANT s_cma$t_date_time = 8 record cma$t_date_time LONG low LONG high end record cma$t_date_time ! ! Sample decisions for what handles shall be ! DECLARE LONG CONSTANT s_cma$t_handle = 8 record cma$t_handle cma$t_natural handle_field1 cma$t_natural handle_field2 end record cma$t_handle DECLARE LONG CONSTANT cma$c_handle_size = 8 ! ! Sample decision for a one-time initialization control block and its ! initialization macro. ! ! DECLARE LONG CONSTANT s_cma$t_once = 12 record cma$t_once cma$t_integer once_field1 cma$t_integer once_field2 cma$t_integer once_field3 end record cma$t_once ! ! Sample decision for a variable to save the current alert state. ! DECLARE LONG CONSTANT s_cma$t_alert_state = 8 record cma$t_alert_state cma$t_integer state1 cma$t_integer state2 end record cma$t_alert_state ! ! The following are the portable CMA definitions ! ! ! Operations on threads ! ! ! Constants ! DECLARE LONG CONSTANT cma$c_false = 0 DECLARE LONG CONSTANT cma$c_true = 1 DECLARE LONG CONSTANT cma$c_null_ptr = 0 ! ! Objects ! ! ! Predefined null handle ! EXTERNAL cma$t_handle cma$c_null ! ! Exit status constants ! DECLARE LONG CONSTANT cma$c_term_error = 0 DECLARE LONG CONSTANT cma$c_term_normal = 1 DECLARE LONG CONSTANT cma$c_term_alert = 2 DECLARE LONG CONSTANT cma$c_null_thread = -1 ! ! Schedule inheritance constants ! DECLARE LONG CONSTANT cma$c_sched_inherit = 0 DECLARE LONG CONSTANT cma$c_sched_use_default = 1 ! ! Schedule policy constants ! DECLARE LONG CONSTANT cma$c_sched_fifo = 0 DECLARE LONG CONSTANT cma$c_sched_rr = 1 DECLARE LONG CONSTANT cma$c_sched_throughput = 2 DECLARE LONG CONSTANT cma$c_sched_background = 3 DECLARE LONG CONSTANT cma$c_sched_ada_low = 4 ! ! Default and other policies. ! DECLARE LONG CONSTANT cma$c_sched_default = 2 DECLARE LONG CONSTANT cma$c_sched_other = 2 ! ! Mutex types ! DECLARE LONG CONSTANT cma$c_mutex_fast = 0 DECLARE LONG CONSTANT cma$c_mutex_recursive = 1 DECLARE LONG CONSTANT cma$c_mutex_nonrecursive = 2 ! ! Operations on Handles ! ! ! The value of a handle can be assigned the value of another handle. ! EXTERNAL SUB cma$handle_assign & ( & cma$t_handle BY REF, & cma$t_handle BY REF & ) ! ! The value of a handle can be assigned the value of another handle. ! EXTERNAL cma$t_boolean FUNCTION cma$handle_equal & ( & cma$t_handle BY REF, & cma$t_handle BY REF & ) ! ! An attributes object is created to specify the attributes of other CMA ! objects that will be created. ! EXTERNAL SUB cma$attr_create & ( & cma$t_attr BY REF, & cma$t_attr BY REF & ) ! ! An attributes object can be deleted when it is no longer needed. ! EXTERNAL SUB cma$attr_delete & ( & cma$t_attr BY REF & ) ! ! The following procedures can be used to control thread creation, ! termination and deletion. ! ! ! To create a thread object and runnable thread, a routine must be specified ! as the new thread's start routine. An argument may be passed to this ! routine, as an untyped address; an untyped address may also be returned as ! the routine's value. An attributes object may be used to specify details ! about the kind of thread being created. ! EXTERNAL SUB cma$thread_create & ( & cma$t_thread BY REF, & cma$t_attr BY REF, & LONG BY REF, & cma$t_address BY REF & ) ! ! A thread object may be "detached" to specify that the return value and ! completion status will not be requested. ! EXTERNAL SUB cma$thread_detach & ( & cma$t_thread BY REF & ) ! ! A thread may terminate it's own execution. ! EXTERNAL SUB cma$thread_exit_error ! ! Exit a thread normally. ! EXTERNAL SUB cma$thread_exit_normal & ( & cma$t_address BY REF & ) ! ! A thread can await termination of another thread and retrieve the return ! value and completion status of the thread. ! EXTERNAL SUB cma$thread_join & ( & cma$t_thread BY REF, & cma$t_exit_status BY REF, & cma$t_address BY REF & ) ! ! Operations to define thread creation attributes ! ! ! Set or obtain the default thread priority. ! EXTERNAL SUB cma$attr_set_priority & ( & cma$t_attr BY REF, & cma$t_priority BY REF & ) ! ! Obtain thread priority from attributes object. ! EXTERNAL SUB cma$attr_get_priority & ( & cma$t_attr BY REF, & cma$t_priority BY REF & ) ! ! Set or obtain the default scheduling algorithm. ! EXTERNAL SUB cma$attr_set_sched & ( & cma$t_attr BY REF, & cma$t_sched_policy BY REF & ) ! ! Get thread scheduling algorithm from attributes object. ! EXTERNAL SUB cma$attr_get_sched & ( & cma$t_attr BY REF, & cma$t_sched_policy BY REF & ) ! ! Set or obtain whether a thread will use the default scheduling attributes, ! or inherit them from the creating thread. ! EXTERNAL SUB cma$attr_set_inherit_sched & ( & cma$t_attr BY REF, & cma$t_sched_inherit BY REF & ) ! ! Obtain default scheduling attributes. ! EXTERNAL SUB cma$attr_get_inherit_sched & ( & cma$t_attr BY REF, & cma$t_sched_inherit BY REF & ) ! ! Set the default stack size ! EXTERNAL SUB cma$attr_set_stacksize & ( & cma$t_attr BY REF, & cma$t_natural BY REF & ) ! ! Obtain the default stack size. ! EXTERNAL SUB cma$attr_get_stacksize & ( & cma$t_attr BY REF, & cma$t_natural BY REF & ) ! ! Set the default guard size ! EXTERNAL SUB cma$attr_set_guardsize & ( & cma$t_attr BY REF, & cma$t_natural BY REF & ) ! ! Obtain the default guard size ! EXTERNAL SUB cma$attr_get_guardsize & ( & cma$t_attr BY REF, & cma$t_natural BY REF & ) ! ! Thread Scheduling Operations ! ! ! The current user_assigned priority of a thread can be changed. ! EXTERNAL SUB cma$thread_set_priority & ( & cma$t_thread BY REF, & cma$t_priority BY REF & ) ! ! The current user_assigned scheduler algorithm of a thread can be changed. ! EXTERNAL SUB cma$thread_set_sched & ( & cma$t_thread BY REF, & cma$t_sched_policy BY REF & ) ! ! A thread may tell the scheduler that its processor can be made available. ! EXTERNAL SUB cma$yield ! ! A thread may enter a wait state for a specifed period of time. ! EXTERNAL SUB cma$delay & ( & cma$t_interval BY VALUE & ) ! ! Thread Information Operations ! ! ! A thread may obtain a copy of its own thread handle. ! EXTERNAL SUB cma$thread_get_self & ( & cma$t_thread BY REF & ) ! ! The current user_assigned priority of a thread can be read. ! EXTERNAL SUB cma$thread_get_priority & ( & cma$t_thread BY REF, & cma$t_priority BY REF & ) ! ! The current user_assigned scheduler algorithm of a thread can be read. ! EXTERNAL SUB cma$thread_get_sched & ( & cma$t_thread BY REF, & cma$t_sched_policy BY REF & ) ! ! Operations on Mutexes ! ! ! Set whether mutex locks can nest. ! EXTERNAL SUB cma$attr_set_mutex_kind & ( & cma$t_attr BY REF, & cma$t_mutex_kind BY REF & ) ! ! Obtain whether mutex locks can nest. ! EXTERNAL SUB cma$attr_get_mutex_kind & ( & cma$t_attr BY REF, & cma$t_mutex_kind BY REF & ) ! ! The following routines create, delete, lock and unlock mutexes. ! EXTERNAL SUB cma$mutex_create & ( & cma$t_mutex BY REF, & cma$t_attr BY REF & ) ! ! Delete a mutex. ! EXTERNAL SUB cma$mutex_delete & ( & cma$t_mutex BY REF & ) ! ! Lock a mutex. ! EXTERNAL SUB cma$mutex_lock & ( & cma$t_mutex BY REF & ) ! ! Try to lock a mutex. ! EXTERNAL cma$t_boolean FUNCTION cma$mutex_try_lock & ( & cma$t_mutex BY REF & ) ! ! Unlock a mutex. ! EXTERNAL SUB cma$mutex_unlock & ( & cma$t_mutex BY REF & ) ! ! Lock Global mutex. ! EXTERNAL SUB cma$lock_global ! ! Unlock Global mutex. ! EXTERNAL SUB cma$unlock_global ! ! A thread can create and delete condition variables. ! EXTERNAL SUB cma$cond_create & ( & cma$t_cond BY REF, & cma$t_attr BY REF & ) ! ! Delete a condition variable. ! EXTERNAL SUB cma$cond_delete & ( & cma$t_cond BY REF & ) ! ! A thread can signal to and broadcast on a condition variable. ! EXTERNAL SUB cma$cond_broadcast & ( & cma$t_cond BY REF & ) ! ! Signal a condition variable. ! EXTERNAL SUB cma$cond_signal & ( & cma$t_cond BY REF & ) ! ! Interupt signal a condition variable. ! EXTERNAL SUB cma$cond_signal_int & ( & cma$t_cond BY REF & ) ! ! A thread can wait for a condition variable to be signalled or broadcast. ! EXTERNAL SUB cma$cond_wait & ( & cma$t_cond BY REF, & cma$t_mutex BY REF & ) ! ! Operations for timed waiting ! ! ! A thread can perform a timed wait on a condition variable. ! EXTERNAL cma$t_status FUNCTION cma$cond_timed_wait & ( & cma$t_cond BY REF, & cma$t_mutex BY REF, & cma$t_date_time BY REF & ) ! ! A thread may perform some operations on absolute date-time and intervals. ! EXTERNAL SUB cma$time_get_expiration & ( & cma$t_date_time BY REF, & cma$t_interval BY VALUE & ) ! ! Operations for CMA and client initialization. ! ! ! Initialize the CMA facility. ! EXTERNAL SUB cma$init ! ! A thread can declare a one-time initialization routine. The address of ! the init block and routine are passed as parameters. ! ! ! Once routine ! EXTERNAL SUB cma$once & ( & cma$t_address BY REF, & cma$t_init_routine BY REF & ) ! ! Operations for per-thread context ! ! ! A unique per-thread context key can be obtained for the process ! EXTERNAL SUB cma$key_create & ( & cma$t_key BY REF, & cma$t_attr BY REF, & cma$t_destructor BY REF & ) ! ! A thread can set a per-thread context value identified by a key. ! EXTERNAL SUB cma$key_set_context & ( & cma$t_key BY REF, & cma$t_address BY REF & ) ! ! A thread can retrieve a per-thread context value identified by a key. ! EXTERNAL SUB cma$key_get_context & ( & cma$t_key BY REF, & cma$t_address BY REF & ) ! ! Operations for alerts. ! ! ! The current thread can request that a thread terminate it's execution. ! EXTERNAL SUB cma$thread_alert & ( & cma$t_thread BY REF & ) ! ! The current thread can poll for alert delivery. ! EXTERNAL SUB cma$alert_test ! ! Control alert delivery state. ! EXTERNAL SUB cma$alert_disable_asynch & ( & cma$t_alert_state BY REF & ) EXTERNAL SUB cma$alert_disable_general & ( & cma$t_alert_state BY REF & ) EXTERNAL SUB cma$alert_enable_asynch EXTERNAL SUB cma$alert_enable_general & ( & cma$t_alert_state BY REF & ) EXTERNAL SUB cma$alert_restore & ( & cma$t_alert_state BY REF & ) ! ! Operations on stacks ! ! ! Assign a stack to a thread ! EXTERNAL SUB cma$stack_assign_np & ( & cma$t_stack_np BY REF, & cma$t_thread BY REF & ) ! ! Call a routine on a new stack ! EXTERNAL SUB cma$stack_call_routine_np & ( & cma$t_stack_np BY REF, & cma$t_call_routine BY REF, & cma$t_address BY REF, & cma$t_address BY REF & ) ! ! Check stack limit ! EXTERNAL cma$t_boolean FUNCTION cma$stack_check_limit_np & ( & cma$t_integer BY REF & ) ! ! Create a new stack ! EXTERNAL SUB cma$stack_create_np & ( & cma$t_stack_np BY REF, & cma$t_attr BY REF & ) ! ! Delete a stack ! EXTERNAL SUB cma$stack_delete_np & ( & cma$t_stack_np BY REF & ) ! ! CMA Debug entry point ! EXTERNAL SUB cma$debug ! ! Fetch the fp ! EXTERNAL cma$t_address FUNCTION cma$exc_fetch_fp ! ! Push an exception context ! EXTERNAL SUB cma$exc_push_ctx & ( & cma$t_address BY REF & ) EXTERNAL SUB cma$exc_pop_ctx & ( & cma$t_address BY REF & ) EXTERNAL SUB cma$exc_raise & ( & cma$t_address BY REF & ) EXTERNAL SUB cma$exc_raise_status & ( & cma$t_integer BY REF & ) EXTERNAL SUB cma$exc_report & ( & cma$t_address BY REF & ) EXTERNAL cma$t_integer FUNCTION cma$exc_handler EXTERNAL cma$t_integer FUNCTION cma$sigwait & ( & cma$t_address BY REF & ) ! ************************************************************************* ! ! The following are the portable CMA High-Level Library definitions ! ! ************************************************************************* ! ! Operations on attributes objects ! ! ! An attributes object is created to specify the attributes of other CMA ! objects that will be created. ! EXTERNAL SUB cma$lib_attr_create & ( & cma$lib_t_attr BY REF, & cma$lib_t_attr BY REF & ) ! ! An attributes object can be deleted when it is no longer needed. ! EXTERNAL SUB cma$lib_attr_delete & ( & cma$lib_t_attr BY REF & ) ! ! Operations on queues ! EXTERNAL SUB cma$lib_queue_create & ( & cma$lib_t_queue BY REF, & cma$lib_t_attr BY REF & ) EXTERNAL SUB cma$lib_queue_delete & ( & cma$lib_t_queue BY REF & ) EXTERNAL SUB cma$lib_queue_dequeue & ( & cma$lib_t_queue BY REF, & cma$t_address BY REF & ) EXTERNAL SUB cma$lib_queue_enqueue & ( & cma$lib_t_queue BY REF, & cma$t_address BY VALUE & ) EXTERNAL cma$t_boolean FUNCTION cma$lib_queue_try_enqueue_int & ( & cma$lib_t_queue BY REF, & cma$t_address BY VALUE & ) EXTERNAL SUB cma$lib_queue_requeue & ( & cma$lib_t_queue BY REF, & cma$t_address BY VALUE & ) EXTERNAL cma$t_boolean FUNCTION cma$lib_queue_try_dequeue & ( & cma$lib_t_queue BY REF, & cma$t_address BY REF & ) EXTERNAL cma$t_boolean FUNCTION cma$lib_queue_try_enqueue & ( & cma$lib_t_queue BY REF, & cma$t_address BY VALUE & ) EXTERNAL cma$t_boolean FUNCTION cma$lib_queue_try_requeue & ( & cma$lib_t_queue BY REF, & cma$t_address BY VALUE & ) ! ! Set or obtain the default queue size ! EXTERNAL SUB cma$lib_attr_get_queuesize & ( & cma$lib_t_attr BY REF, & cma$t_natural BY REF & ) EXTERNAL SUB cma$lib_attr_set_queuesize & ( & cma$lib_t_attr BY REF, & cma$t_natural BY VALUE & )