mirror of
https://github.com/curl/curl.git
synced 2026-08-25 17:33:32 +03:00
time-keeping: keep timestamp in multi, always update
Always use curlx_now() when calling Curl_pgrs_now(data). Tests with the "manual" updates to now proved differ more then 100ms in parallel testing. Add `curlx_nowp()` to set current time into a struct curltime. Add `curlx_ptimediff_ms() and friends, passing pointers. Update documentation. Closes #19998
This commit is contained in:
parent
308c347c8b
commit
b4be1f271e
61 changed files with 471 additions and 502 deletions
23
lib/psl.c
23
lib/psl.c
|
|
@ -29,6 +29,7 @@
|
|||
#ifdef USE_LIBPSL
|
||||
|
||||
#include "psl.h"
|
||||
#include "progress.h"
|
||||
#include "curl_share.h"
|
||||
|
||||
void Curl_psl_destroy(struct PslCache *pslcache)
|
||||
|
|
@ -41,25 +42,18 @@ void Curl_psl_destroy(struct PslCache *pslcache)
|
|||
}
|
||||
}
|
||||
|
||||
static time_t now_seconds(void)
|
||||
{
|
||||
struct curltime now = curlx_now();
|
||||
|
||||
return now.tv_sec;
|
||||
}
|
||||
|
||||
const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy)
|
||||
{
|
||||
struct PslCache *pslcache = easy->psl;
|
||||
const psl_ctx_t *psl;
|
||||
time_t now;
|
||||
time_t now_sec;
|
||||
|
||||
if(!pslcache)
|
||||
return NULL;
|
||||
|
||||
Curl_share_lock(easy, CURL_LOCK_DATA_PSL, CURL_LOCK_ACCESS_SHARED);
|
||||
now = now_seconds();
|
||||
if(!pslcache->psl || pslcache->expires <= now) {
|
||||
now_sec = Curl_pgrs_now(easy)->tv_sec;
|
||||
if(!pslcache->psl || pslcache->expires <= now_sec) {
|
||||
/* Let a chance to other threads to do the job: avoids deadlock. */
|
||||
Curl_share_unlock(easy, CURL_LOCK_DATA_PSL);
|
||||
|
||||
|
|
@ -67,8 +61,10 @@ const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy)
|
|||
Curl_share_lock(easy, CURL_LOCK_DATA_PSL, CURL_LOCK_ACCESS_SINGLE);
|
||||
|
||||
/* Recheck in case another thread did the job. */
|
||||
now = now_seconds();
|
||||
if(!pslcache->psl || pslcache->expires <= now) {
|
||||
if(pslcache->expires <= now_sec) {
|
||||
now_sec = Curl_pgrs_now(easy)->tv_sec;
|
||||
}
|
||||
if(!pslcache->psl || pslcache->expires <= now_sec) {
|
||||
bool dynamic = FALSE;
|
||||
time_t expires = TIME_T_MAX;
|
||||
|
||||
|
|
@ -76,7 +72,8 @@ const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy)
|
|||
psl = psl_latest(NULL);
|
||||
dynamic = psl != NULL;
|
||||
/* Take care of possible time computation overflow. */
|
||||
expires = now < TIME_T_MAX - PSL_TTL ? now + PSL_TTL : TIME_T_MAX;
|
||||
expires = (now_sec < TIME_T_MAX - PSL_TTL) ?
|
||||
(now_sec + PSL_TTL) : TIME_T_MAX;
|
||||
|
||||
/* Only get the built-in PSL if we do not already have the "latest". */
|
||||
if(!psl && !pslcache->dynamic)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue