master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
25#include "curl_threads.h"
26#include "curlx/timeval.h"
28#ifdef USE_THREADS
30#ifdef _WIN32
32curl_thread_t Curl_thread_create(
33 CURL_THREAD_RETURN_T(CURL_STDCALL *func)(void *), void *arg)
34{
35 curl_thread_t t = CreateThread(NULL, 0, func, arg, 0, NULL);
36 if(!t) {
37 DWORD gle = GetLastError();
38 /* !checksrc! disable ERRNOVAR 1 */
39 errno = (gle == ERROR_ACCESS_DENIED ||
40 gle == ERROR_NOT_ENOUGH_MEMORY) ?
41 EACCES : EINVAL;
42 return curl_thread_t_null;
43 }
44 return t;
45}
47void Curl_thread_destroy(curl_thread_t *hnd)
48{
49 if(*hnd != curl_thread_t_null) {
50 CloseHandle(*hnd);
51 *hnd = curl_thread_t_null;
52 }
53}
55int Curl_thread_join(curl_thread_t *hnd)
56{
57 int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0);
59 Curl_thread_destroy(hnd);
61 return ret;
62}
64#elif defined(HAVE_THREADS_POSIX)
66struct Curl_actual_call {
67 unsigned int (*func)(void *);
68 void *arg;
69};
71static void *curl_thread_create_thunk(void *arg)
72{
73 struct Curl_actual_call *ac = arg;
74 unsigned int (*func)(void *) = ac->func;
75 void *real_arg = ac->arg;
77 curlx_free(ac);
79 (*func)(real_arg);
81 return 0;
82}
84curl_thread_t Curl_thread_create(
85 CURL_THREAD_RETURN_T(CURL_STDCALL *func)(void *), void *arg)
86{
87 curl_thread_t t = curlx_malloc(sizeof(pthread_t));
88 struct Curl_actual_call *ac = NULL;
89 int rc;
91 if(t)
92 ac = curlx_malloc(sizeof(struct Curl_actual_call));
93 if(!(ac && t))
94 goto err;
96 ac->func = func;
97 ac->arg = arg;
99 rc = pthread_create(t, NULL, curl_thread_create_thunk, ac);
100 if(rc) {
101 errno = rc;
102 goto err;
103 }
105 return t;
107err:
108 curlx_free(t);
109 curlx_free(ac);
110 return curl_thread_t_null;
111}
113void Curl_thread_destroy(curl_thread_t *hnd)
114{
115 if(*hnd != curl_thread_t_null) {
116 pthread_detach(**hnd);
117 curlx_free(*hnd);
118 *hnd = curl_thread_t_null;
119 }
120}
122int Curl_thread_join(curl_thread_t *hnd)
123{
124 int ret = (pthread_join(**hnd, NULL) == 0);
126 curlx_free(*hnd);
127 *hnd = curl_thread_t_null;
129 return ret;
130}
132#else
133#error neither HAVE_THREADS_POSIX nor _WIN32 defined
134#endif
135#endif /* USE_THREADS */
137#ifdef USE_MUTEX
139#ifdef _WIN32
141void Curl_cond_signal(CONDITION_VARIABLE *c)
142{
143 WakeConditionVariable(c);
144}
146void Curl_cond_wait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m)
147{
148 SleepConditionVariableCS(c, m, INFINITE);
149}
151CURLcode Curl_cond_timedwait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m,
152 uint32_t timeout_ms)
153{
154 if(!SleepConditionVariableCS(c, m, (DWORD)timeout_ms)) {
155 DWORD err = GetLastError();
156 return (err == ERROR_TIMEOUT) ?
157 CURLE_OPERATION_TIMEDOUT : CURLE_UNRECOVERABLE_POLL;
158 }
159 return CURLE_OK;
160}
162curl_thread_id_t Curl_thread_get_current_id(void)
163{
164 return GetCurrentThreadId();
165}
167bool Curl_thread_is_current(curl_thread_id_t tid)
168{
169 return tid == GetCurrentThreadId();
170}
172#elif defined(HAVE_THREADS_POSIX)
174void Curl_cond_signal(pthread_cond_t *c)
175{
176 /* return code defined as always 0 */
177 (void)pthread_cond_signal(c);
178}
180void Curl_cond_wait(pthread_cond_t *c, pthread_mutex_t *m)
181{
182 /* return code defined as always 0 */
183 (void)pthread_cond_wait(c, m);
184}
186CURLcode Curl_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m,
187 uint32_t timeout_ms)
188{
189 struct curltime now;
190 struct timespec ts;
191 timediff_t usec;
192 int rc;
194 /* POSIX expects an "absolute" time until the condition wait ends.
195 * We cannot use `curlx_now()` here that may run on some monotonic clock
196 * that will be most likely in the past, as far as POSIX abstime is
197 * concerned. */
198#ifdef HAVE_GETTIMEOFDAY
199 struct timeval tv;
200 (void)gettimeofday(&tv, NULL);
201 now.tv_sec = tv.tv_sec;
202 now.tv_usec = (int)tv.tv_usec;
203#else
204 now.tv_sec = time(NULL);
205 now.tv_usec = 0;
206#endif
208 ts.tv_sec = now.tv_sec + (timeout_ms / 1000);
209 usec = now.tv_usec + ((timeout_ms % 1000) * 1000);
210 if(usec >= 1000000) {
211 ++ts.tv_sec;
212 usec %= 1000000;
213 }
214 ts.tv_nsec = (long)usec * 1000;
216 rc = pthread_cond_timedwait(c, m, &ts);
217 if(rc == SOCKETIMEDOUT)
218 return CURLE_OPERATION_TIMEDOUT;
219 return rc ? CURLE_UNRECOVERABLE_POLL : CURLE_OK;
220}
222curl_thread_id_t Curl_thread_get_current_id(void)
223{
224 return pthread_self();
225}
227bool Curl_thread_is_current(curl_thread_id_t tid)
228{
229 return !!pthread_equal(tid, pthread_self());
230}
232#else
233#error neither HAVE_THREADS_POSIX nor _WIN32 defined
234#endif
235#endif /* USE_MUTEX */
Diagnostics4 git calls · 33 ms
CallStatusSizeTime033 ms
discover200152 B5 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit5 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=5 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.0 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=2050 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=a5857b43b9c76c33519e23b0fdaeb47803f167d7 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2050 git.pkt.payload.max=2029 git.sideband.band1.bytes=2028 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e14d44394fa140
- Request
- 411834ef…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format