Update openssl files to 1.0.1k
[msysgit.git] / ssl / man / man3 / CRYPTO_set_dynlock_lock_callback.3
blob1ea0ad054eba49c95748a9fbbf33030d12cc8829
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
131 .IX Title "threads 3"
132 .TH threads 3 "2015-01-08" "1.0.1k" "OpenSSL"
133 .SH "NAME"
134 CRYPTO_THREADID_set_callback, CRYPTO_THREADID_get_callback,
135 CRYPTO_THREADID_current, CRYPTO_THREADID_cmp, CRYPTO_THREADID_cpy,
136 CRYPTO_THREADID_hash, CRYPTO_set_locking_callback, CRYPTO_num_locks,
137 CRYPTO_set_dynlock_create_callback, CRYPTO_set_dynlock_lock_callback,
138 CRYPTO_set_dynlock_destroy_callback, CRYPTO_get_new_dynlockid,
139 CRYPTO_destroy_dynlockid, CRYPTO_lock \- OpenSSL thread support
140 .SH "SYNOPSIS"
141 .IX Header "SYNOPSIS"
142 .Vb 1
143 \& #include <openssl/crypto.h>
146 .Vb 17
147 \& /* Don't use this structure directly. */
148 \& typedef struct crypto_threadid_st
149 \&         {
150 \&         void *ptr;
151 \&         unsigned long val;
152 \&         } CRYPTO_THREADID;
153 \& /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */
154 \& void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val);
155 \& void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
156 \& int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *));
157 \& void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *);
158 \& void CRYPTO_THREADID_current(CRYPTO_THREADID *id);
159 \& int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a,
160 \&                         const CRYPTO_THREADID *b);
161 \& void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest,
162 \&                          const CRYPTO_THREADID *src);
163 \& unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);
166 .Vb 1
167 \& int CRYPTO_num_locks(void);
170 .Vb 2
171 \& /* struct CRYPTO_dynlock_value needs to be defined by the user */
172 \& struct CRYPTO_dynlock_value;
175 .Vb 7
176 \& void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *
177 \&        (*dyn_create_function)(char *file, int line));
178 \& void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)
179 \&        (int mode, struct CRYPTO_dynlock_value *l,
180 \&        const char *file, int line));
181 \& void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)
182 \&        (struct CRYPTO_dynlock_value *l, const char *file, int line));
185 .Vb 1
186 \& int CRYPTO_get_new_dynlockid(void);
189 .Vb 1
190 \& void CRYPTO_destroy_dynlockid(int i);
193 .Vb 1
194 \& void CRYPTO_lock(int mode, int n, const char *file, int line);
197 .Vb 10
198 \& #define CRYPTO_w_lock(type)    \e
199 \&        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
200 \& #define CRYPTO_w_unlock(type)  \e
201 \&        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
202 \& #define CRYPTO_r_lock(type)    \e
203 \&        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
204 \& #define CRYPTO_r_unlock(type)  \e
205 \&        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
206 \& #define CRYPTO_add(addr,amount,type)   \e
207 \&        CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
209 .SH "DESCRIPTION"
210 .IX Header "DESCRIPTION"
211 OpenSSL can safely be used in multi-threaded applications provided
212 that at least two callback functions are set, locking_function and
213 threadid_func.
215 locking_function(int mode, int n, const char *file, int line) is
216 needed to perform locking on shared data structures. 
217 (Note that OpenSSL uses a number of global data structures that
218 will be implicitly shared whenever multiple threads use OpenSSL.)
219 Multi-threaded applications will crash at random if it is not set.
221 \&\fIlocking_function()\fR must be able to handle up to \fICRYPTO_num_locks()\fR
222 different mutex locks. It sets the \fBn\fR\-th lock if \fBmode\fR &
223 \&\fB\s-1CRYPTO_LOCK\s0\fR, and releases it otherwise.
225 \&\fBfile\fR and \fBline\fR are the file number of the function setting the
226 lock. They can be useful for debugging.
228 threadid_func(\s-1CRYPTO_THREADID\s0 *id) is needed to record the currently-executing
229 thread's identifier into \fBid\fR. The implementation of this callback should not
230 fill in \fBid\fR directly, but should use \fICRYPTO_THREADID_set_numeric()\fR if thread
231 IDs are numeric, or \fICRYPTO_THREADID_set_pointer()\fR if they are pointer\-based.
232 If the application does not register such a callback using
233 \&\fICRYPTO_THREADID_set_callback()\fR, then a default implementation is used \- on
234 Windows and BeOS this uses the system's default thread identifying APIs, and on
235 all other platforms it uses the address of \fBerrno\fR. The latter is satisfactory
236 for thread-safety if and only if the platform has a thread-local error number
237 facility.
239 Once \fIthreadid_func()\fR is registered, or if the built-in default implementation is
240 to be used;
241 .IP "* \fICRYPTO_THREADID_current()\fR records the currently-executing thread \s-1ID\s0 into the given \fBid\fR object." 4
242 .IX Item "CRYPTO_THREADID_current() records the currently-executing thread ID into the given id object."
243 .PD 0
244 .IP "* \fICRYPTO_THREADID_cmp()\fR compares two thread IDs (returning zero for equality, ie. the same semantics as \fImemcmp()\fR)." 4
245 .IX Item "CRYPTO_THREADID_cmp() compares two thread IDs (returning zero for equality, ie. the same semantics as memcmp())."
246 .IP "* \fICRYPTO_THREADID_cpy()\fR duplicates a thread \s-1ID\s0 value," 4
247 .IX Item "CRYPTO_THREADID_cpy() duplicates a thread ID value,"
248 .IP "* \fICRYPTO_THREADID_hash()\fR returns a numeric value usable as a hash-table key. This is usually the exact numeric or pointer-based thread \s-1ID\s0 used internally, however this also handles the unusual case where pointers are larger than 'long' variables and the platform's thread IDs are pointer-based \- in this case, mixing is done to attempt to produce a unique numeric value even though it is not as wide as the platform's true thread IDs." 4
249 .IX Item "CRYPTO_THREADID_hash() returns a numeric value usable as a hash-table key. This is usually the exact numeric or pointer-based thread ID used internally, however this also handles the unusual case where pointers are larger than 'long' variables and the platform's thread IDs are pointer-based - in this case, mixing is done to attempt to produce a unique numeric value even though it is not as wide as the platform's true thread IDs."
252 Additionally, OpenSSL supports dynamic locks, and sometimes, some parts
253 of OpenSSL need it for better performance.  To enable this, the following
254 is required:
255 .IP "* Three additional callback function, dyn_create_function, dyn_lock_function and dyn_destroy_function." 4
256 .IX Item "Three additional callback function, dyn_create_function, dyn_lock_function and dyn_destroy_function."
257 .PD 0
258 .IP "* A structure defined with the data that each lock needs to handle." 4
259 .IX Item "A structure defined with the data that each lock needs to handle."
262 struct CRYPTO_dynlock_value has to be defined to contain whatever structure
263 is needed to handle locks.
265 dyn_create_function(const char *file, int line) is needed to create a
266 lock.  Multi-threaded applications might crash at random if it is not set.
268 dyn_lock_function(int mode, CRYPTO_dynlock *l, const char *file, int line)
269 is needed to perform locking off dynamic lock numbered n. Multi-threaded
270 applications might crash at random if it is not set.
272 dyn_destroy_function(CRYPTO_dynlock *l, const char *file, int line) is
273 needed to destroy the lock l. Multi-threaded applications might crash at
274 random if it is not set.
276 \&\fICRYPTO_get_new_dynlockid()\fR is used to create locks.  It will call
277 dyn_create_function for the actual creation.
279 \&\fICRYPTO_destroy_dynlockid()\fR is used to destroy locks.  It will call
280 dyn_destroy_function for the actual destruction.
282 \&\fICRYPTO_lock()\fR is used to lock and unlock the locks.  mode is a bitfield
283 describing what should be done with the lock.  n is the number of the
284 lock as returned from \fICRYPTO_get_new_dynlockid()\fR.  mode can be combined
285 from the following values.  These values are pairwise exclusive, with
286 undefined behaviour if misused (for example, \s-1CRYPTO_READ\s0 and \s-1CRYPTO_WRITE\s0
287 should not be used together):
289 .Vb 4
290 \&        CRYPTO_LOCK     0x01
291 \&        CRYPTO_UNLOCK   0x02
292 \&        CRYPTO_READ     0x04
293 \&        CRYPTO_WRITE    0x08
295 .SH "RETURN VALUES"
296 .IX Header "RETURN VALUES"
297 \&\fICRYPTO_num_locks()\fR returns the required number of locks.
299 \&\fICRYPTO_get_new_dynlockid()\fR returns the index to the newly created lock.
301 The other functions return no values.
302 .SH "NOTES"
303 .IX Header "NOTES"
304 You can find out if OpenSSL was configured with thread support:
306 .Vb 7
307 \& #define OPENSSL_THREAD_DEFINES
308 \& #include <openssl/opensslconf.h>
309 \& #if defined(OPENSSL_THREADS)
310 \&   // thread support enabled
311 \& #else
312 \&   // no thread support
313 \& #endif
316 Also, dynamic locks are currently not used internally by OpenSSL, but
317 may do so in the future.
318 .SH "EXAMPLES"
319 .IX Header "EXAMPLES"
320 \&\fBcrypto/threads/mttest.c\fR shows examples of the callback functions on
321 Solaris, Irix and Win32.
322 .SH "HISTORY"
323 .IX Header "HISTORY"
324 \&\fICRYPTO_set_locking_callback()\fR is
325 available in all versions of SSLeay and OpenSSL.
326 \&\fICRYPTO_num_locks()\fR was added in OpenSSL 0.9.4.
327 All functions dealing with dynamic locks were added in OpenSSL 0.9.5b\-dev.
328 \&\fB\s-1CRYPTO_THREADID\s0\fR and associated functions were introduced in OpenSSL 1.0.0
329 to replace (actually, deprecate) the previous \fICRYPTO_set_id_callback()\fR,
330 \&\fICRYPTO_get_id_callback()\fR, and \fICRYPTO_thread_id()\fR functions which assumed
331 thread IDs to always be represented by 'unsigned long'.
332 .SH "SEE ALSO"
333 .IX Header "SEE ALSO"
334 \&\fIcrypto\fR\|(3)