kernel/user_mutex: Let single-threaded applications sleep on mutexes.
It seems some single-threaded applications do use them, which doesn't result in a deadlock because they use timeouts (or maybe wait on signals, too.)
This commit is contained in:
@@ -223,7 +223,8 @@ status_t
|
|||||||
allocate_team_user_mutex_context(Team* team)
|
allocate_team_user_mutex_context(Team* team)
|
||||||
{
|
{
|
||||||
team->AssertLocked();
|
team->AssertLocked();
|
||||||
ASSERT(team->user_mutex_context == NULL);
|
if (team->user_mutex_context != NULL)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
struct user_mutex_context* context = new(std::nothrow) user_mutex_context;
|
struct user_mutex_context* context = new(std::nothrow) user_mutex_context;
|
||||||
if (context == NULL)
|
if (context == NULL)
|
||||||
@@ -465,9 +466,15 @@ struct UserMutexContextFetcher {
|
|||||||
if (!fShared) {
|
if (!fShared) {
|
||||||
fContext = thread_get_current_thread()->team->user_mutex_context;
|
fContext = thread_get_current_thread()->team->user_mutex_context;
|
||||||
if (fContext == NULL) {
|
if (fContext == NULL) {
|
||||||
_user_debugger("single-threaded team attempted mutex operation");
|
// This should only happen for single-threaded applications (some
|
||||||
fInitStatus = EDEADLK;
|
// appear to use mutexes as a sleep mechanism), as the context gets
|
||||||
return;
|
// allocated on the creation of a second thread.
|
||||||
|
Team* team = thread_get_current_thread()->team;
|
||||||
|
team->Lock();
|
||||||
|
fInitStatus = allocate_team_user_mutex_context(team);
|
||||||
|
team->Unlock();
|
||||||
|
if (fInitStatus != B_OK)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fAddress = (addr_t)mutex;
|
fAddress = (addr_t)mutex;
|
||||||
|
|||||||
Reference in New Issue
Block a user