1d3980376SJohn Polstra.\" 24e1635feSJohn Polstra.\" Copyright (c) 1999, 2000 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 3425bb73e0SAlexey Zelkin.Sh LIBRARY 3525bb73e0SAlexey Zelkin.Lb libc 36d3980376SJohn Polstra.Sh SYNOPSIS 37d3980376SJohn Polstra.Fd #include <dlfcn.h> 38d3980376SJohn Polstra.Ft void 39a37e09e4SBruce 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)" 40d3980376SJohn Polstra.Sh DESCRIPTION 414e1635feSJohn Polstra.Bf Sy 424e1635feSJohn PolstraThis interface is experimental. It may be changed or eliminated in 434e1635feSJohn Polstrafuture releases. 444e1635feSJohn Polstra.Ef 454e1635feSJohn Polstra.Pp 46d3980376SJohn PolstraThreads packages can call 47d3980376SJohn Polstra.Nm 48d3980376SJohn Polstraat initialization time to register locking functions for the dynamic 49d3980376SJohn Polstralinker to use. This enables the dynamic linker to prevent multiple 50d3980376SJohn Polstrathreads from entering its critical sections simultaneously. 51d3980376SJohn Polstra.Pp 52d3980376SJohn PolstraThe 53d3980376SJohn Polstra.Fa context 54d3980376SJohn Polstraparameter specifies an opaque context for creating locks. The 55d3980376SJohn Polstradynamic linker will pass it to the 56d3980376SJohn Polstra.Fa lock_create 57d3980376SJohn Polstrafunction when creating the locks it needs. When the dynamic linker 58d3980376SJohn Polstrais permanently finished using the locking functions (e.g., if the 59d3980376SJohn Polstraprogram makes a subsequent call to 60d3980376SJohn Polstra.Nm 61d3980376SJohn Polstrato register new locking functions) it will call 62d3980376SJohn Polstra.Fa context_destroy 63d3980376SJohn Polstrato destroy the context. 64d3980376SJohn Polstra.Pp 65d3980376SJohn PolstraThe 66d3980376SJohn Polstra.Fa lock_create 67d3980376SJohn Polstraparameter specifies a function for creating a read/write lock. It 68d3980376SJohn Polstramust return a pointer to the new lock. 69d3980376SJohn Polstra.Pp 70d3980376SJohn PolstraThe 71d3980376SJohn Polstra.Fa rlock_acquire 72d3980376SJohn Polstraand 73d3980376SJohn Polstra.Fa wlock_acquire 74d3980376SJohn Polstraparameters specify functions which lock a lock for reading or 75d3980376SJohn Polstrawriting, respectively. The 76d3980376SJohn Polstra.Fa lock_release 77d3980376SJohn Polstraparameter specifies a function which unlocks a lock. Each of these 78d3980376SJohn Polstrafunctions is passed a pointer to the lock. 79d3980376SJohn Polstra.Pp 80d3980376SJohn PolstraThe 81d3980376SJohn Polstra.Fa lock_destroy 82d3980376SJohn Polstraparameter specifies a function to destroy a lock. It may be 83d3980376SJohn Polstra.Dv NULL 84d3980376SJohn Polstraif locks do not need to be destroyed. The 85d3980376SJohn Polstra.Fa context_destroy 867f205788SJohn Polstraparameter specifies a function to destroy the context. It may be 87d3980376SJohn Polstra.Dv NULL 88d3980376SJohn Polstraif the context does not need to be destroyed. 89d3980376SJohn Polstra.Pp 907f205788SJohn PolstraUntil 91d3980376SJohn Polstra.Nm 927f205788SJohn Polstrais called, the dynamic linker protects its critical sections using 937f205788SJohn Polstraa default locking mechanism which works by blocking the 94d3980376SJohn Polstra.Dv SIGVTALRM , 95d3980376SJohn Polstra.Dv SIGPROF , 96d3980376SJohn Polstraand 97d3980376SJohn Polstra.Dv SIGALRM 98d3980376SJohn Polstrasignals. This is sufficient for many application level threads 99d3980376SJohn Polstrapackages, which typically use one of these signals to implement 100d3980376SJohn Polstrapreemption. An application which has registered its own locking 101d3980376SJohn Polstramethods with 102d3980376SJohn Polstra.Nm 103d3980376SJohn Polstracan restore the default locking by calling 104d3980376SJohn Polstra.Nm 105d3980376SJohn Polstrawith all arguments 106d3980376SJohn Polstra.Dv NULL . 107d3980376SJohn Polstra.Sh SEE ALSO 108d3980376SJohn Polstra.Xr rtld 1 , 109d3980376SJohn Polstra.Xr signal 3 110d3980376SJohn Polstra.Sh HISTORY 111d3980376SJohn PolstraThe 112d3980376SJohn Polstra.Nm 113d3980376SJohn Polstrafunction first appeared in FreeBSD 4.0. 114