jcs's openbsd hax
openbsd
1.\" $OpenBSD: pthread_spin_lock.3,v 1.4 2025/06/07 00:16:52 schwarze Exp $
2.\"
3.\" Copyright (c) 2012 Paul Irofti <paul@irofti.net>
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 7 2025 $
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.Lb libpthread
27.In pthread.h
28.Ft int
29.Fn pthread_spin_lock "pthread_spinlock_t *lock"
30.Ft int
31.Fn pthread_spin_trylock "pthread_spinlock_t *lock"
32.Sh DESCRIPTION
33The
34.Fn pthread_spin_lock
35function locks the spinlock referenced by
36.Fa lock .
37The calling thread will acquire the lock if it's not owned by another thread.
38Otherwise it will spin until the lock becomes available.
39.Pp
40The
41.Fn pthread_spin_trylock
42function will acquire the lock if the
43.Fa lock
44is not owned by another thread.
45Otherwise it will fail.
46.Sh RETURN VALUES
47If successful,
48.Fn pthread_spin_lock
49and
50.Fn pthread_spin_trylock
51return zero; otherwise an error number is returned to indicate the error.
52.Sh ERRORS
53.Fn pthread_spin_lock
54will fail if:
55.Bl -tag -width Er
56.It Bq Er EINVAL
57The value specified by
58.Fa lock
59is invalid.
60.It Bq Er EDEADLK
61A deadlock condition was detected.
62.El
63.Pp
64.Fn pthread_spin_trylock
65will fail if:
66.Bl -tag -width Er
67.It Bq Er EINVAL
68The value specified by
69.Fa lock
70is invalid.
71.It Bq Er EBUSY
72The lock is still in use.
73.It Bq Er EDEADLK
74A deadlock condition was detected.
75.El
76.Sh SEE ALSO
77.Xr pthread_spin_init 3 ,
78.Xr pthread_spin_unlock 3
79.Sh STANDARDS
80.Fn pthread_spin_lock
81and
82.Fn pthread_spin_trylock
83conform to
84.St -p1003.1-2008 .