xref: /freebsd/lib/libc/gen/dllockinit.3 (revision daf1cffce2e07931f27c6c6998652e90df6ba87e)
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 SYNOPSIS
35.Fd #include <dlfcn.h>
36.Ft void
37.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)"
38.Sh DESCRIPTION
39.Bf Sy
40This interface is experimental.  It may be changed or eliminated in
41future releases.
42.Ef
43.Pp
44Threads packages can call
45.Nm
46at initialization time to register locking functions for the dynamic
47linker to use.  This enables the dynamic linker to prevent multiple
48threads from entering its critical sections simultaneously.
49.Pp
50The
51.Fa context
52parameter specifies an opaque context for creating locks.  The
53dynamic linker will pass it to the
54.Fa lock_create
55function when creating the locks it needs.  When the dynamic linker
56is permanently finished using the locking functions (e.g., if the
57program makes a subsequent call to
58.Nm
59to register new locking functions) it will call
60.Fa context_destroy
61to destroy the context.
62.Pp
63The
64.Fa lock_create
65parameter specifies a function for creating a read/write lock.  It
66must return a pointer to the new lock.
67.Pp
68The
69.Fa rlock_acquire
70and
71.Fa wlock_acquire
72parameters specify functions which lock a lock for reading or
73writing, respectively.  The
74.Fa lock_release
75parameter specifies a function which unlocks a lock.  Each of these
76functions is passed a pointer to the lock.
77.Pp
78The
79.Fa lock_destroy
80parameter specifies a function to destroy a lock.  It may be
81.Dv NULL
82if locks do not need to be destroyed.  The
83.Fa context_destroy
84parameter specifies a function to destroy the context.  It may be
85.Dv NULL
86if the context does not need to be destroyed.
87.Pp
88Until
89.Nm
90is called, the dynamic linker protects its critical sections using
91a default locking mechanism which works by blocking the
92.Dv SIGVTALRM ,
93.Dv SIGPROF ,
94and
95.Dv SIGALRM
96signals.  This is sufficient for many application level threads
97packages, which typically use one of these signals to implement
98preemption.  An application which has registered its own locking
99methods with
100.Nm
101can restore the default locking by calling
102.Nm
103with all arguments
104.Dv NULL .
105.Sh SEE ALSO
106.Xr rtld 1 ,
107.Xr signal 3
108.Sh HISTORY
109The
110.Nm
111function first appeared in FreeBSD 4.0.
112