.TITLE LOCK .PSECT .PROG. .IDENT /01/ .ENABL LC ; ; P. Hays 2 February 79 ; ; Suspend lock a critical resource. ; int lock(efn) int efn; ; ; Efn specifies an event flag. ; The function blocks execution while the event flag is clear; if the flag ; is set at entry, this function clears it and returns 0. ; ; If one of the internal exec directives is rejected, the value ; of the directive status word is returned. ; ; User must set the flag when through using the resource, then declare ; a significant event. ; .mcall wtse$s, clef$s, drerr$ drerr$ ; Define DSW codes lock:: 1$: clr r0 ; Clear for valid return mov 2(sp),r1 ; r1 <- event flag number clef$s r1 ; Clear the flag, dsw <- previous value bcs 7$ ; complain if directive rejected -> cmp #IS.SET, @#$dsw ; Was the flag set? beq 9$ ; Y- allow entry to resource -> wtse$s r1 ; N- block task until it sets. bcc 1$ ; Fallthru on reject; else try again ^ 7$: mov @#$dsw, r0 ; Get dsw if directive rejected. 9$: return .end