File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232#include < mach/thread_switch.h>
3333#endif
3434#include < thread>
35+ #include < unistd.h>
3536
3637namespace bmalloc {
3738
@@ -41,7 +42,23 @@ static inline void yield()
4142 constexpr mach_msg_timeout_t timeoutInMS = 1 ;
4243 thread_switch (MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, timeoutInMS);
4344#else
44- sched_yield ();
45+ static size_t bmallocMicrosecondsSleep;
46+ static std::once_flag onceFlag;
47+ std::call_once (onceFlag, [] {
48+ const char * env = getenv (" WEBKIT_WPE_BMALLOC_MICROSECONDS_SLEEP" );
49+ if (env) {
50+ int value;
51+ if (sscanf (env, " %d" , &value) == 1 && value > 0 )
52+ bmallocMicrosecondsSleep = value;
53+ }
54+ });
55+ if (bmallocMicrosecondsSleep) {
56+ // The use of sched_yield() can lead to a system hang when real time
57+ // thread priorities are used, so use sleep in the absence of a better
58+ // alternative.
59+ usleep (bmallocMicrosecondsSleep);
60+ } else
61+ sched_yield ();
4562#endif
4663}
4764
You can’t perform that action at this time.
0 commit comments