xref: /freebsd/share/man/man3/pthread_spin_init.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1dec04f43SMike Makonnen.\" Copyright (c) 2004 Michael Telahun Makonnen
2dec04f43SMike Makonnen.\" All rights reserved.
3dec04f43SMike Makonnen.\"
4dec04f43SMike Makonnen.\" Redistribution and use in source and binary forms, with or without
5dec04f43SMike Makonnen.\" modification, are permitted provided that the following conditions
6dec04f43SMike Makonnen.\" are met:
7dec04f43SMike Makonnen.\" 1. Redistributions of source code must retain the above copyright
8dec04f43SMike Makonnen.\"    notice, this list of conditions and the following disclaimer.
9dec04f43SMike Makonnen.\" 2. Redistributions in binary form must reproduce the above copyright
10dec04f43SMike Makonnen.\"    notice, this list of conditions and the following disclaimer in the
11dec04f43SMike Makonnen.\"    documentation and/or other materials provided with the distribution.
12dec04f43SMike Makonnen.\"
13dec04f43SMike Makonnen.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14dec04f43SMike Makonnen.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15dec04f43SMike Makonnen.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16dec04f43SMike Makonnen.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17dec04f43SMike Makonnen.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18dec04f43SMike Makonnen.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19dec04f43SMike Makonnen.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20dec04f43SMike Makonnen.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21dec04f43SMike Makonnen.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22dec04f43SMike Makonnen.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23dec04f43SMike Makonnen.\" SUCH DAMAGE.
24dec04f43SMike Makonnen.\"
25*631e4e3aSJilles Tjoelker.Dd May 31, 2016
26715a0284SRuslan Ermilov.Dt PTHREAD_SPIN_INIT 3
27dec04f43SMike Makonnen.Os
28dec04f43SMike Makonnen.Sh NAME
29715a0284SRuslan Ermilov.Nm pthread_spin_init , pthread_spin_destroy
30dec04f43SMike Makonnen.Nd "initialize or destroy a spin lock"
31dec04f43SMike Makonnen.Sh LIBRARY
32dec04f43SMike Makonnen.Lb libpthread
33dec04f43SMike Makonnen.Sh SYNOPSIS
34dec04f43SMike Makonnen.In pthread.h
35dec04f43SMike Makonnen.Ft int
36dec04f43SMike Makonnen.Fn pthread_spin_init "pthread_spinlock_t *lock" "int pshared"
37dec04f43SMike Makonnen.Ft int
38dec04f43SMike Makonnen.Fn pthread_spin_destroy "pthread_spinlock_t *lock"
39dec04f43SMike Makonnen.Sh DESCRIPTION
40dec04f43SMike MakonnenThe
41dec04f43SMike Makonnen.Fn pthread_spin_init
42dec04f43SMike Makonnenfunction will initialize
43dec04f43SMike Makonnen.Fa lock
44dec04f43SMike Makonnento an unlocked state and
45dec04f43SMike Makonnenallocate any resources necessary to begin using it.
46dec04f43SMike MakonnenIf
47dec04f43SMike Makonnen.Fa pshared
48dec04f43SMike Makonnenis set to
49715a0284SRuslan Ermilov.Dv PTHREAD_PROCESS_SHARED ,
50dec04f43SMike Makonnenany thread,
51dec04f43SMike Makonnenwhether belonging to the process in which the spinlock was created or not,
52dec04f43SMike Makonnenthat has access to the memory area where
53dec04f43SMike Makonnen.Fa lock
54715a0284SRuslan Ermilovresides, can use
55dec04f43SMike Makonnen.Fa lock .
56dec04f43SMike MakonnenIf it is set to
57715a0284SRuslan Ermilov.Dv PTHREAD_PROCESS_PRIVATE ,
58dec04f43SMike Makonnenit can only be used by threads within the same process.
59dec04f43SMike Makonnen.Pp
60dec04f43SMike MakonnenThe
61dec04f43SMike Makonnen.Fn pthread_spin_destroy
62dec04f43SMike Makonnenfunction will destroy
63dec04f43SMike Makonnen.Fa lock
64dec04f43SMike Makonnenand release any resources that may have been allocated on its behalf.
65715a0284SRuslan Ermilov.Sh RETURN VALUES
66dec04f43SMike MakonnenIf successful,
67dec04f43SMike Makonnenboth
68dec04f43SMike Makonnen.Fn pthread_spin_init
69dec04f43SMike Makonnenand
70dec04f43SMike Makonnen.Fn pthread_spin_destroy
71dec04f43SMike Makonnenwill return zero.
72715a0284SRuslan ErmilovOtherwise, an error number will be returned to indicate the error.
73dec04f43SMike Makonnen.Pp
74715a0284SRuslan ErmilovNeither of these functions will return
75715a0284SRuslan Ermilov.Er EINTR .
76dec04f43SMike Makonnen.Sh ERRORS
77dec04f43SMike MakonnenThe
78dec04f43SMike Makonnen.Fn pthread_spin_init
79dec04f43SMike Makonnenand
80dec04f43SMike Makonnen.Fn pthread_spin_destroy
81dec04f43SMike Makonnenfunctions will fail if:
82dec04f43SMike Makonnen.Bl -tag -width Er
83dec04f43SMike Makonnen.It Bq Er EBUSY
84dec04f43SMike MakonnenAn attempt to initialize or destroy
85dec04f43SMike Makonnen.Fa lock
86dec04f43SMike Makonnenwhile it is in use.
87dec04f43SMike Makonnen.It Bq Er EINVAL
88dec04f43SMike MakonnenThe value specified by
89dec04f43SMike Makonnen.Fa lock
90dec04f43SMike Makonnenis invalid.
91dec04f43SMike Makonnen.El
92dec04f43SMike Makonnen.Pp
93dec04f43SMike MakonnenThe
94dec04f43SMike Makonnen.Fn pthread_spin_init
95dec04f43SMike Makonnenfunction will fail if:
96dec04f43SMike Makonnen.Bl -tag -width Er
97dec04f43SMike Makonnen.It Bq Er EAGAIN
98dec04f43SMike MakonnenInsufficient resources,
99dec04f43SMike Makonnenother than memory,
100dec04f43SMike Makonnento initialize
101dec04f43SMike Makonnen.Fa lock .
102dec04f43SMike Makonnen.It Bq Er ENOMEM
103dec04f43SMike MakonnenInsufficient memory to initialize
104dec04f43SMike Makonnen.Fa lock .
105dec04f43SMike Makonnen.El
106dec04f43SMike Makonnen.Sh SEE ALSO
107dec04f43SMike Makonnen.Xr pthread_spin_lock 3 ,
108dec04f43SMike Makonnen.Xr pthread_spin_unlock 3
109dec04f43SMike Makonnen.Sh HISTORY
110dec04f43SMike MakonnenThe
111dec04f43SMike Makonnen.Fn pthread_spin_init
112dec04f43SMike Makonnenand
113dec04f43SMike Makonnen.Fn pthread_spin_destroy
114dec04f43SMike Makonnenfunctions first appeared in
1153e9ed1efSRuslan Ermilov.Lb libkse
116dec04f43SMike Makonnenin
117dec04f43SMike Makonnen.Fx 5.2 ,
118dec04f43SMike Makonnenand in
119dec04f43SMike Makonnen.Lb libthr
120dec04f43SMike Makonnenin
121dec04f43SMike Makonnen.Fx 5.3 .
122*631e4e3aSJilles TjoelkerSupport for process-shared spinlocks appeared in
123*631e4e3aSJilles Tjoelker.Fx 11.0 .
124