xref: /openbsd-src/lib/libpthread/man/pthread_spin_lock.3 (revision 8855e28c066fcedf8b2ce6df476d3f9b3d0ee8f9)
1*8855e28cSpirofti.\"	$OpenBSD: pthread_spin_lock.3,v 1.3 2020/04/06 00:01:08 pirofti Exp $
25037ac14Spirofti.\"
3*8855e28cSpirofti.\" Copyright (c) 2012 Paul Irofti <paul@irofti.net>
45037ac14Spirofti.\"
55037ac14Spirofti.\" Permission to use, copy, modify, and distribute this software for any
65037ac14Spirofti.\" purpose with or without fee is hereby granted, provided that the above
75037ac14Spirofti.\" copyright notice and this permission notice appear in all copies.
85037ac14Spirofti.\"
95037ac14Spirofti.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
105037ac14Spirofti.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
115037ac14Spirofti.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
125037ac14Spirofti.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
135037ac14Spirofti.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
145037ac14Spirofti.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
155037ac14Spirofti.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165037ac14Spirofti.\"
175037ac14Spirofti.\"
18*8855e28cSpirofti.Dd $Mdocdate: April 6 2020 $
195037ac14Spirofti.Dt PTHREAD_SPIN_LOCK 3
205037ac14Spirofti.Os
215037ac14Spirofti.Sh NAME
225037ac14Spirofti.Nm pthread_spin_lock ,
235037ac14Spirofti.Nm pthread_spin_trylock
245037ac14Spirofti.Nd lock a spinlock object
255037ac14Spirofti.Sh SYNOPSIS
2686f9d4cdStedu.In pthread.h
275037ac14Spirofti.Ft int
285037ac14Spirofti.Fn pthread_spin_lock "pthread_spinlock_t *lock"
295037ac14Spirofti.Ft int
305037ac14Spirofti.Fn pthread_spin_trylock "pthread_spinlock_t *lock"
315037ac14Spirofti.Sh DESCRIPTION
325037ac14SpiroftiThe
335037ac14Spirofti.Fn pthread_spin_lock
345037ac14Spiroftifunction locks the spinlock referenced by
355037ac14Spirofti.Fa lock .
365037ac14SpiroftiThe calling thread will acquire the lock if it's not owned by another thread.
375037ac14SpiroftiOtherwise it will spin until the lock becomes available.
385037ac14Spirofti.Pp
395037ac14SpiroftiThe
405037ac14Spirofti.Fn pthread_spin_trylock
415037ac14Spiroftifunction will acquire the lock if the
425037ac14Spirofti.Fa lock
435037ac14Spiroftiis not owned by another thread.
445037ac14SpiroftiOtherwise it will fail.
455037ac14Spirofti.Sh RETURN VALUES
465037ac14SpiroftiIf successful,
475037ac14Spirofti.Fn pthread_spin_lock
485037ac14Spiroftiand
495037ac14Spirofti.Fn pthread_spin_trylock
505037ac14Spiroftireturn zero; otherwise an error number is returned to indicate the error.
515037ac14Spirofti.Sh ERRORS
525037ac14Spirofti.Fn pthread_spin_lock
535037ac14Spiroftiwill fail if:
545037ac14Spirofti.Bl -tag -width Er
555037ac14Spirofti.It Bq Er EINVAL
565037ac14SpiroftiThe value specified by
575037ac14Spirofti.Fa lock
585037ac14Spiroftiis invalid.
595037ac14Spirofti.It Bq Er EDEADLK
605037ac14SpiroftiA deadlock condition was detected.
615037ac14Spirofti.El
625037ac14Spirofti.Pp
635037ac14Spirofti.Fn pthread_spin_trylock
645037ac14Spiroftiwill fail if:
655037ac14Spirofti.Bl -tag -width Er
665037ac14Spirofti.It Bq Er EINVAL
675037ac14SpiroftiThe value specified by
685037ac14Spirofti.Fa lock
695037ac14Spiroftiis invalid.
705037ac14Spirofti.It Bq Er EBUSY
715037ac14SpiroftiThe lock is still in use.
725037ac14Spirofti.It Bq Er EDEADLK
735037ac14SpiroftiA deadlock condition was detected.
745037ac14Spirofti.El
755037ac14Spirofti.Sh SEE ALSO
765037ac14Spirofti.Xr pthread_spin_init 3 ,
775037ac14Spirofti.Xr pthread_spin_unlock 3
785037ac14Spirofti.Sh STANDARDS
795037ac14Spirofti.Fn pthread_spin_lock
805037ac14Spiroftiand
815037ac14Spirofti.Fn pthread_spin_trylock
825037ac14Spirofticonform to
835037ac14Spirofti.St -p1003.1-2008 .
84