------------------------------------------------------------------ -- -- NAME: SEGMENT_SEMAPHORE - BODY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- file: segment_semaphore_b.ada -- level: 1c,2c package body SEGMENT_SEMAPHORE is -- This package provides semaphores to protect the integrity of -- segment storage in the multi-tasking environment of GKS at -- level C. task body SEMAPHORE is READERS : NATURAL; -- Number of readers currently accessing segment storage WRITERS : BOOLEAN; -- Whether or not a writer is accessing segment storage begin -- Initialize readers and writers to none READERS := 0; WRITERS := FALSE; -- loop until program terminates loop select -- a new reader is allowed as long as there are no writers --! when not WRITERS => accept READ_SEIZE do READERS := READERS + 1; end READ_SEIZE; or -- a reader is released if there are currently any active -- readers --! when READERS > 0 => accept READ_RELEASE do READERS := READERS - 1; end READ_RELEASE; or -- a new writer is allowed when there are no other readers -- or writers --! when not WRITERS and READERS = 0 => accept WRITE_SEIZE do WRITERS := TRUE; end WRITE_SEIZE; or -- a writer is released when there currently is an active -- writer --! when WRITERS => accept WRITE_RELEASE do WRITERS := FALSE; end WRITE_RELEASE; or -- allows termination of task with program completion terminate; end select; end loop; end SEMAPHORE; end SEGMENT_SEMAPHORE;