HPlogo HP-UX Reference Volume 4 of 5 > i

io_lock(3I)

Series 800 Only
» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

NAME

io_lock, io_unlock — lock and unlock an interface (OBSOLETED AT 10.30)

SYNOPSIS

#include <dvio.h>

int io_lock(int eid);

int io_unlock(int eid);

DESCRIPTION

iolock() 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 VALUE

io_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.

ERRORS

io_lock() and io_unlock() fail in the following situations, and set errno (see errno(2)) to the value indicated:

[EACCES]

An attempt was made to lock an interface locked by another process with O_NDELAY set.

[EBADF]

eid does not refer to an open file.

[EINTR]

A signal was caught while attempting to perform the lock with O_NDELAY clear.

[EINVAL]

an attempt was made to unlock when the interface is not locked.

[ETIMEDOUT]

A timeout occurred while attempting to perform the lock with O_NDELAY clear.

[ENOTTY]

eid does not refer to a channel device file.

[EPERM]

An attempt was made to unlock when lock is not owned by this user.

WARNINGS

io_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.

AUTHOR

io_lock() and io_unlock() were developed by HP.

© Hewlett-Packard Development Company, L.P.