#ifndef _COMMON_HATHREADS_H
#define _COMMON_HATHREADS_H
+#include <unistd.h>
+#ifdef _POSIX_PRIORITY_SCHEDULING
+#include <sched.h>
+#endif
+
#include <common/config.h>
#include <common/initcall.h>
{
}
+static inline void ha_thread_relax(void)
+{
+#if _POSIX_PRIORITY_SCHEDULING
+ sched_yield();
+#endif
+}
+
static inline void __ha_barrier_atomic_load(void)
{
}
tid_bit = (1UL << tid);
}
+static inline void ha_thread_relax(void)
+{
+#if _POSIX_PRIORITY_SCHEDULING
+ sched_yield();
+#else
+ pl_cpu_relax();
+#endif
+}
+
/* Marks the thread as harmless. Note: this must be true, i.e. the thread must
* not be touching any unprotected shared resource during this period. Usually
* this is called before poll(), but it may also be placed around very slow
{
_HA_ATOMIC_OR(&threads_harmless_mask, tid_bit);
while (threads_want_rdv_mask & all_threads_mask) {
-#if _POSIX_PRIORITY_SCHEDULING
- sched_yield();
-#else
- pl_cpu_relax();
-#endif
+ ha_thread_relax();
}
}
else if (_HA_ATOMIC_CAS(&threads_harmless_mask, &old, old & ~tid_bit))
break;
-#if _POSIX_PRIORITY_SCHEDULING
- sched_yield();
-#else
- pl_cpu_relax();
-#endif
+ ha_thread_relax();
}
/* one thread gets released at a time here, with its harmess bit off.
* The loss of this bit makes the other one continue to spin while the