1.\" Copyright (c) 2004 Michael Telahun Makonnen 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.\" Note: The date here should be updated whenever a non-trivial 28.\" change is made to the manual page. 29.Dd January 22, 2004 30.Dt PTHREAD_SPIN_LOCK 3 PTHREAD_SPIN_TRYLOCK 3 PTHREAD_SPIN_UNLOCK 3 31.Os 32.Sh NAME 33.Nm pthread_spin_lock pthread_spin_trylock pthread_spin_unlock 34.Nd "lock or unlock a spin lock" 35.Sh LIBRARY 36.Lb libpthread 37.Lb libthr 38.Sh SYNOPSIS 39.In pthread.h 40.Ft int 41.Fn pthread_spin_lock "pthread_spinlock_t *lock" 42.Ft int 43.Fn pthread_spin_trylock "pthread_spinlock_t *lock" 44.Ft int 45.Fn pthread_spin_unlock "pthread_spinlock_t *lock" 46.Sh DESCRIPTION 47The 48.Fn pthread_spin_lock 49function will acquire 50.Fa lock 51if it is not currently owned by another thread. 52If the lock cannot be acquired immediately it will 53spin attempting to acquire the lock (it will not sleep) until 54it becomes available. 55.Pp 56The 57.Fn pthread_spin_trylock 58function is the same as 59.Fn pthread_spin_lock 60except that if it cannot acquire 61.Fa lock 62immediately it will return with an error. 63.Pp 64The 65.Fn pthread_spin_unlock 66function will release 67.Fa lock , 68which must have been previously locked by a call to 69.Fn pthread_spin_lock 70or 71.Fn pthread_spin_trylock . 72.Sh DIAGNOSTICS 73If successful all these functions will return zero. 74Otherwise an error number will be returned to indicate the error. 75.Pp 76None of these functions will return EINTR. 77.Pp 78.Sh ERRORS 79The 80.Fn pthread_spin_lock , 81.Fn pthread_spin_trylock 82and 83.Fn pthread_spin_unlock 84functions will fail if: 85.Bl -tag -width Er 86.It Bq Er EINVAL 87The value specified by 88.Fa lock 89is invalid or is not initialized. 90.El 91.Pp 92The 93.Fn pthread_spin_lock 94function may fail if: 95.Bl -tag -width Er 96.It Bq Er EDEADLK 97The calling thread already owns the lock. 98.El 99.Pp 100The 101.Fn pthread_spin_trylock 102function will fail if: 103.Bl -tag -width Er 104.It Bq Er EBUSY 105Another thread currently holds 106.Fa lock . 107.El 108.Pp 109The 110.Fn pthread_spin_unlock 111function may fail if: 112.Bl -tag -width Er 113.It Bq Er EPERM 114The calling thread does not own 115.Fa lock . 116.El 117.Sh SEE ALSO 118.Xr pthread_spin_init 3 , 119.Xr pthread_spin_destroy 3 120.Sh HISTORY 121The 122.Fn pthread_spin_lock , 123.Fn pthread_spin_trylock 124and 125.Fn pthread_spin_unlock 126functions first appeared in 127.Lb libpthread 128in 129.Fx 5.2 , 130and in 131.Lb libthr 132in 133.Fx 5.3 . 134.Sh BUGS 135The implementation of 136.Fn pthread_spin_lock , 137.Fn pthread_spin_trylock 138and 139.Fn pthread_spin_unlock 140is expected to conform to 141.St -p1003.2 . 142