💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › FAQs.and.INFO › GSOS › usefla… captured on 2023-03-20 at 22:50:50.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Newsgroups: comp.sys.apple2.programmer Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!wupost!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@actrix.gen.nz (David Empson) Subject: Re: Mut-ex outside GNO Message-ID: <CxK6vv.6sD@actrix.gen.nz> Organization: Actrix Information Exchange References: <375dg0$5gp@alpha.vaxxine.com> <377008$16t@gap.cco.caltech.edu> Date: Wed, 12 Oct 1994 12:04:42 GMT Lines: 69 In article <377008$16t@gap.cco.caltech.edu>, Nathan Mates <nathan@cco.caltech.edu> wrote: > > The best way to make sure that only one process is within a segment > is to use a varb, sort of like the busy flag. By setting the interrupt > flag in the P-reg, you can make sure that nobody else can tweak this > varb while you're checking it. Here's a short code snippet: > > * > * > CheckFlag start > * > * Returns cs if someone's already in the lib, cc if nobody was > * (and therefore a go-ahead to enter it) > * > php ;save old p-reg, including interrupt flag > sei ;nobody bother us. We're working. > lda MyFlag > bne WereBusy ;someone's in. Wait for it to be freed > inc MyFlag ;now, we're in control of the lib > plp ;restore old I > clc ;flag we got control > rts > > WereBusy plp ;restore old I > sec ;flag someone else's in it. > rts > end If you use something like TSB or TRB, you don't even need to disable interrupts. These instructions were specifically intended for use as indivisible flag test and manipulation (the standard mutex semaphone "test and set" operation). phb phk plb lda #1 tsb InUse ; Test bit 0 and set it beq Yippee ; If it was clear, we're in plb sec ; Otherwise, the routine is already in use. rts Yippee