1d3980376SJohn Polstra.\" 2d3980376SJohn Polstra.\" Copyright (c) 1999 John D. Polstra 3d3980376SJohn Polstra.\" All rights reserved. 4d3980376SJohn Polstra.\" 5d3980376SJohn Polstra.\" Redistribution and use in source and binary forms, with or without 6d3980376SJohn Polstra.\" modification, are permitted provided that the following conditions 7d3980376SJohn Polstra.\" are met: 8d3980376SJohn Polstra.\" 1. Redistributions of source code must retain the above copyright 9d3980376SJohn Polstra.\" notice, this list of conditions and the following disclaimer. 10d3980376SJohn Polstra.\" 2. Redistributions in binary form must reproduce the above copyright 11d3980376SJohn Polstra.\" notice, this list of conditions and the following disclaimer in the 12d3980376SJohn Polstra.\" documentation and/or other materials provided with the distribution. 13d3980376SJohn Polstra.\" 14d3980376SJohn Polstra.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15d3980376SJohn Polstra.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16d3980376SJohn Polstra.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17d3980376SJohn Polstra.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18d3980376SJohn Polstra.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19d3980376SJohn Polstra.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20d3980376SJohn Polstra.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21d3980376SJohn Polstra.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22d3980376SJohn Polstra.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23d3980376SJohn Polstra.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24d3980376SJohn Polstra.\" SUCH DAMAGE. 25d3980376SJohn Polstra.\" 26d3980376SJohn Polstra.\" $FreeBSD$ 27d3980376SJohn Polstra.\" 28d3980376SJohn Polstra.Dd December 26, 1999 29d3980376SJohn Polstra.Os FreeBSD 30d3980376SJohn Polstra.Dt DLLOCKINIT 3 31d3980376SJohn Polstra.Sh NAME 32d3980376SJohn Polstra.Nm dllockinit 33d3980376SJohn Polstra.Nd register thread locking methods with the dynamic linker 34d3980376SJohn Polstra.Sh SYNOPSIS 35d3980376SJohn Polstra.Fd #include <dlfcn.h> 36d3980376SJohn Polstra.Ft void 37a37e09e4SBruce Evans.Fn dllockinit "void *context" "void *(*lock_create)(void *context)" "void (*rlock_acquire)(void *lock)" "void (*wlock_acquire)(void *lock)" "void (*lock_release)(void *lock)" "void (*lock_destroy)(void *lock)" "void (*context_destroy)(void *context)" 38d3980376SJohn Polstra.Sh DESCRIPTION 39d3980376SJohn PolstraThreads packages can call 40d3980376SJohn Polstra.Nm 41d3980376SJohn Polstraat initialization time to register locking functions for the dynamic 42d3980376SJohn Polstralinker to use. This enables the dynamic linker to prevent multiple 43d3980376SJohn Polstrathreads from entering its critical sections simultaneously. 44d3980376SJohn Polstra.Pp 45d3980376SJohn PolstraThe 46d3980376SJohn Polstra.Fa context 47d3980376SJohn Polstraparameter specifies an opaque context for creating locks. The 48d3980376SJohn Polstradynamic linker will pass it to the 49d3980376SJohn Polstra.Fa lock_create 50d3980376SJohn Polstrafunction when creating the locks it needs. When the dynamic linker 51d3980376SJohn Polstrais permanently finished using the locking functions (e.g., if the 52d3980376SJohn Polstraprogram makes a subsequent call to 53d3980376SJohn Polstra.Nm 54d3980376SJohn Polstrato register new locking functions) it will call 55d3980376SJohn Polstra.Fa context_destroy 56d3980376SJohn Polstrato destroy the context. 57d3980376SJohn Polstra.Pp 58d3980376SJohn PolstraThe 59d3980376SJohn Polstra.Fa lock_create 60d3980376SJohn Polstraparameter specifies a function for creating a read/write lock. It 61d3980376SJohn Polstramust return a pointer to the new lock. 62d3980376SJohn Polstra.Pp 63d3980376SJohn PolstraThe 64d3980376SJohn Polstra.Fa rlock_acquire 65d3980376SJohn Polstraand 66d3980376SJohn Polstra.Fa wlock_acquire 67d3980376SJohn Polstraparameters specify functions which lock a lock for reading or 68d3980376SJohn Polstrawriting, respectively. The 69d3980376SJohn Polstra.Fa lock_release 70d3980376SJohn Polstraparameter specifies a function which unlocks a lock. Each of these 71d3980376SJohn Polstrafunctions is passed a pointer to the lock. 72d3980376SJohn Polstra.Pp 73d3980376SJohn PolstraThe 74d3980376SJohn Polstra.Fa lock_destroy 75d3980376SJohn Polstraparameter specifies a function to destroy a lock. It may be 76d3980376SJohn Polstra.Dv NULL 77d3980376SJohn Polstraif locks do not need to be destroyed. The 78d3980376SJohn Polstra.Fa context_destroy 797f205788SJohn Polstraparameter specifies a function to destroy the context. It may be 80d3980376SJohn Polstra.Dv NULL 81d3980376SJohn Polstraif the context does not need to be destroyed. 82d3980376SJohn Polstra.Pp 837f205788SJohn PolstraUntil 84d3980376SJohn Polstra.Nm 857f205788SJohn Polstrais called, the dynamic linker protects its critical sections using 867f205788SJohn Polstraa default locking mechanism which works by blocking the 87d3980376SJohn Polstra.Dv SIGVTALRM , 88d3980376SJohn Polstra.Dv SIGPROF , 89d3980376SJohn Polstraand 90d3980376SJohn Polstra.Dv SIGALRM 91d3980376SJohn Polstrasignals. This is sufficient for many application level threads 92d3980376SJohn Polstrapackages, which typically use one of these signals to implement 93d3980376SJohn Polstrapreemption. An application which has registered its own locking 94d3980376SJohn Polstramethods with 95d3980376SJohn Polstra.Nm 96d3980376SJohn Polstracan restore the default locking by calling 97d3980376SJohn Polstra.Nm 98d3980376SJohn Polstrawith all arguments 99d3980376SJohn Polstra.Dv NULL . 100d3980376SJohn Polstra.Sh SEE ALSO 101d3980376SJohn Polstra.Xr rtld 1 , 102d3980376SJohn Polstra.Xr signal 3 103d3980376SJohn Polstra.Sh HISTORY 104d3980376SJohn PolstraThe 105d3980376SJohn Polstra.Nm 106d3980376SJohn Polstrafunction first appeared in FreeBSD 4.0. 107