// Block until any event on any window is received. // No event is returned here! SVEvent* ScrollView::AwaitEventAnyWindow() { // Initialize the waiting semaphore. SVSemaphore* sem = new SVSemaphore(); std::pair<ScrollView*, SVEventType> ea((ScrollView*)nullptr, SVET_ANY); waiting_for_events_mu->Lock(); waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)nullptr); waiting_for_events_mu->Unlock(); // Wait on it. stream_->Flush(); sem->Wait(); // Process the event we got woken up for (its in waiting_for_events pair). waiting_for_events_mu->Lock(); SVEvent* ret = waiting_for_events[ea].second; waiting_for_events.erase(ea); waiting_for_events_mu->Unlock(); return ret; }
// Block until an event of the given type is received. // Note: The calling function is responsible for deleting the returned // SVEvent afterwards! SVEvent* ScrollView::AwaitEvent(SVEventType type) { // Initialize the waiting semaphore. SVSemaphore* sem = new SVSemaphore(); std::pair<ScrollView*, SVEventType> ea(this, type); mutex_waiting->Lock(); waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, NULL); mutex_waiting->Unlock(); // Wait on it, but first flush. stream_->Flush(); sem->Wait(); // Process the event we got woken up for (its in waiting_for_events pair). mutex_waiting->Lock(); SVEvent* ret = waiting_for_events[ea].second; waiting_for_events.erase(ea); mutex_waiting->Unlock(); return ret; }