_spin_init(3synch)


_spin_init -- initialize a spin lock

Synopsis

   cc [options] -Kthread file
   

#include <synch.h>

int _spin_init(spin_t *lock, void *arg);

Parameters


lock
pointer to spin lock to be initialized

arg
NULL (reserved for future use)

Description

_spin_init initializes the spin lock pointed to by lock to the unlocked state. Once initialized, the spin lock can be used any number of times without being re-initialized.

lock parameter

lock points to the spin lock to be initialized.

arg parameter

arg should be set to NULL. It is not currently used, but is reserved for future use.

Static spin lock initialization

In this implementation, a spin lock can be initialized statically if its storage is zero-filled. In this case, _spin_init need not be called.

Return values

_spin_init returns zero for success and an error number for failure.

Errors

If any the following conditions is detected, _spin_init returns the corresponding value:

EINVAL
invalid argument specified

Warnings

Spin locks should not be used on a single processor system. In the best case, a spin lock on a single processor system will waste resources, slowing down the owner of the lock; in the worst case, it will deadlock the processor.

_spin_init does not examine the lock argument before initializing it. If _spin_init is called more than once for the same spin lock, it will overwrite its state. It is the user's responsibility to ensure that _spin_init is only called once for each spin lock.

Operations on locks initialized with _spin_init are not recursive--a thread can deadlock if it attempts to relock a spin lock that it already has locked.

References

Intro(3synch), _spin(3synch), _spin_destroy(3synch), _spin_lock(3synch), _spin_trylock(3synch), _spin_unlock(3synch)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004