2 * Copyright (c) 2007-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 * Stephan Aßmus <superstippi@gmx.de>
11 #include "PackageImageViewer.h"
14 BlockingWindow::BlockingWindow(BRect frame
, const char* title
, uint32 flags
)
16 BWindow(frame
, title
, B_MODAL_WINDOW
,
17 B_NOT_ZOOMABLE
| B_NOT_RESIZABLE
| B_NOT_CLOSABLE
| flags
),
24 BlockingWindow::~BlockingWindow()
30 BlockingWindow::QuitRequested()
40 int32 returnValue
= 0;
42 // Since this class can be thought of as a modified BAlert window, no use
43 // to reinvent a well fledged wheel. This concept has been borrowed from
44 // the current BAlert implementation
45 fSemaphore
= create_sem(0, "PackageInstaller BlockingWindow");
46 if (fSemaphore
< B_OK
) {
51 thread_id callingThread
= find_thread(NULL
);
52 BWindow
* window
= dynamic_cast<BWindow
*>(BLooper::LooperForThread(
57 // Make sure calling window thread, which is blocked here, is updating
58 // the window from time to time.
62 ret
= acquire_sem_etc(fSemaphore
, 1, B_RELATIVE_TIMEOUT
, 50000);
63 } while (ret
== B_INTERRUPTED
);
65 if (ret
== B_BAD_SEM_ID
)
67 window
->UpdateIfNeeded();
70 // Since there are no spinlocks, wait until the semaphore is free
71 while (acquire_sem(fSemaphore
) == B_INTERRUPTED
) {
75 returnValue
= fReturnValue
;
85 BlockingWindow::ReleaseSem(int32 returnValue
)
87 if (fSemaphore
>= B_OK
) {
88 delete_sem(fSemaphore
);
90 fReturnValue
= returnValue
;