Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!apple!rcm From: rcm@Apple.COM (Robert Monsen) Newsgroups: comp.sys.mac.programmer Subject: Handles (was Re: HLock interdiction??) Keywords: MacTutor, Memory Manager, DogCow Message-ID: <10360@goofy.Apple.COM> Date: 21 Sep 90 20:00:41 GMT References: <1990Sep21.043054.24649@cunixf.cc.columbia.edu> <16451@unix.SRI.COM> Organization: Apple Computer Inc., Cupertino, CA Lines: 37 In article <16451@unix.SRI.COM> mxmora@unix.UUCP (Matt Mora) writes: [...] >You need to use Hgetstate/Hsetstate to keep the handle as it were. If you need >to lock a handle by all means do it. Just save the state of the handle before >hand and reset it back after you are done with it. Remeber that handles can >have more states than just being locked. Also you probably don't need to do >this with all handles, just the ones that you share with the ROM. Do it with all your handles. If you call a routine, it shouldn't have to know whether the caller has locked it. This can be the source of quite subtle bugs. Believe me, I've been burned by it more than once; because of that, I always use the following: /* File Lock.c */ typedef SignedByte HState; HState MyHLock(Handle h) { HState state = HGetState(h); HLock(h); return state; } void MyHUnlock(Handle h, HState state) { HSetState(h, state); } Lock the handles only when you are using them, and keep the state on the stack in an automatic variable. Believe me, you will be happier if you do. Bob Monsen Orion Network Systems Berkeley Ca.