void MessageManager::StartSocket(int socketFD, struct bufferevent *bufferevent) { //Initialize the MessageEndpoint if it doesn't yet exist Lock lock(&m_endpointsMutex); //If this socket doesn't even exist yet in the map, then it must be brand new if(m_endpoints.count(socketFD) == 0) { pthread_rwlock_t *rwLock = new pthread_rwlock_t; pthread_rwlock_init(rwLock, NULL); //Write lock this new lock because we don't want someone trying to read from it or write to it halfway through our addition Lock endLock(rwLock, WRITE_LOCK); m_endpoints[socketFD] = std::pair<MessageEndpoint*, pthread_rwlock_t*>( new MessageEndpoint(socketFD, bufferevent), rwLock); return; } //Write lock the message endpoint. Now we're allowed to access and write to it Lock endLock(m_endpoints[socketFD].second, WRITE_LOCK); if(m_endpoints[socketFD].first == NULL) { m_endpoints[socketFD].first = new MessageEndpoint(socketFD, bufferevent); } }
void NuPlayerVPPProcessor::seek() { LOGI("seek"); /* invoke thread if it is waiting */ if (mThreadRunning) { { Mutex::Autolock procLock(mProcThread->mLock); LOGV("got proc lock"); if (!hasProcessingBuffer()) { LOGI("seek done"); return; } mProcThread->mSeek = true; LOGV("set proc seek "); mProcThread->mRunCond.signal(); LOGV("wake up proc thread"); } Mutex::Autolock endLock(mProcThread->mEndLock); LOGI("waiting proc thread mEnd lock"); mProcThread->mEndCond.wait(mProcThread->mEndLock); LOGI("wake up from proc thread"); flushNoShutdown(); mLastInputTimeUs = -1; LOGI("seek done"); } }
void WidgetManager::onPose( Array<shared_ptr<Surface> >& posedArray, Array<shared_ptr<Surface2D> >& posed2DArray) { if (m_locked) { // This must be onPose for the GApp being invoked during an event callback // that fired during rendering. Avoid posing again during this period. return; } beginLock(); for (int i = 0; i < m_moduleArray.size(); ++i) { m_moduleArray[i]->onPose(posedArray, posed2DArray); } endLock(); }
bool WidgetManager::onEvent(const GEvent& event) { const bool motionEvent = (event.type == GEventType::MOUSE_MOTION) || (event.type == GEventType::JOY_AXIS_MOTION) || (event.type == GEventType::JOY_HAT_MOTION) || (event.type == GEventType::JOY_BALL_MOTION); const bool positionalEvent = (event.type == GEventType::MOUSE_BUTTON_CLICK) || (event.type == GEventType::MOUSE_BUTTON_DOWN) || (event.type == GEventType::MOUSE_BUTTON_UP) || (event.type == GEventType::MOUSE_MOTION); beginLock(); { // Deliver positional events in order of widget's depth preference if (positionalEvent) { const Point2& P = event.mousePosition(); // Find the distance at which object believes that it is for this event. By default, this is // the focus array position. Array<SortWrapper<shared_ptr<Widget> > > widgetWithZ; widgetWithZ.resize(m_moduleArray.size()); for (int i = 0; i < m_moduleArray.size(); ++i) { const shared_ptr<Widget>& w = m_moduleArray[i]; SortWrapper<shared_ptr<Widget> >& s = widgetWithZ[i]; s.value = w; s.key = w->positionalEventZ(P); if (isNaN(s.key)) { // The module wishes to use its focus position as a "Depth" if (w == m_focusedModule) { // Focused module gets priority and pretends that it is // higher than the first one s.key = float(m_moduleArray.size()); } else { s.key = float(i); } } // if default key } // for each widget widgetWithZ.sort(SORT_DECREASING); for (int i = 0; i < widgetWithZ.size(); ++i) { if (widgetWithZ[i].value->onEvent(event)) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } } else { // Except for motion events, ensure that the focused module gets each event first if (m_focusedModule && ! motionEvent) { if (m_focusedModule->onEvent(event)) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } for (int i = m_moduleArray.size() - 1; i >=0; --i) { // Don't double-deliver to the focused module if (motionEvent || (m_moduleArray[i] != m_focusedModule)) { if (m_moduleArray[i]->onEvent(event) && ! motionEvent) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } } } } endLock(); return false; }