Skip to content

Commit

Permalink
Merge pull request #1435 from WebPlatformForEmbedded/pgorszkowski/2.3…
Browse files Browse the repository at this point in the history
…8/fix-bmalloc-hang-with-rt-thread-priorities

Workaround bmalloc hang with RT thread priorities.
  • Loading branch information
magomez authored Dec 11, 2024
2 parents a6a3fac + 8782ef0 commit 1667f9e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Source/bmalloc/bmalloc/Mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <mach/thread_switch.h>
#endif
#include <thread>
#include <unistd.h>

namespace bmalloc {

Expand All @@ -41,7 +42,23 @@ static inline void yield()
constexpr mach_msg_timeout_t timeoutInMS = 1;
thread_switch(MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, timeoutInMS);
#else
sched_yield();
static size_t bmallocMicrosecondsSleep;
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
const char* env = getenv("WEBKIT_WPE_BMALLOC_MICROSECONDS_SLEEP");
if (env) {
int value;
if (sscanf(env, "%d", &value) == 1 && value > 0)
bmallocMicrosecondsSleep = value;
}
});
if (bmallocMicrosecondsSleep) {
// The use of sched_yield() can lead to a system hang when real time
// thread priorities are used, so use sleep in the absence of a better
// alternative.
usleep(bmallocMicrosecondsSleep);
} else
sched_yield();
#endif
}

Expand Down

0 comments on commit 1667f9e

Please sign in to comment.