Enforce some minimum sleep value

This commit is contained in:
Raúl Marín 2024-05-14 16:55:19 +02:00
parent 525b3d9d61
commit 6254a4fe32

View File

@ -153,7 +153,7 @@ bool ThreadFuzzer::isEffective() const
return true; \
if (NAME##_before_sleep_probability.load(std::memory_order_relaxed) > 0.0) \
return true; \
if (NAME##_before_sleep_time_us_max.load(std::memory_order_relaxed) > 0.0) \
if (NAME##_before_sleep_time_us_max.load(std::memory_order_relaxed) > 0.001) \
return true; \
\
if (NAME##_after_yield_probability.load(std::memory_order_relaxed) > 0.0) \
@ -162,7 +162,7 @@ bool ThreadFuzzer::isEffective() const
return true; \
if (NAME##_after_sleep_probability.load(std::memory_order_relaxed) > 0.0) \
return true; \
if (NAME##_after_sleep_time_us_max.load(std::memory_order_relaxed) > 0.0) \
if (NAME##_after_sleep_time_us_max.load(std::memory_order_relaxed) > 0.001) \
return true;
FOR_EACH_WRAPPED_FUNCTION(CHECK_WRAPPER_PARAMS)
@ -170,7 +170,7 @@ bool ThreadFuzzer::isEffective() const
# undef INIT_WRAPPER_PARAMS
#endif
if (explicit_sleep_probability > 0 && sleep_time_us_max > 0)
if (explicit_sleep_probability > 0 && sleep_time_us_max > 0.001)
return true;
if (explicit_memory_exception_probability > 0)
@ -230,11 +230,9 @@ static void injectionImpl(
UNUSED(migrate_probability);
#endif
if (sleep_probability > 0
&& sleep_time_us_max > 0
&& std::bernoulli_distribution(sleep_probability)(thread_local_rng))
if (sleep_probability > 0 && sleep_time_us_max > 0.001 && std::bernoulli_distribution(sleep_probability)(thread_local_rng))
{
sleepForNanoseconds((thread_local_rng() % static_cast<uint64_t>(sleep_time_us_max * 1000))); /*may sleep(0)*/
sleepForNanoseconds((thread_local_rng() % static_cast<uint64_t>(sleep_time_us_max * 1000)));
}
}