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.\" 25dec04f43SMike Makonnen.\" $FreeBSD$ 26dec04f43SMike Makonnen.\" 27dec04f43SMike Makonnen.Dd January 22, 2004 28715a0284SRuslan Ermilov.Dt PTHREAD_SPIN_LOCK 3 29dec04f43SMike Makonnen.Os 30dec04f43SMike Makonnen.Sh NAME 31e825f576SRuslan Ermilov.Nm pthread_spin_lock , pthread_spin_trylock , pthread_spin_unlock 32dec04f43SMike Makonnen.Nd "lock or unlock a spin lock" 33dec04f43SMike Makonnen.Sh LIBRARY 34dec04f43SMike Makonnen.Lb libpthread 35dec04f43SMike Makonnen.Lb libthr 36dec04f43SMike Makonnen.Sh SYNOPSIS 37dec04f43SMike Makonnen.In pthread.h 38dec04f43SMike Makonnen.Ft int 39dec04f43SMike Makonnen.Fn pthread_spin_lock "pthread_spinlock_t *lock" 40dec04f43SMike Makonnen.Ft int 41dec04f43SMike Makonnen.Fn pthread_spin_trylock "pthread_spinlock_t *lock" 42dec04f43SMike Makonnen.Ft int 43dec04f43SMike Makonnen.Fn pthread_spin_unlock "pthread_spinlock_t *lock" 44dec04f43SMike Makonnen.Sh DESCRIPTION 45dec04f43SMike MakonnenThe 46dec04f43SMike Makonnen.Fn pthread_spin_lock 47dec04f43SMike Makonnenfunction will acquire 48dec04f43SMike Makonnen.Fa lock 49dec04f43SMike Makonnenif it is not currently owned by another thread. 50715a0284SRuslan ErmilovIf the lock cannot be acquired immediately, it will 51dec04f43SMike Makonnenspin attempting to acquire the lock (it will not sleep) until 52dec04f43SMike Makonnenit becomes available. 53dec04f43SMike Makonnen.Pp 54dec04f43SMike MakonnenThe 55dec04f43SMike Makonnen.Fn pthread_spin_trylock 56dec04f43SMike Makonnenfunction is the same as 57dec04f43SMike Makonnen.Fn pthread_spin_lock 58dec04f43SMike Makonnenexcept that if it cannot acquire 59dec04f43SMike Makonnen.Fa lock 60dec04f43SMike Makonnenimmediately it will return with an error. 61dec04f43SMike Makonnen.Pp 62dec04f43SMike MakonnenThe 63dec04f43SMike Makonnen.Fn pthread_spin_unlock 64dec04f43SMike Makonnenfunction will release 65dec04f43SMike Makonnen.Fa lock , 66dec04f43SMike Makonnenwhich must have been previously locked by a call to 67dec04f43SMike Makonnen.Fn pthread_spin_lock 68dec04f43SMike Makonnenor 69dec04f43SMike Makonnen.Fn pthread_spin_trylock . 70715a0284SRuslan Ermilov.Sh RETURN VALUES 71715a0284SRuslan ErmilovIf successful, all these functions will return zero. 72715a0284SRuslan ErmilovOtherwise, an error number will be returned to indicate the error. 73dec04f43SMike Makonnen.Pp 74715a0284SRuslan ErmilovNone of these functions will return 75715a0284SRuslan Ermilov.Er EINTR . 76dec04f43SMike Makonnen.Sh ERRORS 77dec04f43SMike MakonnenThe 78dec04f43SMike Makonnen.Fn pthread_spin_lock , 79dec04f43SMike Makonnen.Fn pthread_spin_trylock 80dec04f43SMike Makonnenand 81dec04f43SMike Makonnen.Fn pthread_spin_unlock 82dec04f43SMike Makonnenfunctions will fail if: 83dec04f43SMike Makonnen.Bl -tag -width Er 84dec04f43SMike Makonnen.It Bq Er EINVAL 85dec04f43SMike MakonnenThe value specified by 86dec04f43SMike Makonnen.Fa lock 87dec04f43SMike Makonnenis invalid or is not initialized. 88dec04f43SMike Makonnen.El 89dec04f43SMike Makonnen.Pp 90dec04f43SMike MakonnenThe 91dec04f43SMike Makonnen.Fn pthread_spin_lock 92dec04f43SMike Makonnenfunction may fail if: 93dec04f43SMike Makonnen.Bl -tag -width Er 94dec04f43SMike Makonnen.It Bq Er EDEADLK 95dec04f43SMike MakonnenThe calling thread already owns the lock. 96dec04f43SMike Makonnen.El 97dec04f43SMike Makonnen.Pp 98dec04f43SMike MakonnenThe 99dec04f43SMike Makonnen.Fn pthread_spin_trylock 100dec04f43SMike Makonnenfunction will fail if: 101dec04f43SMike Makonnen.Bl -tag -width Er 102dec04f43SMike Makonnen.It Bq Er EBUSY 103dec04f43SMike MakonnenAnother thread currently holds 104dec04f43SMike Makonnen.Fa lock . 105dec04f43SMike Makonnen.El 106dec04f43SMike Makonnen.Pp 107dec04f43SMike MakonnenThe 108dec04f43SMike Makonnen.Fn pthread_spin_unlock 109dec04f43SMike Makonnenfunction may fail if: 110dec04f43SMike Makonnen.Bl -tag -width Er 111dec04f43SMike Makonnen.It Bq Er EPERM 112dec04f43SMike MakonnenThe calling thread does not own 113dec04f43SMike Makonnen.Fa lock . 114dec04f43SMike Makonnen.El 115dec04f43SMike Makonnen.Sh SEE ALSO 116715a0284SRuslan Ermilov.Xr pthread_spin_destroy 3 , 117715a0284SRuslan Ermilov.Xr pthread_spin_init 3 118dec04f43SMike Makonnen.Sh HISTORY 119dec04f43SMike MakonnenThe 120dec04f43SMike Makonnen.Fn pthread_spin_lock , 121dec04f43SMike Makonnen.Fn pthread_spin_trylock 122dec04f43SMike Makonnenand 123dec04f43SMike Makonnen.Fn pthread_spin_unlock 124dec04f43SMike Makonnenfunctions first appeared in 125dec04f43SMike Makonnen.Lb libpthread 126dec04f43SMike Makonnenin 127dec04f43SMike Makonnen.Fx 5.2 , 128dec04f43SMike Makonnenand in 129dec04f43SMike Makonnen.Lb libthr 130dec04f43SMike Makonnenin 131dec04f43SMike Makonnen.Fx 5.3 . 132dec04f43SMike Makonnen.Sh BUGS 133dec04f43SMike MakonnenThe implementation of 134dec04f43SMike Makonnen.Fn pthread_spin_lock , 135dec04f43SMike Makonnen.Fn pthread_spin_trylock 136dec04f43SMike Makonnenand 137dec04f43SMike Makonnen.Fn pthread_spin_unlock 138dec04f43SMike Makonnenis expected to conform to 139dec04f43SMike Makonnen.St -p1003.2 . 140