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