/* Wait for an event to occur on the dispatcher and service the event. This is not called by mprServiceEvents. The dispatcher may be "started" and owned by the thread, or it may be unowned. WARNING: the event may have already happened by the time this API is invoked. WARNING: this will enable GC while sleeping. */ PUBLIC int mprWaitForEvent(MprDispatcher *dispatcher, MprTicks timeout, int64 mark) { MprEventService *es; MprTicks expires, delay; int runEvents, changed; if (dispatcher == NULL) { dispatcher = MPR->dispatcher; } if (dispatcher->flags & MPR_DISPATCHER_DESTROYED) { return 0; } if ((runEvents = (dispatcher->owner == mprGetCurrentOsThread())) != 0) { /* Called from an event on a running dispatcher */ assert(isRunning(dispatcher) || (dispatcher->flags & MPR_DISPATCHER_DESTROYED)); if (dispatchEvents(dispatcher)) { return 0; } } es = MPR->eventService; es->now = mprGetTicks(); expires = timeout < 0 ? MPR_MAX_TIMEOUT : (es->now + timeout); if (expires < 0) { expires = MPR_MAX_TIMEOUT; } delay = expires - es->now; lock(es); delay = getDispatcherIdleTicks(dispatcher, delay); dispatcher->flags |= MPR_DISPATCHER_WAITING; changed = dispatcher->mark != mark && mark != -1; unlock(es); if (changed) { return 0; } mprYield(MPR_YIELD_STICKY); mprWaitForCond(dispatcher->cond, delay); mprResetYield(); es->now = mprGetTicks(); lock(es); dispatcher->flags &= ~MPR_DISPATCHER_WAITING; unlock(es); if (runEvents) { dispatchEvents(dispatcher); assert(isRunning(dispatcher) || (dispatcher->flags & MPR_DISPATCHER_DESTROYED)); } return 0; }
void UEventsManager::mainLoop() { postEventSem_.acquire(); if(!this->isKilled()) { dispatchEvents(); } }
void EventRouter::collectEndDispatchEvents() { Event *pEvent = nullptr; while ((pEvent = EventRouter::pollEvent()) != nullptr) { postEvent(pEvent); } dispatchEvents(); }
/** \fn NMEventManager::eventLoop() \brief Begin the main event loop. */ void NMEventManager::runLoop() { if( m_exit) return; cout << "EventLoop runnning" << '\n'; while( !m_exit) { activateSockets(); activateExternals(); activateTimers(); dispatchEvents(); usleep(500); } }
void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow) { if (!hasScheduledItems()) return; RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); callMediaQueryListListeners(); dispatchEvents(); executeCallbacks(monotonicTimeNow); scheduleAnimationIfNeeded(); }
void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow) { if (!m_callbacks.size() && !m_eventQueue.size()) return; if (m_suspendCount) return; RefPtr<ScriptedAnimationController> protect(this); dispatchEvents(); executeCallbacks(monotonicTimeNow); scheduleAnimationIfNeeded(); }
void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow) { if (m_callbackCollection.isEmpty() && !m_eventQueue.size() && !m_mediaQueryListListeners.size()) return; if (m_suspendCount) return; RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); callMediaQueryListListeners(); dispatchEvents(); executeCallbacks(monotonicTimeNow); scheduleAnimationIfNeeded(); }
/* Run events for a dispatcher in a worker thread. When complete, reschedule the dispatcher as required. */ static void dispatchEventsWorker(MprDispatcher *dispatcher) { if (dispatcher->flags & MPR_DISPATCHER_DESTROYED) { /* Dispatcher destroyed after worker started */ return; } dispatcher->owner = mprGetCurrentOsThread(); dispatchEvents(dispatcher); assert(dispatcher->owner == 0 || dispatcher->owner == mprGetCurrentOsThread()); dispatcher->owner = 0; if (!(dispatcher->flags & MPR_DISPATCHER_DESTROYED)) { dequeueDispatcher(dispatcher); mprScheduleDispatcher(dispatcher); } }
Text::Text(Screen *screen) : QObject(screen) , m_screen(screen) , m_text_line(0) , m_start_index(0) , m_old_start_index(0) , m_end_index(0) , m_line(0) , m_old_line(0) , m_width(1) , m_style_dirty(true) , m_text_dirty(true) , m_visible(true) , m_visible_old(true) , m_forgroundColor(m_screen->defaultForgroundColor()) , m_backgroundColor(m_screen->defaultBackgroundColor()) { connect(m_screen->colorPalette(), SIGNAL(changed()), this, SLOT(paletteChanged())); connect(m_screen, SIGNAL(dispatchTextSegmentChanges()), this, SLOT(dispatchEvents())); }
void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow) { WTF_LOG(ScriptedAnimationController, "serviceScriptedAnimations: #callbacks = %d, #events = %d, #mediaQueryListListeners = %d, count = %d", static_cast<int>(m_callbacks.size()), static_cast<int>(m_eventQueue.size()), static_cast<int>(m_mediaQueryListListeners.size()), m_suspendCount); if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListeners.size()) return; if (m_suspendCount) return; RefPtr<ScriptedAnimationController> protect(this); callMediaQueryListListeners(); dispatchEvents(); executeCallbacks(monotonicTimeNow); scheduleAnimationIfNeeded(); }
int bpclock(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { #else int main(int argc, char *argv[]) { #endif Sdr sdr; BpDB *bpConstants; int state = 1; time_t currentTime; if (bpAttach() < 0) { putErrmsg("bpclock can't attach to BP.", NULL); return 1; } sdr = getIonsdr(); bpConstants = getBpConstants(); isignal(SIGTERM, shutDown); /* Main loop: wait for event occurrence time, then * execute applicable events. */ oK(_running(&state)); writeMemo("[i] bpclock is running."); while (_running(NULL)) { /* Sleep for 1 second, then dispatch all events * whose executions times have now been reached. */ snooze(1); currentTime = getUTCTime(); if (dispatchEvents(sdr, bpConstants->timeline, currentTime) < 0) { putErrmsg("Can't dispatch events.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Also adjust throttles in response to rate * changes noted in the shared ION database. */ if (adjustThrottles() < 0) { putErrmsg("Can't adjust throttles.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Then apply rate control. */ applyRateControl(sdr); } writeErrmsgMemos(); writeMemo("[i] bpclock has ended."); ionDetach(); return 0; }
int ltpclock(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { #else int main(int argc, char *argv[]) { #endif Sdr sdr; LtpDB *ltpConstants; int state = 1; time_t currentTime; if (ltpInit(0, 0) < 0) { putErrmsg("ltpclock can't initialize LTP.", NULL); return 1; } sdr = getIonsdr(); ltpConstants = getLtpConstants(); isignal(SIGTERM, shutDown); /* Main loop: wait for event occurrence time, then * execute applicable events. */ oK(_running(&state)); writeMemo("[i] ltpclock is running."); while (_running(NULL)) { /* Sleep for 1 second, then dispatch all events * whose executions times have now been reached. */ snooze(1); currentTime = getUTCTime(); /* Infer link state changes from rate changes * noted in the shared ION database. */ if (manageLinks(sdr, currentTime) < 0) { putErrmsg("Can't manage links.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Then dispatch retransmission events, as * constrained by the new link state. */ if (dispatchEvents(sdr, ltpConstants->timeline, currentTime) < 0) { putErrmsg("Can't dispatch events.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } } writeErrmsgMemos(); writeMemo("[i] ltpclock has ended."); ionDetach(); return 0; }
void ScriptedAnimationController::dispatchEventsAndCallbacksForPrinting() { dispatchEvents(EventNames::MediaQueryListEvent); callMediaQueryListListeners(); }
int main() { constexpr auto width = 1200u; constexpr auto height = 800u; // init ny app auto& backend = ny::Backend::choose(); if(!backend.vulkan()) { dlg_error("ny backend has no vulkan support!"); return 0; } auto ac = backend.createAppContext(); // basic vpp init auto iniExtensions = ac->vulkanExtensions(); iniExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); vk::ApplicationInfo appInfo ("vpp-intro", 1, "vpp", 1, VK_API_VERSION_1_0); vk::InstanceCreateInfo instanceInfo; instanceInfo.pApplicationInfo = &appInfo; instanceInfo.enabledExtensionCount = iniExtensions.size(); instanceInfo.ppEnabledExtensionNames = iniExtensions.data(); #ifdef WithLayers constexpr auto layer = "VK_LAYER_LUNARG_standard_validation"; instanceInfo.enabledLayerCount = 1; instanceInfo.ppEnabledLayerNames = &layer; #endif vpp::Instance instance(instanceInfo); #ifdef WithLayers vpp::DebugCallback debugCallback(instance); #endif // ny init auto run = true; auto listener = MyWindowListener {}; listener.run = &run; auto vkSurface = vk::SurfaceKHR {}; auto ws = ny::WindowSettings {}; ws.surface = ny::SurfaceType::vulkan; ws.listener = &listener; ws.size = {width, height}; ws.vulkan.instance = (VkInstance) instance.vkHandle(); ws.vulkan.storeSurface = &(std::uintptr_t&) (vkSurface); auto wc = ac->createWindowContext(ws); // further vpp init const vpp::Queue* presentQueue; vpp::Device device(instance, vkSurface, presentQueue); vpp::Swapchain swapchain(device, vkSurface, {width, height}, {}); // vvg setup auto nvgContext = vvg::createContext(swapchain); auto font = nvgCreateFont(nvgContext, "sans", "Roboto-Regular.ttf"); using Clock = std::chrono::high_resolution_clock; auto lastFrameTimer = Clock::now(); unsigned int framesCount = 0; std::string fpsString = "420 fps"; // main loop while(run) { if(!ac->dispatchEvents()) break; nvgBeginFrame(nvgContext, width, height, width / (float) height); nvgBeginPath(nvgContext); nvgMoveTo(nvgContext, 10, 10); nvgLineTo(nvgContext, 10, 400); nvgLineTo(nvgContext, 100, 400); nvgQuadTo(nvgContext, 100, 50, 400, 120); nvgLineTo(nvgContext, 450, 10); nvgClosePath(nvgContext); nvgFillColor(nvgContext, nvgRGBAf(0.5, 0.8, 0.7, 1.0)); nvgFill(nvgContext); nvgBeginPath(nvgContext); nvgFontFaceId(nvgContext, font); nvgFontSize(nvgContext, 100.f); nvgFontBlur(nvgContext, .8f); nvgFillColor(nvgContext, nvgRGBAf(1.0, 1.0, 1.0, 1.0)); nvgTextBox(nvgContext, 200, 200, width - 200, "Hello Vulkan Vector Graphics World", nullptr); nvgFontSize(nvgContext, 30.f); nvgFontBlur(nvgContext, .2f); nvgText(nvgContext, 10, height - 20, fpsString.c_str(), nullptr); nvgBeginPath(nvgContext); nvgRect(nvgContext, 700, 400, 300, 300); nvgPathWinding(nvgContext, NVG_HOLE); nvgRect(nvgContext, 750, 450, 50, 50); // auto paint = nvgRadialGradient(nvgContext, 750, 425,20, 50, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); // auto paint = nvgRadialGradient(nvgContext, 0.0, 0.0, 0.2, 100.0, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); auto paint = nvgLinearGradient(nvgContext, 700, 400, 800, 450, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0)); nvgFillPaint(nvgContext, paint); // nvgFillColor(nvgContext, nvgRGBA(200, 200, 0, 200)); nvgClosePath(nvgContext); nvgFill(nvgContext); nvgEndFrame(nvgContext); // only refresh frame timer every second framesCount++; if(Clock::now() - lastFrameTimer >= std::chrono::seconds(1)) { fpsString = std::to_string(framesCount) + " fps"; lastFrameTimer = Clock::now(); framesCount = 0; } } vvg::destroyContext(*nvgContext); }