[haiku-appserver] deadlock

  • From: Adi Oanca <adioanca@xxxxxxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Sat, 25 Jun 2005 13:21:32 +0300


--- Begin Message ---
  • From: adioanca@xxxxxxxxxxxxx
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Sat, 25 Jun 2005 12:16:28 +0300 (EEST)
Hi,

   Stephan it appears the MultiLocker code introduced a deadlock.

here's the code to reproduce the bug. Yes, it's ugly, I know. :-)


   Can you please fix this?


Thanks!
#include <OS.h>
#include <Application.h>
#include <Window.h>
#include <View.h>
#include <Rect.h>
#include <Button.h>
#include <Point.h>
#include <stdio.h>

const int32             offset = 0;
int32   no = 0;

class MyView : public BView
{
public:
                                                        MyView(BRect, const 
char*, uint32, uint32);
        virtual void                    MouseDown(BPoint point);
        virtual void                    KeyDown(const char* bytes, int32 
numBytes);
        virtual void                    KeyUp(const char* bytes, int32 
numBytes);
        virtual void                    MouseUp(BPoint point);
        virtual void                    MouseMoved(     BPoint where,
                                                                                
uint32 code,
                                                                                
const BMessage *a_message);
        virtual void    MessageReceived(BMessage *message);
        virtual void                    Draw(BRect rect);
};

class MyApp : public BApplication
{
public:
        MyApp(void);
};

class MyWin : public BWindow
{
public:
                                        MyWin(BRect rect, const char *name, 
window_look look, window_feel feel, uint32 flags, uint32 wks);
        virtual void    MessageReceived(BMessage *message);
        virtual void    WindowActivated(bool state);
        virtual void    WorkspaceActivated(int32 ws, bool state);
        virtual void    WorkspacesChanged(uint32 oldws, uint32 newws);
private:
        MyView                  *view;
};

void MyView::Draw(BRect rect)
{
        StrokeLine(BPoint(20,20), BPoint(100,70));
}

MyView::MyView(BRect rect, const char* name, uint32 rm, uint32 flags)
        : BView(rect, name, rm, flags)
{
}

void MyView::MouseDown(BPoint point)
{
        SetMouseEventMask(B_POINTER_EVENTS);
        printf("%s Mouse Down: %f, %f\n", Name(), point.x, point.y);
}

void MyView::MouseUp(BPoint point)
{
        printf("%s Mouse UP: %f, %f\n", Name(), point.x, point.y);
}

void MyView::KeyDown(const char* bytes, int32 numBytes)
{
        printf("%s Key Down: %c\n", Name(), bytes[0]);
}

void MyView::KeyUp(const char* bytes, int32 numBytes)
{
        printf("%s Key UP: %c\n", Name(), bytes[0]);
}

void MyView::MouseMoved(BPoint where, uint32 code, const BMessage *a_message)
{
/*
        printf("%s Mouse Move, location %f,%f  code: ", Name(), where.x, 
where.y);
        switch(code)
        {
                case B_ENTERED_VIEW:
                        printf("B_ENTERED_VIEW\n");
                        break;
                case B_INSIDE_VIEW:
                        printf("B_INSIDE_VIEW\n");
                        break;
                case B_EXITED_VIEW:
                        printf("B_EXITED_VIEW\n");
                        break;
                case B_OUTSIDE_VIEW:
                        printf("B_OUTSIDE_VIEW\n");
                        break;
        }
*/
}

void MyView::MessageReceived(BMessage *message)
{
        if (message->what == B_MOUSE_WHEEL_CHANGED)
                printf("Adi: Wheel\n");
        else
                message->PrintToStream();
}

MyWin::MyWin(BRect rect, const char *name, window_look look, window_feel feel, 
uint32 flags, uint32 wks)
        : BWindow(rect, name, look, feel, flags, wks)
{
        rgb_color       c;
        c.red           = 23;
        c.green         = 59;
        c.blue          = 124;
        c.alpha         = 255;
        char            viewName[30];
        no++;
        sprintf(viewName, "view %ld", no);
        view = new MyView(Bounds().InsetByCopy(5,5),viewName, B_FOLLOW_NONE, 
B_WILL_DRAW | B_NAVIGABLE);
//      view = new MyView(BRect(50,20, 150,80),"bla", B_FOLLOW_NONE, 
B_WILL_DRAW | B_NAVIGABLE);
//      view->SetViewColor(c);
//      if (no!=3)
//      view->SetEventMask(B_POINTER_EVENTS);
//      view->Hide();
//      view->Show();
        AddChild(view);
//      view->Hide();
//      view->Show();
//      AddChild(new BButton(BRect(50,20,150, 80), "B", "Hit!", new 
BMessage(222)));
}

