]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi-notify: add check macro
authorStefan Eissing <stefan@eissing.org>
Fri, 19 Dec 2025 11:52:30 +0000 (12:52 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 20 Dec 2025 16:30:54 +0000 (17:30 +0100)
Since Curl_mntfy_dispatch_all() is called with high frequency and
mostly unnecessary, add a check macro to avoid the call when not
needed.

Closes #20034

lib/multi.c
lib/multi_ntfy.c
lib/multi_ntfy.h

index 22e89bb750573fd7c8e5bc4d3b40fe67f64980db..a24e511adc8367def1466a53ae99d311c707d444 100644 (file)
@@ -2798,7 +2798,7 @@ static CURLMcode multi_perform(struct Curl_multi *multi,
   if(multi_ischanged(multi, TRUE))
     process_pending_handles(multi);
 
-  if(!returncode)
+  if(!returncode && CURL_MNTFY_HAS_ENTRIES(multi))
     returncode = Curl_mntfy_dispatch_all(multi);
 
   /*
@@ -3195,7 +3195,7 @@ out:
   if(multi_ischanged(multi, TRUE))
     process_pending_handles(multi);
 
-  if(!mresult)
+  if(!mresult && CURL_MNTFY_HAS_ENTRIES(multi))
     mresult = Curl_mntfy_dispatch_all(multi);
 
   if(running_handles) {
index d4cdbe16c891ad6c4990b11e22b9a80ffcf65319..c41743719e924f7840a54528a0f47d08ba334758 100644 (file)
@@ -174,6 +174,7 @@ void Curl_mntfy_add(struct Curl_easy *data, unsigned int type)
       mntfy_chunk_append(tail, data, (uint32_t)type);
     else
       multi->ntfy.failure = CURLM_OUT_OF_MEMORY;
+    multi->ntfy.has_entries = TRUE;
   }
 }
 
@@ -201,5 +202,7 @@ CURLMcode Curl_mntfy_dispatch_all(struct Curl_multi *multi)
     multi->ntfy.failure = CURLM_OK; /* reset, once delivered */
     return mresult;
   }
+  else
+    multi->ntfy.has_entries = FALSE;
   return CURLM_OK;
 }
index 144d0319d0e6ddc5515b4bc3efef0ff97153ad77..2f1f34435756b9a9fe45a7596ff57f0399cbab19 100644 (file)
@@ -33,9 +33,10 @@ struct curl_multi_ntfy {
   curl_notify_callback ntfy_cb;
   void *ntfy_cb_data;
   struct uint32_bset enabled;
-  CURLMcode failure;
   struct mntfy_chunk *head;
   struct mntfy_chunk *tail;
+  CURLMcode failure;
+  BIT(has_entries);
 };
 
 void Curl_mntfy_init(struct Curl_multi *multi);
@@ -53,6 +54,8 @@ void Curl_mntfy_add(struct Curl_easy *data, unsigned int type);
       Curl_mntfy_add((d), (t));                       \
   } while(0)
 
+#define CURL_MNTFY_HAS_ENTRIES(m)       ((m)->ntfy.has_entries)
+
 CURLMcode Curl_mntfy_dispatch_all(struct Curl_multi *multi);
 
 #endif /* HEADER_CURL_MULTI_NTFY_H */