Propeller Locks in PASM - what are LockNew and LockRet for?
Wossname
Posts: 174
What's the reasoning behind the LockNew and LockRet instructions? I guess you'd have to use them if you have more than 8 resources to guard, but is that the only reason?
If I only have 3 resources to guard, is it safe to omit LockNew and LockRet? I'd like to do away with them because I'm trying to free up a few lines of code space here and there in a particularly busy Cog running PASM code.
If I only have 3 resources to guard, is it safe to omit LockNew and LockRet? I'd like to do away with them because I'm trying to free up a few lines of code space here and there in a particularly busy Cog running PASM code.
Comments
It all depends on how you are sharing a resource. Have a look at FullDuplexSerial for a fine example of how it shares cyclic buffers between writer and reader processes. Because of the way it updates the head and tail pointers into those buffers data cannot become corrupted.
You can guard shared resources between a single reader and a single writer with simple flags as well.
It's risky to try to use both techniques in the same program. If you manually assign lock numbers in your program, don't use LOCKNEW and LOCKRET. If you use LOCKNEW and LOCKRET, don't use specific lock numbers. Similarly, if you use COGNEW, don't use COGINIT with the possible exception of using COGINIT to reload and restart a cog that you originally started with COGNEW (something that doesn't apply to locks).