void runLoop(TimerCallbackParameters* timerCallbackParameters, float frequency) { CFRunLoopObserverContext observerContext; observerContext.version = 0; observerContext.info = 0; observerContext.retain = 0; observerContext.release = 0; observerContext.copyDescription = 0; auto observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeTimers, true, 0, observerCallback, &observerContext); CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, kCFRunLoopCommonModes); CFRunLoopTimerContext timerContext; timerContext.version = 0; timerContext.info = timerCallbackParameters; timerContext.retain = 0; timerContext.release = 0; timerContext.copyDescription = 0; auto timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 1.0 / frequency, 0, 0, timerCallBack, &timerContext); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); CFRunLoopRun(); }
void rwsched_cfrunloop_relocate_timers_to_main_mode(rwsched_tasklet_ptr_t sched_tasklet) { //unsigned int i, j; unsigned int i; rwsched_CFRunLoopTimerRef rwsched_object; rwsched_instance_ptr_t instance; // Validate input parameters RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); for (i = 1 ; i < sched_tasklet->cftimer_array->len ; i++) { if ((rwsched_object = g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, i)) != NULL) { RW_CF_TYPE_VALIDATE(rwsched_object, rwsched_CFRunLoopTimerRef); instance = rwsched_object->callback_context.instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); //CFRunLoopRemoveTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->deferred_cfrunloop_mode); if (rwsched_object->onetime_timer_fired_while_blocked) { //(rwsched_object->cf_callout)(rwsched_object, rwsched_object->cf_context.info); RW_ASSERT(rwsched_object->onetime_timer); rwsched_object->cf_object = CFRunLoopTimerCreate(rwsched_object->ott.allocator, CFAbsoluteTimeGetCurrent()+0.000001, 0, rwsched_object->ott.flags, rwsched_object->ott.order, rwsched_cftimer_callout_intercept, &rwsched_object->tmp_context); rwsched_object->onetime_timer_fired_while_blocked = 0; } CFRunLoopAddTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->main_cfrunloop_mode); } } }
int timer_callout_set(timer_callout_t * callout, CFAbsoluteTime relative_time, timer_func_t * func, void * arg1, void * arg2, void * arg3) { CFRunLoopTimerContext context = { 0, NULL, NULL, NULL, NULL }; CFAbsoluteTime wakeup_time; if (callout == NULL) { return (0); } timer_cancel(callout); if (func == NULL) { return (0); } callout->func = func; callout->arg1 = arg1; callout->arg2 = arg2; callout->arg3 = arg3; callout->enabled = TRUE; callout->time_generation = S_time_generation; context.info = callout; wakeup_time = CFAbsoluteTimeGetCurrent() + relative_time; callout->timer_source = CFRunLoopTimerCreate(NULL, wakeup_time, 0.0, 0, 0, timer_callout_process, &context); my_log(LOG_DEBUG, "timer: wakeup time is (%0.09g) %0.09g", relative_time, wakeup_time); my_log(LOG_DEBUG, "timer: adding timer source"); CFRunLoopAddTimer(CFRunLoopGetCurrent(), callout->timer_source, kCFRunLoopDefaultMode); return (1); }
int main (int argc, char * const argv[]) { g_MasterLoop = CFRunLoopGetCurrent(); signal (SIGTERM, CancelExec); signal (SIGHUP, ForceStartup); signal (SIGALRM, ForceInventory); // a bit of runway for network services sleep(30); CheckRun(true); // initial check CFAuto<CFRunLoopTimerRef> SCATimer; SCATimer.Attach( CFRunLoopTimerCreate( kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + SurveyTime, SurveyTime, 0, 0, InventoryCheckTimerFunc, NULL)); CFRunLoopAddTimer(g_MasterLoop, SCATimer, kCFRunLoopDefaultMode); CFRunLoopRun(); CFRunLoopTimerInvalidate( SCATimer ); }
void fx_setTimeout(txMachine* the) { txTimeoutData* data; #if mxMacOSX CFRunLoopTimerContext context; #endif txNumber duration = fxToNumber(the, mxArgv(1)) / 1000; data = c_malloc(sizeof(txTimeoutData)); mxElseError(data); c_memset(data, 0, sizeof(txTimeoutData)); data->the = the; data->function.kind = mxArgv(0)->kind; data->function.value = mxArgv(0)->value; fxRemember(the, &(data->function)); if (mxArgc > 2) { data->argument.kind = mxArgv(2)->kind; data->argument.value = mxArgv(2)->value; } fxRemember(the, &(data->argument)); #if mxMacOSX memset(&context, 0, sizeof(context)); context.info = data; context.release = fx_setTimeoutRelease; data->timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + duration, 0, 0, 0, fx_setTimeoutCallback, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), data->timer, gxRunLoopMode); #endif }
static void configuration_changed(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) { CFRunLoopTimerContext context = { 0, (void *)store, CFRetain, CFRelease, NULL }; CFAbsoluteTime time_boot; CFAbsoluteTime time_now ; // if active, cancel any in-progress attempt to resolve the primary IP address if (ptrTarget != NULL) { ptr_query_stop(); } // if active, cancel any queued configuration change if (timer != NULL) { CFRunLoopTimerInvalidate(timer); CFRelease(timer); timer = NULL; } // queue configuration change time_boot = boottime() + SMB_STARTUP_DELAY; time_now = CFAbsoluteTimeGetCurrent() + SMB_DEBOUNCE_DELAY; timer = CFRunLoopTimerCreate(NULL, time_now > time_boot ? time_now : time_boot, 0, 0, 0, smb_update_configuration, &context); CFRunLoopAddTimer(rl, timer, kCFRunLoopDefaultMode); return; }
void RunLoopTimerBase::start(double nextFireInterval, double repeatInterval) { if (m_timer) CFRunLoopTimerInvalidate(m_timer.get()); CFRunLoopTimerContext context = { 0, this, 0, 0, 0 }; m_timer = adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context)); }
void* RunLoopThread(void* args) { unsigned i; InitUSB(); currentRunLoop = CFRunLoopGetCurrent(); CFRunLoopTimerContext context = {0, NULL, NULL, NULL, NULL}; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.1, 0.1, 0, 0, &onTimerFired, &context); CFRunLoopAddTimer(currentRunLoop, timer, kCFRunLoopCommonModes); // Signal the parent that we are running adb_mutex_lock(&start_lock); adb_cond_signal(&start_cond); adb_mutex_unlock(&start_lock); CFRunLoopRun(); currentRunLoop = 0; for (i = 0; i < vendorIdCount; i++) { IOObjectRelease(notificationIterators[i]); } IONotificationPortDestroy(notificationPort); usb_cleanup(); DBG("RunLoopThread done\n"); return NULL; }
static void schedulePowerEvent(PowerEventBehavior *behave) { static CFRunLoopTimerContext tmr_context = {0,0,0,0,0}; CFAbsoluteTime fire_time = 0.0; CFDictionaryRef upcoming = NULL; CFDateRef temp_date = NULL; if(behave->timer) { CFRunLoopTimerInvalidate(behave->timer); CFRelease(behave->timer); behave->timer = 0; } // find upcoming time upcoming = copyEarliestUpcoming(behave); if(!upcoming) { // No scheduled events if (behave->noScheduledEventCallout) { (*behave->noScheduledEventCallout)(NULL); } return; } /* * Perform any necessary actions at schedulePowerEvent time */ if ( behave->scheduleNextCallout ) { (*behave->scheduleNextCallout)(upcoming); } if (behave->currentEvent) { CFRelease(behave->currentEvent); } behave->currentEvent = (CFDictionaryRef)upcoming; tmr_context.info = (void *)behave; temp_date = _getScheduledEventDate(upcoming); if(!temp_date) goto exit; fire_time = CFDateGetAbsoluteTime(temp_date); behave->timer = CFRunLoopTimerCreate(0, fire_time, 0.0, 0, 0, handleTimerExpiration, &tmr_context); if(behave->timer) { CFRunLoopAddTimer( CFRunLoopGetCurrent(), behave->timer, kCFRunLoopDefaultMode); } exit: return; }
void cfRunLoopRun(ExternalTimerCallback callback, void* context) { externalCallback = callback; externalContext = context; timerRef = CFRunLoopTimerCreate(NULL, 0, 1.0, 0, 0, timerCallback, NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timerRef, kCFRunLoopCommonModes); CFRunLoopRun(); }
HeapTimer::HeapTimer(JSGlobalData* globalData, CFRunLoopRef runLoop) : m_globalData(globalData) , m_runLoop(runLoop) { memset(&m_context, 0, sizeof(CFRunLoopTimerContext)); m_context.info = this; m_timer.adoptCF(CFRunLoopTimerCreate(0, s_decade, s_decade, 0, 0, HeapTimer::timerDidFire, &m_context)); CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); }
void RunLoop::TimerBase::start(double nextFireInterval, bool repeat) { if (m_timer) stop(); CFRunLoopTimerContext context = { 0, this, 0, 0, 0 }; CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0; m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context)); CFRunLoopAddTimer(m_runLoop->m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); }
void DefaultGCActivityCallback::commonConstructor(Heap* heap, CFRunLoopRef runLoop) { d = adoptPtr(new DefaultGCActivityCallbackPlatformData); memset(&d->context, 0, sizeof(CFRunLoopTimerContext)); d->context.info = heap; d->runLoop = runLoop; d->timer.adoptCF(CFRunLoopTimerCreate(0, decade, decade, 0, 0, DefaultGCActivityCallbackPlatformData::trigger, &d->context)); CFRunLoopAddTimer(d->runLoop.get(), d->timer.get(), kCFRunLoopCommonModes); }
static int initialize_timer() { gTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + actualidle, actualidle, 0, 0, diediedie, NULL); int err = 0; debug("entry"); if (0 != (err = pthread_create(&idletimer_thread, NULL, idletimer, NULL))) helplog(ASL_LEVEL_ERR, "Could not start idletimer thread: %s", strerror(err)); return err; }
int main(int argc, char** argv) { CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent()+1, 0,0,0, timeout, NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); am_device_notification* notification; check("Subscribing to device notification", AMDeviceNotificationSubscribe(&onDevice, 0,0,NULL, ¬ification)); CFRunLoopRun(); return 1; }
HeapTimer::HeapTimer(VM* vm, CFRunLoopRef runLoop) : m_vm(vm) , m_runLoop(runLoop) { memset(&m_context, 0, sizeof(CFRunLoopTimerContext)); m_context.info = &vm->apiLock(); m_context.retain = retainAPILock; m_context.release = releaseAPILock; m_timer = adoptCF(CFRunLoopTimerCreate(0, s_decade, s_decade, 0, 0, HeapTimer::timerDidFire, &m_context)); CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); }
struct CFMIDIRunLoopSource * CFMIDIRunLoopSourceCreate( struct MIDIRunloopSource * source ) { int i, create; CFRunLoopTimerContext timer_context; CFSocketContext socket_context; CFOptionFlags socket_cb_types; CFSocketRef socket; struct CFMIDIRunLoopSource * cf = malloc( sizeof(struct CFMIDIRunLoopSource) + sizeof(CFRunLoopSourceRef)*(source->nfds-1) ); MIDIPrecondReturn( cf != NULL, ENOMEM, NULL ); timer_context.version = 0; timer_context.info = source; timer_context.release = NULL; timer_context.retain = NULL; timer_context.copyDescription = NULL; socket_context.version = 0; socket_context.info = source; socket_context.release = NULL; socket_context.retain = NULL; socket_context.copyDescription = NULL; cf->length = source->nfds; if( source->timeout.tv_sec > 0 || source->timeout.tv_nsec > 0 ) { cf->cfrlt = CFRunLoopTimerCreate( NULL, CFAbsoluteTimeGetCurrent(), (double) source->timeout.tv_sec + 0.000000001 * (double) source->timeout.tv_nsec, 0, 1, &_cf_timer_callback, &timer_context ); } else { cf->cfrlt = NULL; } for( i=0; i<cf->length; i++ ) { create = 0; socket_cb_types = kCFSocketNoCallBack; if( FD_ISSET(i, &(source->readfds)) ) { socket_cb_types |= kCFSocketReadCallBack; create = 1; } if( FD_ISSET(i, &(source->writefds)) ) { socket_cb_types |= kCFSocketWriteCallBack; create = 1; } if( create ) { socket = CFSocketCreateWithNative( NULL, i, socket_cb_types, &_cf_socket_callback, &socket_context ); cf->cfrls[i] = CFSocketCreateRunLoopSource( NULL, socket, 1 ); CFRelease( socket ); } else { cf->cfrls[i] = NULL; } } return cf; }
static void ParkEventLoop() { // RunLoop needs at least one source, and 1e20 is pretty far into the future CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode); CFRelease(t); // Park this thread in the main run loop. int32_t result; do { result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false); } while (result != kCFRunLoopRunFinished); }
static CFRunLoopTimerRef createActivityTimer(StartupContext aStartupContext) { CFRunLoopTimerContext aTimerContext; aTimerContext.version = 0; aTimerContext.info = aStartupContext; aTimerContext.retain = 0; aTimerContext.release = 0; aTimerContext.copyDescription = 0; return CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), kTimerInterval, 0, 0, &checkForActivity, &aTimerContext); }
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; }
// recveive - receive a packet // Inputs: // num = device to receive from (zero based) // buf = buffer to receive packet // len = buffer's size // timeout = time to wait, in milliseconds // Output: // number of bytes received, or -1 on error // int pjrc_rawhid::receive(int num, void *buf, int len, int timeout) { hid_t *hid; buffer_t *b; CFRunLoopTimerRef timer=NULL; CFRunLoopTimerContext context; int ret=0, timeout_occurred=0; if (len < 1) return 0; hid = get_hid(num); if (!hid || !hid->open) return -1; if ((b = hid->first_buffer) != NULL) { if (len > b->len) len = b->len; memcpy(buf, b->buf, len); hid->first_buffer = b->next; free(b); return len; } memset(&context, 0, sizeof(context)); context.info = &timeout_occurred; timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + (double)timeout / 1000.0, 0, 0, 0, timeout_callback, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); the_correct_runloop = CFRunLoopGetCurrent(); //qDebug("--"); while (1) { //qDebug("."); CFRunLoopRun(); // Found the problem: somehow the input_callback does not // stop this CFRunLoopRun because it is hooked to a different run loop !!! // Hence the use of the "correct_runloop" variable above. //qDebug(" .."); if ((b = hid->first_buffer) != NULL) { if (len > b->len) len = b->len; memcpy(buf, b->buf, len); hid->first_buffer = b->next; free(b); ret = len; //qDebug("*************"); break; } if (!hid->open) { printf("pjrc_rawhid_recv, device not open\n"); ret = -1; break; } if (timeout_occurred) break; } CFRunLoopTimerInvalidate(timer); CFRelease(timer); return ret; }
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 setSharedTimerFireTime(double fireTime) { ASSERT(sharedTimerFiredFunction); if (sharedTimer) { CFRunLoopTimerInvalidate(sharedTimer); CFRelease(sharedTimer); } CFAbsoluteTime fireDate = fireTime - kCFAbsoluteTimeIntervalSince1970; sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0); CFRunLoopAddTimer(CFRunLoopGetCurrent(), sharedTimer, kCFRunLoopCommonModes); }
CACFRunLoopTimer::CACFRunLoopTimer(CFAbsoluteTime inFireTime, CFTimeInterval inFireInterval) : mRunLoopTimer(NULL) { // initialize the context mRunLoopTimerContext.version = 0; mRunLoopTimerContext.info = this; mRunLoopTimerContext.retain = NULL; mRunLoopTimerContext.release = NULL; mRunLoopTimerContext.copyDescription = NULL; mRunLoopTimer = CFRunLoopTimerCreate(NULL, inFireTime, inFireInterval, 0, 0, (CFRunLoopTimerCallBack)TimerCallBack, &mRunLoopTimerContext); ThrowIf(mRunLoopTimer == NULL, CAException('what'), "CACFRunLoopTimer::CACFRunLoopTimer: couldn't create the timer object"); }
int rawhid_recv(int num, void *buf, int len, int timeout) { //fprintf(stderr,"rawhid_recv start len: %d\n",len); //fprintf(stderr,"rawhid_recv start \n"); hid_t *hid; buffer_t *b; CFRunLoopTimerRef timer=NULL; CFRunLoopTimerContext context; int ret=0, timeout_occurred=0; if (len < 1) return 0; hid = get_hid(num); if (!hid || !hid->open) return -1; if ((b = hid->first_buffer) != NULL) { if (len > b->len) len = b->len; memcpy(buf, b->buf, len); hid->first_buffer = b->next; free(b); // fprintf(stderr,"rawhid_recv A len: %d\n\n",len); return len; } memset(&context, 0, sizeof(context)); context.info = &timeout_occurred; timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + (double)timeout / 1000.0, 0, 0, 0, timeout_callback, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); while (1) { CFRunLoopRun(); if ((b = hid->first_buffer) != NULL) { if (len > b->len) len = b->len; memcpy(buf, b->buf, len); hid->first_buffer = b->next; free(b); ret = len; break; } if (!hid->open) { //printf("rawhid_recv, device not open\n"); ret = -1; break; } if (timeout_occurred) break; } CFRunLoopTimerInvalidate(timer); CFRelease(timer); //fprintf(stderr,"rawhid_recv ret: %d\n",ret); return ret; }
void osx_driver_setclipboard( struct ts_display_t *display, ts_clipboard_p clipboard) { //printf("%s called\n", __func__); loop_display = display; loop_clipboard = clipboard; loop_to = NULL; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, 0, 0, 0, 0, osx_setclipboard_callback, NULL); CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes); }
static void startComplete(pid_t pid, int status, struct rusage *rusage, void *context) { execCommand = 0; if (WIFEXITED(status)) { switch (WEXITSTATUS(status)) { case AT_CMD_SUCCESS : SCLog(TRUE, LOG_NOTICE, CFSTR("AppleTalk startup complete")); if ((curState < 0) || (curState > (int)context)) { // the stack is now up but we really want it down stopAppleTalk(NULL, (void *)curState); } return; case AT_CMD_ALREADY_RUNNING : // the stack is already up but we're not sure // if the configuration is correct, restart SCLog(TRUE, LOG_NOTICE, CFSTR("AppleTalk already running, restarting")); stopAppleTalk(NULL, (void *)curState); return; default : break; } } SCLog(TRUE, LOG_ERR, CFSTR("AppleTalk startup failed, status = %d%s"), WEXITSTATUS(status), (execRetry > 1) ? " (retrying)" : ""); // startup failed, retry if (--execRetry > 0) { CFRunLoopTimerContext timerContext = { 0, (void *)curState, NULL, NULL, NULL }; CFRunLoopTimerRef timer; timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + 1.0, 0.0, 0, 0, startAppleTalk, &timerContext); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); CFRelease(timer); return; } return; }
static void register_timeout(void) { if (idle_timer == NULL) { idle_timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + TIMEOUT_IN_SECONDS, TIMEOUT_IN_SECONDS, 0, 0, idle_timer_proc, NULL); if (idle_timer == NULL) { asl_log(NULL, NULL, ASL_LEVEL_CRIT, "FATAL: failed to create idle timer, exiting."); exit(1); } CFRunLoopAddTimer(CFRunLoopGetCurrent(), idle_timer, kCFRunLoopDefaultMode); } }
int main(int argc, const char * argv[]) { int result = 0; FSEventStreamRef streamRef; Boolean startedOK; int flush_seconds = 3600; // When to force-flush any queued events if(argc < 2 || strcasecmp(argv[1], "--help") == 0) { fprintf(stderr, "usage: %s path ...\n", argv[0]); exit(1); } const char **paths = &argv[1]; streamRef = my_FSEventStreamCreate(paths, argc-1); FSEventStreamScheduleWithRunLoop(streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); startedOK = FSEventStreamStart(streamRef); if (!startedOK) { log_error("FSEventStreamStart(streamRef) failed"); goto out; } if (flush_seconds >= 0) { log_debug("CFAbsoluteTimeGetCurrent() => %.3f", CFAbsoluteTimeGetCurrent()); CFAllocatorRef allocator = kCFAllocatorDefault; CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + /*settings->*/flush_seconds; CFTimeInterval interval = /*settings->*/flush_seconds; CFOptionFlags flags = 0; CFIndex order = 0; CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack)timer_callback; CFRunLoopTimerContext context = { 0, streamRef, NULL, NULL, NULL }; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(allocator, fireDate, interval, flags, order, callback, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); } // Run CFRunLoopRun(); // Stop / Invalidate / Release FSEventStreamStop(streamRef); out: FSEventStreamInvalidate(streamRef); FSEventStreamRelease(streamRef); return result; }
void setSharedTimerFireTime(double fireTime) { ASSERT(sharedTimerFiredFunction); WebThreadContext *threadContext = WebThreadCurrentContext(); CFRunLoopTimerRef sharedTimer = threadContext->sharedTimer; if (sharedTimer) { CFRunLoopTimerInvalidate(sharedTimer); CFRelease(sharedTimer); } CFAbsoluteTime fireDate = fireTime - kCFAbsoluteTimeIntervalSince1970; sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0); threadContext->sharedTimer = sharedTimer; CFRunLoopAddTimer(threadContext->runLoop, sharedTimer, kCFRunLoopDefaultMode); }