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