1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLSHOPT_LOCKFUNC
5Section: 3
6Source: libcurl
7See-also:
8  - CURLSHOPT_UNLOCKFUNC (3)
9  - curl_share_cleanup (3)
10  - curl_share_init (3)
11  - curl_share_setopt (3)
12Protocol:
13  - All
14Added-in: 7.10.3
15---
16
17# NAME
18
19CURLSHOPT_LOCKFUNC - mutex lock callback
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26void lockcb(CURL *handle, curl_lock_data data, curl_lock_access access,
27            void *clientp);
28
29CURLSHcode curl_share_setopt(CURLSH *share, CURLSHOPT_LOCKFUNC, lockcb);
30~~~
31
32# DESCRIPTION
33
34Set a mutex lock callback for the share object, to allow it to get used by
35multiple threads concurrently. There is a corresponding
36CURLSHOPT_UNLOCKFUNC(3) callback called when the mutex is again released.
37
38The *lockcb* argument must be a pointer to a function matching the
39prototype shown above. The arguments to the callback are:
40
41*handle* is the currently active easy handle in use when the share object
42is intended to get used.
43
44The *data* argument tells what kind of data libcurl wants to lock. Make
45sure that the callback uses a different lock for each kind of data.
46
47*access* defines what access type libcurl wants, shared or single.
48
49*clientp* is the private pointer you set with CURLSHOPT_USERDATA(3).
50This pointer is not used by libcurl itself.
51
52# %PROTOCOLS%
53
54# EXAMPLE
55
56~~~c
57extern void mutex_lock(CURL *handle, curl_lock_data data,
58                       curl_lock_access access, void *clientp);
59
60int main(void)
61{
62  CURLSHcode sh;
63  CURLSH *share = curl_share_init();
64  sh = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, mutex_lock);
65  if(sh)
66    printf("Error: %s\n", curl_share_strerror(sh));
67}
68~~~
69
70# %AVAILABILITY%
71
72# RETURN VALUE
73
74CURLSHE_OK (zero) means that the option was set properly, non-zero means an
75error occurred. See libcurl-errors(3) for the full list with
76descriptions.
77