------------------------------------------------------------------------ -- Howard Eng 2/94 -- -- Unixpros, Inc. -- -- -- -- This package implements a semaphore. It is used for mutexes and -- -- condition variables. -- ------------------------------------------------------------------------ with SYSTEM; with TEXT_IO; package body DCE_ADA_SEMAPHORE is task body SEMAPHORE_TASK_TYPE is FINISHED : BOOLEAN := FALSE; WAIT_TIME : DURATION; CURR_TIME : CALENDAR.TIME; use CALENDAR; begin loop select accept WAKE_ONE; select accept WAIT; else NULL; end select; or accept WAKE_ALL; loop select accept WAIT; else exit; end select; end loop; or -- -- For the timed wait, T_OUT is the clock time that the thread should -- be released. The "accept" takes the difference between T_OUT and -- the current time to derive the maximum delay time. -- accept TIMED_WAIT( T_OUT : in CALENDAR.TIME ) do CURR_TIME := CALENDAR.CLOCK; if( CURR_TIME > T_OUT ) then WAIT_TIME := DURATION( 0 ); else WAIT_TIME := T_OUT - CURR_TIME; end if; select accept WAKE_ONE; or accept WAKE_ALL; loop select accept WAIT; else exit; end select; end loop; or delay WAIT_TIME; end select; end TIMED_WAIT; or accept STOP do loop select accept WAIT; else exit; end select; end loop; end STOP; FINISHED := TRUE; or -- when FINISHED => terminate; end select; end loop; end SEMAPHORE_TASK_TYPE; end DCE_ADA_SEMAPHORE;