Skip to content

Commit 1667f9e

Browse files
authored
Merge pull request #1435 from WebPlatformForEmbedded/pgorszkowski/2.38/fix-bmalloc-hang-with-rt-thread-priorities
Workaround bmalloc hang with RT thread priorities.
2 parents a6a3fac + 8782ef0 commit 1667f9e

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Source/bmalloc/bmalloc/Mutex.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <mach/thread_switch.h>
3333
#endif
3434
#include <thread>
35+
#include <unistd.h>
3536

3637
namespace 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

0 commit comments

Comments
 (0)