1.\"	$OpenBSD: pthread_spin_lock.3,v 1.2 2013/06/05 03:44:50 tedu Exp $
2.\"
3.\" Copyright (c) 2012 Paul Irofti <pirofti@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.\"
18.Dd $Mdocdate: June 5 2013 $
19.Dt PTHREAD_SPIN_LOCK 3
20.Os
21.Sh NAME
22.Nm pthread_spin_lock ,
23.Nm pthread_spin_trylock
24.Nd lock a spinlock object
25.Sh SYNOPSIS
26.In pthread.h
27.Ft int
28.Fn pthread_spin_lock "pthread_spinlock_t *lock"
29.Ft int
30.Fn pthread_spin_trylock "pthread_spinlock_t *lock"
31.Sh DESCRIPTION
32The
33.Fn pthread_spin_lock
34function locks the spinlock referenced by
35.Fa lock .
36The calling thread will acquire the lock if it's not owned by another thread.
37Otherwise it will spin until the lock becomes available.
38.Pp
39The
40.Fn pthread_spin_trylock
41function will acquire the lock if the
42.Fa lock
43is not owned by another thread.
44Otherwise it will fail.
45.Sh RETURN VALUES
46If successful,
47.Fn pthread_spin_lock
48and
49.Fn pthread_spin_trylock
50return zero; otherwise an error number is returned to indicate the error.
51.Sh ERRORS
52.Fn pthread_spin_lock
53will fail if:
54.Bl -tag -width Er
55.It Bq Er EINVAL
56The value specified by
57.Fa lock
58is invalid.
59.It Bq Er EDEADLK
60A deadlock condition was detected.
61.El
62.Pp
63.Fn pthread_spin_trylock
64will fail if:
65.Bl -tag -width Er
66.It Bq Er EINVAL
67The value specified by
68.Fa lock
69is invalid.
70.It Bq Er EBUSY
71The lock is still in use.
72.It Bq Er EDEADLK
73A deadlock condition was detected.
74.El
75.Sh SEE ALSO
76.Xr pthread_spin_init 3 ,
77.Xr pthread_spin_unlock 3
78.Sh STANDARDS
79.Fn pthread_spin_lock
80and
81.Fn pthread_spin_trylock
82conform to
83.St -p1003.1-2008 .
84