From: Victor Julien Date: Tue, 10 Jun 2025 10:47:25 +0000 (+0200) Subject: time: replace usleep by SleepUsec/SleepMsec X-Git-Tag: suricata-8.0.0-rc1~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3f054b6258b4319a1322fe0e976f6cbb0dc3034;p=thirdparty%2Fsuricata.git time: replace usleep by SleepUsec/SleepMsec Helps cross platform support, esp Windows --- diff --git a/src/detect-engine.c b/src/detect-engine.c index 7c6e9c1363..bb9b41572d 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -2411,7 +2411,7 @@ retry: threads_done = no_of_detect_tvs; break; } - usleep(1000); + SleepMsec(1); if (SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) == 1) { SCLogDebug("new_det_ctx - %p used by detect engine", new_det_ctx[i]); threads_done++; @@ -2437,7 +2437,7 @@ retry: } while (!TmThreadsCheckFlag(tv, THV_RUNNING_DONE)) { - usleep(100); + SleepUsec(100); } } } diff --git a/src/flow-bypass.c b/src/flow-bypass.c index a57909c6ff..94e8afeba8 100644 --- a/src/flow-bypass.c +++ b/src/flow-bypass.c @@ -123,7 +123,7 @@ static TmEcode BypassedFlowManager(ThreadVars *th_v, void *thread_data) return TM_ECODE_OK; } StatsSyncCountersIfSignalled(th_v); - usleep(10000); + SleepMsec(10); } } return TM_ECODE_OK; diff --git a/src/flow-manager.c b/src/flow-manager.c index 26b9485652..0b074acb25 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -841,7 +841,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data) while (!TimeModeIsReady()) { if (suricata_ctl_flags != 0) return TM_ECODE_OK; - usleep(10); + SleepUsec(10); } bool run = TmThreadsWaitForUnpause(th_v); @@ -965,7 +965,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data) } if (emerg || !time_is_live) { - usleep(250); + SleepUsec(250); } else { struct timeval cond_tv; gettimeofday(&cond_tv, NULL); @@ -1145,7 +1145,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data) const bool emerg = (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY); if (emerg || !time_is_live) { - usleep(250); + SleepUsec(250); } else { struct timeval cond_tv; gettimeofday(&cond_tv, NULL); @@ -1240,7 +1240,7 @@ void FlowDisableFlowRecyclerThread(void) /* make sure all flows are processed */ do { FlowWakeupFlowRecyclerThread(); - usleep(10); + SleepUsec(10); } while (!FlowRecyclerReadyToShutdown()); SCMutexLock(&tv_root_lock); diff --git a/src/log-flush.c b/src/log-flush.c index f9ab98b068..8da1157df7 100644 --- a/src/log-flush.c +++ b/src/log-flush.c @@ -100,7 +100,7 @@ retry: threads_done = no_of_detect_tvs; break; } - usleep(1000); + SleepMsec(1); if (fw_threads[i] && FlowWorkerGetFlushAck(fw_threads[i])) { SCLogDebug("thread slot %d has ack'd flush request", i); threads_done++; @@ -164,7 +164,7 @@ static void *LogFlusherWakeupThread(void *arg) uint64_t worker_flush_count = 0; bool run = TmThreadsWaitForUnpause(tv_local); while (run) { - usleep(log_flush_sleep_time * 1000); + SleepMsec(log_flush_sleep_time); if (++wait_count == flush_wait_count) { worker_flush_count++; diff --git a/src/source-pcap.c b/src/source-pcap.c index cb520a2b49..b278aecb45 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -422,7 +422,7 @@ static TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot) int dbreak = 0; SCLogError("error code %" PRId32 " %s", r, pcap_geterr(ptv->pcap_handle)); do { - usleep(PCAP_RECONNECT_TIMEOUT); + SleepUsec(PCAP_RECONNECT_TIMEOUT); if (suricata_ctl_flags != 0) { dbreak = 1; break;