btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / packageinstaller / BlockingWindow.cpp
blob978d3558133587d4f892d5d759532d0cc1293ed6
1 /*
2 * Copyright (c) 2007-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 * Stephan Aßmus <superstippi@gmx.de>
8 */
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),
18 fSemaphore(-1),
19 fReturnValue(0)
24 BlockingWindow::~BlockingWindow()
29 bool
30 BlockingWindow::QuitRequested()
32 ReleaseSem(0);
33 return true;
37 int32
38 BlockingWindow::Go()
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) {
47 Quit();
48 return returnValue;
51 thread_id callingThread = find_thread(NULL);
52 BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(
53 callingThread));
54 Show();
56 if (window != NULL) {
57 // Make sure calling window thread, which is blocked here, is updating
58 // the window from time to time.
59 status_t ret;
60 for (;;) {
61 do {
62 ret = acquire_sem_etc(fSemaphore, 1, B_RELATIVE_TIMEOUT, 50000);
63 } while (ret == B_INTERRUPTED);
65 if (ret == B_BAD_SEM_ID)
66 break;
67 window->UpdateIfNeeded();
69 } else {
70 // Since there are no spinlocks, wait until the semaphore is free
71 while (acquire_sem(fSemaphore) == B_INTERRUPTED) {
75 returnValue = fReturnValue;
77 if (Lock())
78 Quit();
80 return returnValue;
84 void
85 BlockingWindow::ReleaseSem(int32 returnValue)
87 if (fSemaphore >= B_OK) {
88 delete_sem(fSemaphore);
89 fSemaphore = -1;
90 fReturnValue = returnValue;