lockc–Lock a resource
This function is used to lock a resource from access by another I-stream. If the lock is held by this I-stream, a dump is taken and the lock updated to show this occurrence. If the lock is held by another I-stream, the code will spin for a second or return a condition code depending on the t_lock_opt value. If the spin ends successfully, a catastrophic dump is taken. If the lock is free, this code will lock it.
Format
#include <tpf/tpfapi.h>
int lockc(void *lockword, enum t_lock_opt opt); - lockword
- A pointer to a lock made up of 2 consecutive fullwords used for lock and trace.
- opt
- One of 2 possible values directing the lockc function to either spin or return a condition code when the lock is held by another I-stream. The possible values of the enumeration type t_lock_opt are LOCK_O_SPIN and LOCK_O_RETN.
Normal return
Zero.
Error return
4 Lock is being held by another I-stream (for LOCK_O_RETN only)
Programming considerations
- The lock specified by lockword must not be held by this I-stream. If the lock is held, a 000572 system error will be issued and the lock held (for LOCK_O_SPIN only).
- Any other lock should not be held by this I-stream because a "lock-out" condition could occur. This implies that control must not be given up once a lock is held.
- A catastrophic dump will occur if the spin lock (LOCK_O_SPIN) times out (the 000571 system error).
Examples
The following example attempts
to lock an area in which the lock field is pointed to by table_lock_ptr.
The return condition is checked.
#include <tpf/tpfapi.h>
⋮
if (lockc(table_lock_ptr,LOCK_O_RETN)!=0)
⋮Related information
See z/TPF C functions overview for more information about z/TPF C/C++ language support.