|
|
HP-UX Reference Volume 4 of 5 > iio_lock(3I)Series 800 Only |
|
NAMEio_lock, io_unlock — lock and unlock an interface (OBSOLETED AT 10.30) DESCRIPTIONiolock() attempts to lock the interface associated with an entity identifier for the requesting process. Locking an interface gives exclusive use of the interface associated with the eid to the requesting process, thus avoiding unintended interference from other processes during a series of separate I/O requests. All locks for a process are removed when the process closes the file or terminates. eid is an entity identifier of an open HP-IB, Centronics-compatible parallel, or GPIO device file, obtained from an open(), dup(), fcntl(), or creat() call (see open(2), dup(2), fcntl(2), and creat(2)). Other processes that attempt to access or lock a locked interface either return an error or sleep until the interface becomes unlocked. The action taken is determined by the current setting of the O_NDELAY flag (see open(2). If the O_NDELAY flag is set, accesses to a locked interface fail and set errno to indicate the error. If the O_NDELAY flag is not set, accesses to a locked interface block until the interface is unlocked, the current timeout expires, or the request is interrupted by a signal. A lock is associated with a process, not with an eid. Locking an interface with a particular eid does not prevent the process that owns the lock from accessing the interface through another eid. A lock associated with an eid is not inherited by a child process during a fork() (see fork(2)). Nested locking is fully supported. If a process owns a locked interface and calls a generic subroutine that does a lock and unlock, the calling process does not lose its lock on the interface. Locking requests produced by a given process for an interface already locked by the same process increment the current lock count for that interface. io_unlock() allows a process to remove a lock from the interface associated with the eid. A locked interface can be unlocked only by the process that directly owns the lock. When an unlock operation is applied to an eid that is currently multiply locked, the unlock operation decrements the current lock counter for that interface, and the interface remains locked until the count is reduced to zero. RETURN VALUEio_lock() and io_unlock() return the integer value of the current lock count if successful. A lock count greater than zero indicates that the interface is still locked. A lock count of zero indicates that the interface is no longer locked. A -1 indicates that an error has occurred. ERRORSio_lock() and io_unlock() fail in the following situations, and set errno (see errno(2)) to the value indicated:
WARNINGSio_lock() provides a mandatory lock enforced by the system, and should not be used with any interface supporting a system disk or swap device. Processes that lock HP-IB or GPIO interfaces should clear all locks before exiting. The driver attempts to clear them if the process terminates unexpectedly; however, a lock might be left outstanding if the locker dies after creating new file descriptors (via fork() or dup()) that refer to the same device file. Ensuring that all open file descriptors on a given interface are closed remedies the situation. |
|