From 420379aef6b11fba2a20aca34939cc9c4dc8733b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 15 Mar 2006 14:04:44 +0000 Subject: [PATCH] I should have finally fixed those app_server crashes in HWInterface::_DrawCursor(). Axel, even though we understood the problem, we didn't really fix it back then: When the sync flag was set to true in BView::SetViewCursor(), the link was only flushed, which means that the function still returned before the ServerWindow thread processed the message. This means that the race condition (the cursor being immediately deleted after SetViewCursor returns, which might be processed in ServerApp thread before the SetViewCursor request in ServerWindow thread) still existed. I changed SetViewCursor now to do a real sync (wait for the ServerWindow reply) before returning. The alternative would be to set the fPendingViewCursor flag in either case. Anyhow, I could reproduce the error quite reliably before this change, and now it is gone... here is to hoping! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16809 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/View.cpp | 11 +++++++++-- src/servers/app/ServerWindow.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index a68fb990eb..db08174242 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -1006,14 +1006,21 @@ BView::SetViewCursor(const BCursor *cursor, bool sync) fOwner->fLink->StartMessage(AS_LAYER_SET_CURSOR); fOwner->fLink->Attach(cursor->fServerToken); + fOwner->fLink->Attach(sync); if (!sync) { cursor->fPendingViewCursor = true; // this avoids a race condition in case the cursor is // immediately deleted after this call, as the deletion // is handled by the application, not the window - } else - fOwner->fLink->Flush(); + } else { + // make sure the server has processed the + // message and "acquired" the cursor in + // the window thread before returning from + // this function + int32 code; + fOwner->fLink->FlushWithReply(code); + } } diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 57456b9ce4..232d1af79f 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -1254,7 +1254,9 @@ ServerWindow::_DispatchViewMessage(int32 code, fCurrentLayer->Name())); int32 token; - if (link.Read(&token) != B_OK) + bool sync; + link.Read(&token); + if (link.Read(&sync) != B_OK) break; ServerCursor* cursor = fDesktop->GetCursorManager().FindCursor(token); @@ -1265,6 +1267,12 @@ ServerWindow::_DispatchViewMessage(int32 code, if (fDesktop->ViewUnderMouse(fWindowLayer) == fCurrentLayer->Token()) fServerApp->SetCurrentCursor(cursor); } + if (sync) { + // sync the client (it can now delete the cursor) + fLink.StartMessage(B_OK); + fLink.Flush(); + } + break; } case AS_LAYER_SET_FLAGS: