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