//----------------------------------------------------------------------------- bool CVSTGUITimer::stop () { if (platformTimer) { #if MAC CFRunLoopRemoveTimer (CFRunLoopGetCurrent (), (CFRunLoopTimerRef)platformTimer, kCFRunLoopCommonModes); CFRunLoopTimerInvalidate ((CFRunLoopTimerRef)platformTimer); CFRelease ((CFRunLoopTimerRef)platformTimer); #elif WINDOWS KillTimer ((HWND)NULL, (UINT_PTR)platformTimer); std::list<CVSTGUITimer*>::iterator it = gTimerList.begin (); while (it != gTimerList.end ()) { if ((*it) == this) { gTimerList.remove (*it); break; } it++; } #endif platformTimer = 0; #if DEBUGLOG DebugPrint ("Timer stopped (0x%x)\n", timerObject); #endif return true; } return false; }
void pause_idle_timer(void) { debug("entry"); assert(gTimer); assert(gRunLoop); CFRunLoopRemoveTimer(gRunLoop, gTimer, kCFRunLoopDefaultMode); }
void CFRunLoopRemoveMIDIRunLoopSource( CFRunLoopRef rl, struct CFMIDIRunLoopSource * source, CFStringRef mode ) { int i; if( source->cfrlt != NULL ) CFRunLoopRemoveTimer( rl, source->cfrlt, mode ); for( i=0; i<source->length; i++ ) { if( source->cfrls[i] != NULL ) CFRunLoopRemoveSource( rl, source->cfrls[i], mode ); } }
void DeviceNotification(void * refCon, io_service_t service, natural_t messageType, void * messageArgument ) { UPSDataRef upsDataRef = (UPSDataRef) refCon; if ( (upsDataRef != NULL) && (messageType == kIOMessageServiceIsTerminated) ) { upsDataRef->isPresent = FALSE; SCDynamicStoreRemoveValue(upsDataRef->upsStore, upsDataRef->upsStoreKey); if ( upsDataRef->upsEventSource ) { CFRunLoopRemoveSource(CFRunLoopGetCurrent(), upsDataRef->upsEventSource, kCFRunLoopDefaultMode); CFRelease(upsDataRef->upsEventSource); upsDataRef->upsEventSource = NULL; } if ( upsDataRef->upsEventTimer ) { CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), upsDataRef->upsEventTimer, kCFRunLoopDefaultMode); CFRelease(upsDataRef->upsEventTimer); upsDataRef->upsEventTimer = NULL; } if (upsDataRef->upsPlugInInterface != NULL) { (*(upsDataRef->upsPlugInInterface))->Release (upsDataRef->upsPlugInInterface); upsDataRef->upsPlugInInterface = NULL; } if (upsDataRef->notification != MACH_PORT_NULL) { IOObjectRelease(upsDataRef->notification); upsDataRef->notification = MACH_PORT_NULL; } if (upsDataRef->upsStoreKey) { CFRelease(upsDataRef->upsStoreKey); upsDataRef->upsStoreKey = NULL; } if (upsDataRef->upsStoreDict) { CFRelease(upsDataRef->upsStoreDict); upsDataRef->upsStoreDict = NULL; } if (upsDataRef->upsStore) { CFRelease(upsDataRef->upsStore); upsDataRef->upsStore = NULL; } } }
void HeapTimer::synchronize() { if (CFRunLoopGetCurrent() == m_runLoop.get()) return; CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); m_runLoop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); }
DefaultGCActivityCallback::~DefaultGCActivityCallback() { CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes); CFRunLoopTimerInvalidate(d->timer.get()); d->context.info = 0; d->runLoop = 0; d->timer = 0; }
void DefaultGCActivityCallback::synchronize() { if (CFRunLoopGetCurrent() == d->runLoop.get()) return; CFRunLoopRemoveTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes); d->runLoop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes); }
static void* Pt_Thread(void *p) { CFTimeInterval timerInterval; CFRunLoopTimerContext timerContext; CFRunLoopTimerRef timer; PtThreadParams *params = (PtThreadParams*)p; //CFTimeInterval timeout; /* raise the thread's priority */ kern_return_t error; thread_extended_policy_data_t extendedPolicy; thread_precedence_policy_data_t precedencePolicy; extendedPolicy.timeshare = 0; error = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread timeshare policy", error); } precedencePolicy.importance = THREAD_IMPORTANCE; error = thread_policy_set(mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread precedence policy", error); } /* set up the timer context */ timerContext.version = 0; timerContext.info = params; timerContext.retain = NULL; timerContext.release = NULL; timerContext.copyDescription = NULL; /* create a new timer */ timerInterval = (double)params->resolution / 1000.0; timer = CFRunLoopTimerCreate(NULL, startTime+timerInterval, timerInterval, 0, 0, Pt_CFTimerCallback, &timerContext); timerRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(timerRunLoop, timer, CFSTR("PtTimeMode")); /* run until we're told to stop by Pt_Stop() */ CFRunLoopRunInMode(CFSTR("PtTimeMode"), LONG_TIME, false); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer, CFSTR("PtTimeMode")); CFRelease(timer); free(params); return NULL; }
static int run_loop_for_time(double duration) { bool timed_out = false; CFRunLoopTimerContext timer_context = { 0, &timed_out, NULL, NULL, NULL }; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + duration, 0.0, 0, 0, timeout_cb, &timer_context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); CFRunLoopRun(); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); CFRelease(timer); return timed_out ? -1 : 0; }
void nglTimer::Stop() { if (mRunning) { NGL_ASSERT(mpCFRunLoopTimer); CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent(); NGL_ASSERT(mpCFRunLoop == currentRunLoop); CFRunLoopRemoveTimer(currentRunLoop, mpCFRunLoopTimer, kCFRunLoopCommonModes); if (mpCFRunLoopTimer) CFRelease(mpCFRunLoopTimer); mpCFRunLoopTimer = NULL; } mRunning = false; }
CF_EXPORT void rwsched_tasklet_CFRunLoopRemoveTimer(rwsched_tasklet_ptr_t sched_tasklet, rwsched_CFRunLoopRef rl, rwsched_CFRunLoopTimerRef rwsched_timer, CFStringRef mode) { // Validate input paraemters RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_ptr_t instance = sched_tasklet->instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); RW_CF_TYPE_VALIDATE(rwsched_timer, rwsched_CFRunLoopTimerRef); // Call the native CFRunLoop function CFRunLoopRemoveTimer(rl, rwsched_timer->cf_object, mode); }
/***************************************************************************** * Dealloc * - * Much like Obj-C dealloc this method is responsible for releasing any object * this plugin is holding. Unlike ObjC, you call directly free() instead of * [super dalloc]. *****************************************************************************/ static void Dealloc(BonjourUserEventsPlugin* plugin) { CFUUIDRef factoryID = plugin->_factoryID; if (factoryID) { CFPlugInRemoveInstanceForFactory(factoryID); CFRelease(factoryID); } if (plugin->_tokenToBrowserMap) CFRelease(plugin->_tokenToBrowserMap); if (plugin->_browsers) CFRelease(plugin->_browsers); if (plugin->_onAddEvents) CFRelease(plugin->_onAddEvents); if (plugin->_onRemoveEvents) CFRelease(plugin->_onRemoveEvents); if (plugin->_whileServiceExist) CFRelease(plugin->_whileServiceExist); if (plugin->_timers) { CFIndex i; CFIndex count = CFArrayGetCount(plugin->_timers); CFRunLoopRef crl = CFRunLoopGetCurrent(); for (i = 0; i < count; ++i) { CFRunLoopTimerRef timer = (CFRunLoopTimerRef)CFArrayGetValueAtIndex(plugin->_timers, i); CFRunLoopRemoveTimer(crl, timer, kCFRunLoopCommonModes); } CFRelease(plugin->_timers); } free(plugin); }
void UPSDeviceAdded(void *refCon, io_iterator_t iterator) { io_object_t upsDevice = MACH_PORT_NULL; UPSDataRef upsDataRef = NULL; CFDictionaryRef upsProperties = NULL; CFDictionaryRef upsEvent = NULL; CFSetRef upsCapabilites = NULL; CFRunLoopSourceRef upsEventSource = NULL; CFRunLoopTimerRef upsEventTimer = NULL; CFTypeRef typeRef = NULL; IOCFPlugInInterface ** plugInInterface = NULL; IOUPSPlugInInterface_v140 ** upsPlugInInterface = NULL; HRESULT result = S_FALSE; IOReturn kr; SInt32 score; while ( (upsDevice = IOIteratorNext(iterator)) ) { // Create the CF plugin for this device kr = IOCreatePlugInInterfaceForService(upsDevice, kIOUPSPlugInTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score); if ( kr != kIOReturnSuccess ) goto UPSDEVICEADDED_NONPLUGIN_CLEANUP; // Grab the new v140 interface result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID_v140), (LPVOID)&upsPlugInInterface); if ( ( result == S_OK ) && upsPlugInInterface ) { kr = (*upsPlugInInterface)->createAsyncEventSource(upsPlugInInterface, &typeRef); if ((kr != kIOReturnSuccess) || !typeRef) goto UPSDEVICEADDED_FAIL; if ( CFGetTypeID(typeRef) == CFRunLoopTimerGetTypeID() ) { upsEventTimer = (CFRunLoopTimerRef)typeRef; CFRunLoopAddTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode); } else if ( CFGetTypeID(typeRef) == CFRunLoopSourceGetTypeID() ) { upsEventSource = (CFRunLoopSourceRef)typeRef; CFRunLoopAddSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode); } } // Couldn't grab the new interface. Fallback on the old. else { result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID), (LPVOID)&upsPlugInInterface); } // Got the interface if ( ( result == S_OK ) && upsPlugInInterface ) { kr = (*upsPlugInInterface)->getProperties(upsPlugInInterface, &upsProperties); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; upsDataRef = GetPrivateData(upsProperties); if ( !upsDataRef ) goto UPSDEVICEADDED_FAIL; upsDataRef->upsPlugInInterface = (IOUPSPlugInInterface **)upsPlugInInterface; upsDataRef->upsEventSource = upsEventSource; upsDataRef->upsEventTimer = upsEventTimer; upsDataRef->isPresent = true; kr = (*upsPlugInInterface)->getCapabilities(upsPlugInInterface, &upsCapabilites); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; kr = CreatePowerManagerUPSEntry(upsDataRef, upsProperties, upsCapabilites); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; kr = (*upsPlugInInterface)->getEvent(upsPlugInInterface, &upsEvent); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; ProcessUPSEvent(upsDataRef, upsEvent); (*upsPlugInInterface)->setEventCallback(upsPlugInInterface, UPSEventCallback, NULL, upsDataRef); IOServiceAddInterestNotification( gNotifyPort, // notifyPort upsDevice, // service kIOGeneralInterest, // interestType DeviceNotification, // callback upsDataRef, // refCon &(upsDataRef->notification) // notification ); goto UPSDEVICEADDED_CLEANUP; } UPSDEVICEADDED_FAIL: // Failed to allocated a UPS interface. Do some cleanup if ( upsPlugInInterface ) { (*upsPlugInInterface)->Release(upsPlugInInterface); upsPlugInInterface = NULL; } if ( upsEventSource ) { CFRunLoopRemoveSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode); upsEventSource = NULL; } if ( upsEventTimer ) { CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode); upsEventSource = NULL; } UPSDEVICEADDED_CLEANUP: // Clean up (*plugInInterface)->Release(plugInInterface); UPSDEVICEADDED_NONPLUGIN_CLEANUP: IOObjectRelease(upsDevice); } }
static void __deviceCallback(void * context, IOReturn result, void * sender, IOHIDDeviceRef device) { boolean_t terminated = context == 0; CFStringRef debugString = CFCopyDescription(device); char * c_debug_string = NULL; if( debugString ){ // DG: Bluetooth "Product" strings have Unicode encoding and no nul terminator and CFStringGetCStringPtr returns NULL // Need to manually copy to C string CFIndex length = CFStringGetLength(debugString); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, CFStringGetSystemEncoding()) + 1; c_debug_string = (char *)malloc(maxSize); CFStringGetCString(debugString, c_debug_string, maxSize, CFStringGetSystemEncoding()); CFRelease(debugString); } static CFMutableDictionaryRef s_timers = NULL; if ( !s_timers ) s_timers = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); uint64_t uuid = 0; CFNumberRef temp = IOHIDDeviceGetProperty( device, CFSTR(kIOHIDUniqueIDKey) ); if ( temp && CFGetTypeID(temp) == CFNumberGetTypeID() ) CFNumberGetValue( temp, kCFNumberLongLongType, &uuid ); CFNumberGetValue( IOHIDDeviceGetProperty( device, CFSTR(kIOHIDUniqueIDKey) ), kCFNumberLongLongType, &uuid ); printf("%-10.10s: %s UniqueID %llu\n", terminated ? "terminated" : "matched", c_debug_string ? c_debug_string : "", uuid ); if ( c_debug_string ) free(c_debug_string); if ( terminated ) { CFDictionaryRemoveValue(gOutputElements, device); CFRunLoopTimerRef timer = (CFRunLoopTimerRef)CFDictionaryGetValue(s_timers, device); if ( timer ) { CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); } CFDictionaryRemoveValue(s_timers, device); } else { CFArrayRef outputElements = NULL; CFMutableDictionaryRef matching = NULL; if ( gPrintDescriptor ) { CFDataRef descriptor = NULL; descriptor = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDReportDescriptorKey)); if ( descriptor ) { PrintHIDDescriptor(CFDataGetBytePtr(descriptor), CFDataGetLength(descriptor)); } } if ( gPollInterval != 0.0 ) { CFRunLoopTimerContext context = {.info=device}; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), gPollInterval, 0, 0, __timerCallback, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); CFDictionaryAddValue(s_timers, device, timer); CFRelease(timer); printf("Adding polling timer @ %4.6f s\n", gPollInterval); } matching = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if ( matching ) { uint32_t value = kIOHIDElementTypeOutput; CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); if ( number ) { CFDictionarySetValue(matching, CFSTR(kIOHIDElementTypeKey), number); outputElements = IOHIDDeviceCopyMatchingElements(device, matching, 0); if ( outputElements ) { CFDictionarySetValue(gOutputElements, device, outputElements); CFRelease(outputElements); } CFRelease(number); } CFRelease(matching); } }
int system_starter (Action anAction, CFStringRef aService) { CFRunLoopSourceRef anIPCSource = NULL; NSSearchPathDomainMask aMask; CFRunLoopTimerRef anActivityTimer = NULL; StartupContext aStartupContext = (StartupContext) malloc(sizeof(struct StartupContextStorage)); if (! aStartupContext) { error(CFSTR("Not enough memory to allocate startup context.\n")); return(1); } /** * Init the display context. Starts with the default text display. * A graphical display may be requested later via IPC. **/ aStartupContext->aDisplayContext = initDisplayContext(); aStartupContext->aResourcesBundlePath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/%@.%s/"), kBundleDirectory, kResourcesBundleName, kBundleExtension); { CFStringRef aLocalizedString = LocalizedString(aStartupContext->aResourcesBundlePath, kWelcomeToMacintoshKey); if (aLocalizedString) { displayStatus(aStartupContext->aDisplayContext, aLocalizedString); CFRelease(aLocalizedString); } } if (gSafeBootFlag) { CFStringRef aLocalizedString = LocalizedString(aStartupContext->aResourcesBundlePath, kSafeBootKey); if (aLocalizedString) { (void) displaySafeBootMsg(aStartupContext->aDisplayContext, aLocalizedString); CFRelease(aLocalizedString); } } if (gDebugFlag && gNoRunFlag) sleep(1); /** * Create the IPC port **/ anIPCSource = CreateIPCRunLoopSource(kSystemStarterMessagePort, aStartupContext); if (anIPCSource) { CFRunLoopAddSource(CFRunLoopGetCurrent(), anIPCSource, kCFRunLoopCommonModes); CFRelease(anIPCSource); } else { error(CFSTR("Could not create IPC port (%@)."), kSystemStarterMessagePort); return(1); } /** * Get a list of Startup Items which are in /Local and /System. * We can't search /Network yet because the network isn't up. **/ aMask = NSSystemDomainMask; if (!gSafeBootFlag) { aMask |= NSLocalDomainMask; } else { if (gDebugFlag) { debug(CFSTR("Safe Boot mode active\n")); fflush(stdout); } } aStartupContext->aWaitingList = StartupItemListCreateWithMask(aMask); aStartupContext->aFailedList = NULL; aStartupContext->aStatusDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); aStartupContext->aServicesCount = 0; aStartupContext->aRunningCount = 0; aStartupContext->aQuitOnNotification = gQuitOnNotification && aStartupContext->aDisplayContext; if (aService) { CFMutableArrayRef aDependentsList = StartupItemListCreateDependentsList(aStartupContext->aWaitingList, aService, anAction); if (aDependentsList) { CFRelease(aStartupContext->aWaitingList); aStartupContext->aWaitingList = aDependentsList; } else { error(CFSTR("Unknown service: %@\n"), aService); return(1); } } aStartupContext->aServicesCount = StartupItemListCountServices(aStartupContext->aWaitingList); /** * Create the activity timer. **/ anActivityTimer = createActivityTimer(aStartupContext); /** * Do the run loop **/ while (1) { CFMutableDictionaryRef anItem = StartupItemListGetNext(aStartupContext->aWaitingList, aStartupContext->aStatusDict, anAction); if (anItem) { int err = StartupItemRun(aStartupContext->aStatusDict, anItem, anAction); if (!err) { ++aStartupContext->aRunningCount; MonitorStartupItem(aStartupContext, anItem); } else { /* add item to failed list */ AddItemToFailedList(aStartupContext, anItem); /* Remove the item from the waiting list. */ RemoveItemFromWaitingList(aStartupContext, anItem); } } else { /* If no item was selected to run, and if no items are running, startup is done. */ if (aStartupContext->aRunningCount == 0) { if (gDebugFlag) debug(CFSTR("none left\n")); break; } /* Perform periodic checks for activity. */ if (anActivityTimer) { CFRunLoopAddTimer(CFRunLoopGetCurrent(), anActivityTimer, kCFRunLoopCommonModes); } /* Process incoming IPC messages and item terminations */ CFRunLoopRun(); /* Don't perform activity checks while we are doing work. */ if (anActivityTimer) { CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), anActivityTimer, kCFRunLoopCommonModes); } } } /** * Good-bye. **/ displayErrorMessages(aStartupContext); /* Display final message and wait if necessary */ { CFStringRef aLocalizedString = NULL; if (aStartupContext->aQuitOnNotification) { aLocalizedString = LocalizedString(aStartupContext->aResourcesBundlePath, kLoginWindowKey); } else { aLocalizedString = LocalizedString(aStartupContext->aResourcesBundlePath, kStartupCompleteKey); } if (aLocalizedString) { displayStatus(aStartupContext->aDisplayContext, aLocalizedString); CFRelease(aLocalizedString); } } /* sit and wait for a message from ConsoleMessage to quit */ if (aStartupContext->aQuitOnNotification) { CFRunLoopRun(); } /* clean up */ if (anActivityTimer ) CFRelease(anActivityTimer); if (aStartupContext->aStatusDict ) CFRelease(aStartupContext->aStatusDict); if (aStartupContext->aWaitingList) CFRelease(aStartupContext->aWaitingList); if (aStartupContext->aFailedList) CFRelease(aStartupContext->aFailedList); if (aStartupContext->aResourcesBundlePath) CFRelease(aStartupContext->aResourcesBundlePath); if (aStartupContext->aDisplayContext) freeDisplayContext(aStartupContext->aDisplayContext); free(aStartupContext); return(0); }
HeapTimer::~HeapTimer() { CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); CFRunLoopTimerInvalidate(m_timer.get()); }
static void * /* O - Return status/value */ sysEventThreadEntry(void) { io_object_t powerNotifierObj; /* Power notifier object */ IONotificationPortRef powerNotifierPort; /* Power notifier port */ SCDynamicStoreRef store = NULL;/* System Config dynamic store */ CFRunLoopSourceRef powerRLS = NULL,/* Power runloop source */ storeRLS = NULL;/* System Config runloop source */ CFStringRef key[6], /* System Config keys */ pattern[2]; /* System Config patterns */ CFArrayRef keys = NULL, /* System Config key array*/ patterns = NULL;/* System Config pattern array */ SCDynamicStoreContext storeContext; /* Dynamic store context */ CFRunLoopTimerContext timerContext; /* Timer context */ cupsd_thread_data_t threadData; /* Thread context data for the * * runloop notifiers */ /* * Register for power state change notifications */ bzero(&threadData, sizeof(threadData)); threadData.sysevent.powerKernelPort = IORegisterForSystemPower(&threadData, &powerNotifierPort, sysEventPowerNotifier, &powerNotifierObj); if (threadData.sysevent.powerKernelPort) { powerRLS = IONotificationPortGetRunLoopSource(powerNotifierPort); CFRunLoopAddSource(CFRunLoopGetCurrent(), powerRLS, kCFRunLoopDefaultMode); } else DEBUG_puts("sysEventThreadEntry: error registering for system power " "notifications"); /* * Register for system configuration change notifications */ bzero(&storeContext, sizeof(storeContext)); storeContext.info = &threadData; store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cupsd"), sysEventConfigurationNotifier, &storeContext); if (!ComputerNameKey) ComputerNameKey = SCDynamicStoreKeyCreateComputerName(kCFAllocatorDefault); if (!BTMMKey) BTMMKey = SCDynamicStoreKeyCreate(kCFAllocatorDefault, CFSTR("Setup:/Network/BackToMyMac")); if (!NetworkGlobalKeyIPv4) NetworkGlobalKeyIPv4 = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv4); if (!NetworkGlobalKeyIPv6) NetworkGlobalKeyIPv6 = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv6); if (!NetworkGlobalKeyDNS) NetworkGlobalKeyDNS = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetDNS); if (!HostNamesKey) HostNamesKey = SCDynamicStoreKeyCreateHostNames(kCFAllocatorDefault); if (!NetworkInterfaceKeyIPv4) NetworkInterfaceKeyIPv4 = SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4); if (!NetworkInterfaceKeyIPv6) NetworkInterfaceKeyIPv6 = SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6); if (store && ComputerNameKey && HostNamesKey && NetworkGlobalKeyIPv4 && NetworkGlobalKeyIPv6 && NetworkGlobalKeyDNS && NetworkInterfaceKeyIPv4 && NetworkInterfaceKeyIPv6) { key[0] = ComputerNameKey; key[1] = BTMMKey; key[2] = NetworkGlobalKeyIPv4; key[3] = NetworkGlobalKeyIPv6; key[4] = NetworkGlobalKeyDNS; key[5] = HostNamesKey; pattern[0] = NetworkInterfaceKeyIPv4; pattern[1] = NetworkInterfaceKeyIPv6; keys = CFArrayCreate(kCFAllocatorDefault, (const void **)key, sizeof(key) / sizeof(key[0]), &kCFTypeArrayCallBacks); patterns = CFArrayCreate(kCFAllocatorDefault, (const void **)pattern, sizeof(pattern) / sizeof(pattern[0]), &kCFTypeArrayCallBacks); if (keys && patterns && SCDynamicStoreSetNotificationKeys(store, keys, patterns)) { if ((storeRLS = SCDynamicStoreCreateRunLoopSource(kCFAllocatorDefault, store, 0)) != NULL) { CFRunLoopAddSource(CFRunLoopGetCurrent(), storeRLS, kCFRunLoopDefaultMode); } else DEBUG_printf(("sysEventThreadEntry: SCDynamicStoreCreateRunLoopSource " "failed: %s\n", SCErrorString(SCError()))); } else DEBUG_printf(("sysEventThreadEntry: SCDynamicStoreSetNotificationKeys " "failed: %s\n", SCErrorString(SCError()))); } else DEBUG_printf(("sysEventThreadEntry: SCDynamicStoreCreate failed: %s\n", SCErrorString(SCError()))); if (keys) CFRelease(keys); if (patterns) CFRelease(patterns); /* * Set up a timer to delay the wake change notifications. * * The initial time is set a decade or so into the future, we'll adjust * this later. */ bzero(&timerContext, sizeof(timerContext)); timerContext.info = &threadData; threadData.timerRef = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + (86400L * 365L * 10L), 86400L * 365L * 10L, 0, 0, sysEventTimerNotifier, &timerContext); CFRunLoopAddTimer(CFRunLoopGetCurrent(), threadData.timerRef, kCFRunLoopDefaultMode); /* * Store our runloop in a global so the main thread can use it to stop us. */ pthread_mutex_lock(&SysEventThreadMutex); SysEventRunloop = CFRunLoopGetCurrent(); pthread_cond_signal(&SysEventThreadCond); pthread_mutex_unlock(&SysEventThreadMutex); /* * Disappear into the runloop until it's stopped by the main thread. */ CFRunLoopRun(); /* * Clean up before exiting. */ if (threadData.timerRef) { CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), threadData.timerRef, kCFRunLoopDefaultMode); CFRelease(threadData.timerRef); } if (threadData.sysevent.powerKernelPort) { CFRunLoopRemoveSource(CFRunLoopGetCurrent(), powerRLS, kCFRunLoopDefaultMode); IODeregisterForSystemPower(&powerNotifierObj); IOServiceClose(threadData.sysevent.powerKernelPort); IONotificationPortDestroy(powerNotifierPort); } if (storeRLS) { CFRunLoopRemoveSource(CFRunLoopGetCurrent(), storeRLS, kCFRunLoopDefaultMode); CFRunLoopSourceInvalidate(storeRLS); CFRelease(storeRLS); } if (store) CFRelease(store); pthread_exit(NULL); }
void cfRunLoopStop() { CFRunLoopTimerInvalidate(timerRef); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timerRef, kCFRunLoopCommonModes); CFRunLoopStop(CFRunLoopGetCurrent()); timerRef = NULL; }
void rwsched_cftimer_callout_intercept(CFRunLoopTimerRef timer, void *info) { rwsched_instance_ptr_t instance; rwsched_CFRunLoopTimerRef rwsched_object = (rwsched_CFRunLoopTimerRef) info; rwsched_tasklet_ptr_t sched_tasklet; // Validate input parameters __CFGenericValidateType_(timer, CFRunLoopTimerGetTypeID(), __PRETTY_FUNCTION__); RW_CF_TYPE_VALIDATE(rwsched_object, rwsched_CFRunLoopTimerRef); sched_tasklet = rwsched_object->callback_context.tasklet_info; RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); instance = rwsched_object->callback_context.instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); // #1 - Check if the current tasklet is in blocking mode; if a // timer fired while blocking, then dont call the callback // #2 - Otherwise the current tasklet is not blocking and the timer callback // shall be called if (sched_tasklet->blocking_mode.blocked) { /* printf("BLOK timer=%p valid=%d repeat=%d interval=%f next-fire=%f \n", timer, CFRunLoopTimerIsValid(timer), CFRunLoopTimerDoesRepeat(timer), CFRunLoopTimerGetInterval(timer), (CFRunLoopTimerGetNextFireDate(timer) - CFAbsoluteTimeGetCurrent())); */ CFRunLoopRemoveTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->main_cfrunloop_mode); //CFRunLoopAddTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->deferred_cfrunloop_mode); if (rwsched_object->onetime_timer) rwsched_object->onetime_timer_fired_while_blocked = 1; } else { /* printf("MAIN timer=%p valid=%d repeat=%d interval=%f next-fire=%f \n", timer, CFRunLoopTimerIsValid(timer), CFRunLoopTimerDoesRepeat(timer), CFRunLoopTimerGetInterval(timer), (CFRunLoopTimerGetNextFireDate(timer) - CFAbsoluteTimeGetCurrent())); */ g_rwresource_track_handle = sched_tasklet->rwresource_track_handle; g_tasklet_info = sched_tasklet; // The current task is not blocking so we can invoke the callback now struct timeval tv_begin, tv_end, tv_delta; if (sched_tasklet->instance->latency.check_threshold_ms) { gettimeofday(&tv_begin, NULL); } else { tv_begin.tv_sec = 0; } (rwsched_object->cf_callout)(rwsched_object, rwsched_object->cf_context.info); if (tv_begin.tv_sec && sched_tasklet->instance->latency.check_threshold_ms) { gettimeofday(&tv_end, NULL); timersub(&tv_end, &tv_begin, &tv_delta); unsigned int cbms = (tv_delta.tv_sec * 1000 + tv_delta.tv_usec / 1000); if (cbms >= sched_tasklet->instance->latency.check_threshold_ms) { char *name = rw_btrace_get_proc_name(rwsched_object->cf_callout); RWSCHED_LOG_EVENT(instance, SchedDebug, RWLOG_ATTR_SPRINTF("rwsched[%d] CF timer took %ums ctx %p callback %s", getpid(), cbms, rwsched_object->cf_context.info, name)); free(name); } } g_tasklet_info = 0; g_rwresource_track_handle = 0; } }