5 CRYPTO_set_locking_callback, CRYPTO_set_id_callback - OpenSSL thread support
9 #include <openssl/crypto.h>
11 void CRYPTO_set_locking_callback(void (*locking_function)(int mode,
12 int n, const char *file, int line));
14 void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
16 int CRYPTO_num_locks(void);
20 OpenSSL can safely be used in multi-threaded applications provided
21 that two callback functions are set.
23 locking_function(int mode, int n, const char *file, int line) is
24 needed to perform locking on shared data stuctures. Multi-threaded
25 applications will crash at random if it is not set.
27 locking_function() must be able to handle up to CRYPTO_num_locks()
28 different mutex locks. It sets the B<n>-th lock if B<mode> &
29 B<CRYPTO_LOCK>, and releases it otherwise.
31 B<file> and B<line> are the file number of the function setting the
32 lock. They can be useful for debugging.
34 id_function(void) is a function that returns a thread ID. It is not
35 needed on Windows nor on platforms where getpid() returns a different
36 ID for each thread (most notably Linux).
40 CRYPTO_num_locks() returns the required number of locks.
41 The other functions return no values.
45 You can find out if OpenSSL was configured with thread support:
47 #define OPENSSL_THREAD_DEFINES
48 #include <openssl/opensslconf.h>
50 // thread support enabled
57 B<crypto/threads/mttest.c> shows examples of the callback functions on
58 Solaris, Irix and Win32.
62 CRYPTO_set_locking_callback() and CRYPTO_set_id_callback() are
63 available in all versions of SSLeay and OpenSSL.
64 CRYPTO_num_locks() was added in OpenSSL 0.9.4.
68 L<crypto(3)|crypto(3)>