🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #10161

Re: Manx help

#10161
From: Michael "Ford" Ditto
Date: Fri, 28 Oct 1988 23:56
52 lines
2581 bytes
In article <5918@killer.DALLAS.TX.US> jdp@killer.DALLAS.TX.US (Jim Pritchett) writes:
>  Basically the problem is that although the test program below runs fine,
>the system becomes severely unstable and crashes within a couple of commands
 ...
>  struct FileLock *lockcd, *lockram;
 ...
>  lockram = Lock("ram:t", ACCESS_READ);
>  lockcd = CurrentDir(lockram);
 ...
>  UnLock(lockram);
>  lockram = CurrentDir(lockcd);
>
>  UnLock(lockcd);
>  UnLock(lockram);

Hmm... one call to Lock() and *three* calls to UnLock() .. a sure sign
that Something Bad will happen.

The problem is that you are unlocking your current directory.  Get rid
of the first two UnLock()'s and the function should work.

The basic idea behind CurrentDir() is that it "trades" locks with you --
you give it one and it gives you the one it had.  It completely forgets
about the one it had, and it expects you to "forget" about the one you
gave it; it is no longer your responsibility to unlock the new current
directory, but it is your responsibility to unlock the old one.  Because
it is a "trade", you can "trade it back" when you're done, and the net
effect is nil, so you only need to UnLock whatever you Locked.

Also note that in this particular case, you don't really care what you
temporarily set your CurrentDir to (I assume "ram:t" was an arbitrary
dummy object to pass to CurrentDir).  So, you can use the magic zero
lock; a lock of zero is always valid and need never be UnLocked.  So,
your code can be simplified to:

>  ULONG lockcd;

>  lockcd = CurrentDir((ULONG)0);	/* Steal the cd for a bit */
 [ ... do stuff with lockcd ... ]
>  (void)CurrentDir(lockcd);		/* Put it back */

Note that a lock is NOT the same as a (struct FileLock *); the return
value type of Lock() and CurrentDir() is ULONG.

Hope this helps.
-- 
					-=] Ford [=-

"The number of Unix installations	(In Real Life:  Mike Ditto)
has grown to 10, with more expected."	ford@kenobi.cts.com
- The Unix Programmer's Manual,		...!sdcsvax!crash!elgar!ford
  2nd Edition, June, 1972.		ditto@cbmvax.commodore.com
Technical Details
Message-ID: <5133@cbmvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!ucbvax!hplabs!pyramid!cbmvax!ditto
References: <5918@killer.DALLAS.TX.US>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!ucbvax!hplabs!pyramid!cbmvax!ditto
From: ditto@cbmvax.UUCP (Michael "Ford" Ditto)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Manx help
Summary: Too many UnLock()s
Keywords: Manx Aztec DOS Locks
Message-ID: <5133@cbmvax.UUCP>
Date: 28 Oct 88 23:56:59 GMT
References: <5918@killer.DALLAS.TX.US>
Reply-To: ditto@cbmvax.UUCP (Michael "Ford" Ditto)
Organization: Commodore Technology, West Chester, PA
Lines: 52