void MyWin::WindowActivated(bool state)
{
        printf("%s::WindowActivated(%s)\n", Name(), state == true? "true": 
"false");
}

void MyWin::WorkspaceActivated(int32 ws, bool state)
{
        printf("%s::WorkspaceActivated(%ld, %s)...\n", Name(), ws, state == 
true? "true": "false");
}

void MyWin::WorkspacesChanged(uint32 oldws, uint32 newws)
{
        printf("%s::WorkspaceActivated(%ld, %ld)...\n", Name(), oldws, newws);
        CurrentMessage()->PrintToStream();
}

void MyWin::MessageReceived(BMessage *message)
{
//      message->PrintToStream();
        BWindow::MessageReceived(message);
}

MyApp::MyApp(void)
 : BApplication("application/x-vnd.wgp-OBTestApp")
{
printf("Adi: MyApp\n");
        MyWin *win=new 
                MyWin(BRect(offset+100,100,offset+300,200),"NormalWindow1",
                B_DOCUMENT_WINDOW_LOOK,
//              B_NO_BORDER_WINDOW_LOOK,
                B_NORMAL_WINDOW_FEEL, 0, 0);
//                      B_FLOATING_APP_WINDOW_FEEL, 0);
        win->Show();

/*
        snooze(200000);
        win->MoveBy(25, 25);
        snooze(200000);
        win->MoveBy(25, 25);
        snooze(200000);
        win->MoveBy(25, 25);
        snooze(200000);
        win->MoveBy(25, 25);

        snooze(200000);
        win->MoveBy(-25, 25);
        snooze(200000);
        win->MoveBy(25, -25);
        snooze(200000);
        win->MoveBy(25, -25);
        snooze(200000);
        win->MoveBy(-25, 25);
*/

//      MyWin *win1=new 
//              MyWin(BRect(offset+200,200,offset+400,350),"FlaotingAllWindow",
//              B_DOCUMENT_WINDOW_LOOK,
//              B_NO_BORDER_WINDOW_LOOK,
//              B_NORMAL_WINDOW_FEEL, 0, 0);
//              B_FLOATING_ALL_WINDOW_FEEL, 0, 0);
//      win1->Show();

//      MyWin *win2=new 
//              
MyWin(BRect(offset+400,100,offset+600,200),"ModalAppWindow",B_DOCUMENT_WINDOW_LOOK,
//              B_NORMAL_WINDOW_FEEL, 0, 0);
//              B_FLOATING_APP_WINDOW_FEEL, 0);
//              B_MODAL_APP_WINDOW_FEEL, 0, 0);
//      win2->Show();

/*
        MyWin *win2=new 
                MyWin(BRect(offset+400,100,offset+600,200),"ZTestWindow3",
                B_DOCUMENT_WINDOW_LOOK,
                B_NORMAL_WINDOW_FEEL, 0, 0);
//                      B_FLOATING_APP_WINDOW_FEEL, 0);
//                      B_FLOATING_SUBSET_WINDOW_FEEL, 0);
//                      B_MODAL_SUBSET_WINDOW_FEEL, 0);
//                      B_MODAL_APP_WINDOW_FEEL, 0);
//                      B_FLOATING_ALL_WINDOW_FEEL, 0);
//                      B_MODAL_ALL_WINDOW_FEEL, 0,0);
        win2->Show();

//      win2->AddToSubset(win1);
*/
//      MyWin *win3=new 
//              
MyWin(BRect(offset+400,300,offset+600,400),"ZTestWindow4",B_DOCUMENT_WINDOW_LOOK,
//              B_NORMAL_WINDOW_FEEL,0);
//                      B_FLOATING_APP_WINDOW_FEEL, 0);
//                      B_FLOATING_SUBSET_WINDOW_FEEL, 0);
//                      B_MODAL_SUBSET_WINDOW_FEEL, 0, 0);
//                      B_MODAL_APP_WINDOW_FEEL, 0, 0x8UL);
//      snooze(2000000);
//      win3->Show();

//      win3->AddToSubset(win1);

//      snooze(2000000);
//      win->Hide();

//      snooze(2000000);
//      win->Show();

//      win->Lock();
//      win->Quit();
//      delete win;

//      win3->Show();
//      win1->SetWorkspaces(0x4UL);



//      win->SetWorkspaces(0x3UL);



//      snooze(2000000);
//      win2->Hide();
//      snooze(2000000);
//      win2->Show();

//      snooze(2000000);
//      win1->Hide();
//      snooze(2000000);
//      win1->Show();


}

int main(void)
{
        MyApp app;
        app.Run();
}

--- End Message ---

Other related posts: