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